summaryrefslogtreecommitdiff
path: root/src/or/router.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-05-11 11:52:51 -0400
committerNick Mathewson <nickm@torproject.org>2012-05-11 11:52:51 -0400
commite0655708a20069a5f42476a25d62e9d3f8138d8c (patch)
tree4ee26e5176efe7f61c4fba89bc21886b7508df27 /src/or/router.c
parent84ddc4b6aad392dd9a735580caf6fb68e3694d42 (diff)
parent6d2898607bd831944c6c15b6e15200a426149811 (diff)
downloadtor-e0655708a20069a5f42476a25d62e9d3f8138d8c.tar.gz
tor-e0655708a20069a5f42476a25d62e9d3f8138d8c.zip
Merge remote-tracking branch 'asn/bug4865_take2'
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 35955f3ee0..4468c7b26a 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1228,6 +1228,22 @@ consider_publishable_server(int force)
}
}
+/** Return the port of the first active listener of type
+ * <b>listener_type</b>. */
+/** XXX not a very good interface. it's not reliable when there are
+ multiple listeners. */
+uint16_t
+router_get_active_listener_port_by_type(int listener_type)
+{
+ /* Iterate all connections, find one of the right kind and return
+ the port. Not very sophisticated or fast, but effective. */
+ const connection_t *c = connection_get_by_type(listener_type);
+ if (c)
+ return c->port;
+
+ return 0;
+}
+
/** Return the port that we should advertise as our ORPort; this is either
* the one configured in the ORPort option, or the one we actually bound to
* if ORPort is "auto".
@@ -1238,12 +1254,11 @@ router_get_advertised_or_port(const or_options_t *options)
int port = get_primary_or_port();
(void)options;
- if (port == CFG_AUTO_PORT) {
- connection_t *c = connection_get_by_type(CONN_TYPE_OR_LISTENER);
- if (c)
- return c->port;
- return 0;
- }
+ /* If the port is in 'auto' mode, we have to use
+ router_get_listener_port_by_type(). */
+ if (port == CFG_AUTO_PORT)
+ return router_get_active_listener_port_by_type(CONN_TYPE_OR_LISTENER);
+
return port;
}
@@ -1260,12 +1275,10 @@ router_get_advertised_dir_port(const or_options_t *options, uint16_t dirport)
if (!dirport_configured)
return dirport;
- if (dirport_configured == CFG_AUTO_PORT) {
- connection_t *c = connection_get_by_type(CONN_TYPE_DIR_LISTENER);
- if (c)
- return c->port;
- return 0;
- }
+
+ if (dirport_configured == CFG_AUTO_PORT)
+ return router_get_active_listener_port_by_type(CONN_TYPE_DIR_LISTENER);
+
return dirport_configured;
}