[tor-commits] [tor/master] Make node_ipv6_preferred() take microdescs into account.
nickm at torproject.org
nickm at torproject.org
Tue Sep 4 22:24:27 UTC 2012
commit 8b081231b54f1bb33243078fab510a9a543242a0
Author: Linus Nordberg <linus at torproject.org>
Date: Fri Aug 31 23:02:19 2012 +0200
Make node_ipv6_preferred() take microdescs into account.
Also, make node_get_prim_orport() indicate in its return value whether
a valid OR port was copied or not.
Maybe we should make it legal to pass ap_out==NULL?
---
src/or/nodelist.c | 31 ++++++++++++++++++++++---------
src/or/nodelist.h | 2 +-
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 9ee114b..25ed6a6 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -821,31 +821,44 @@ node_get_declared_family(const node_t *node)
int
node_ipv6_preferred(const node_t *node)
{
+ tor_addr_port_t ipv4_addr;
node_assert_ok(node);
- if (node->ri)
- return (!tor_addr_is_null(&node->ri->ipv6_addr)
- && (node->ipv6_preferred || node->ri->addr == 0));
- if (node->rs)
- return (!tor_addr_is_null(&node->rs->ipv6_addr)
- && (node->ipv6_preferred || node->rs->addr == 0));
+
+ if (node->ipv6_preferred || node_get_prim_orport(node, &ipv4_addr)) {
+ if (node->ri)
+ return !tor_addr_is_null(&node->ri->ipv6_addr);
+ if (node->md)
+ return !tor_addr_is_null(&node->md->ipv6_addr);
+ if (node->rs)
+ return !tor_addr_is_null(&node->rs->ipv6_addr);
+ }
return 0;
}
/** Copy the primary (IPv4) OR port (IP address and TCP port) for
- * <b>node</b> into *<b>ap_out</b>. */
-void
+ * <b>node</b> into *<b>ap_out</b>. Return 0 if a valid address and
+ * port was copied, else return non-zero.*/
+int
node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
{
node_assert_ok(node);
tor_assert(ap_out);
if (node->ri) {
+ if (node->ri->addr == 0 || node->ri->or_port == 0)
+ return -1;
tor_addr_from_ipv4h(&ap_out->addr, node->ri->addr);
ap_out->port = node->ri->or_port;
- } else if (node->rs) {
+ return 0;
+ }
+ if (node->rs) {
+ if (node->rs->addr == 0 || node->rs->or_port == 0)
+ return -1;
tor_addr_from_ipv4h(&ap_out->addr, node->rs->addr);
ap_out->port = node->rs->or_port;
+ return 0;
}
+ return -1;
}
/** Copy the preferred OR port (IP address and TCP port) for
diff --git a/src/or/nodelist.h b/src/or/nodelist.h
index 18bf4ae..fb65fa5 100644
--- a/src/or/nodelist.h
+++ b/src/or/nodelist.h
@@ -51,7 +51,7 @@ long node_get_declared_uptime(const node_t *node);
time_t node_get_published_on(const node_t *node);
const smartlist_t *node_get_declared_family(const node_t *node);
int node_ipv6_preferred(const node_t *node);
-void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
+int node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
More information about the tor-commits
mailing list