aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2012-03-31 13:54:09 +0200
committerGeorge Kadianakis <desnacked@riseup.net>2012-03-31 13:54:09 +0200
commitfedf76a2e6452124c38ecc51cea6567b9d5cc23d (patch)
tree9e312986c70ae482346cb8f35ac9a0748692df99
parentda6e0993dc4a0037933a522e2f578c145f6538cc (diff)
downloadtor-fedf76a2e6452124c38ecc51cea6567b9d5cc23d.tar
tor-fedf76a2e6452124c38ecc51cea6567b9d5cc23d.tar.gz
Introduce and use router_get_active_listener_port_by_type().
router_get_active_listener_port_by_type() iterates all connections, trying to find a listener of a specific type, and returns its TCP port.
-rw-r--r--src/or/router.c35
-rw-r--r--src/or/router.h1
2 files changed, 24 insertions, 12 deletions
diff --git a/src/or/router.c b/src/or/router.c
index bf15689a1..67d26e13e 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1216,6 +1216,20 @@ consider_publishable_server(int force)
}
}
+/** Return the port of the first active listener of type
+ * <b>listener_type</b>. */
+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".
@@ -1226,12 +1240,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;
}
@@ -1248,12 +1261,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;
}
diff --git a/src/or/router.h b/src/or/router.h
index fb914349f..294736e70 100644
--- a/src/or/router.h
+++ b/src/or/router.h
@@ -53,6 +53,7 @@ int authdir_mode_publishes_statuses(const or_options_t *options);
int authdir_mode_tests_reachability(const or_options_t *options);
int authdir_mode_bridge(const or_options_t *options);
+uint16_t router_get_active_listener_port_by_type(int listener_type);
uint16_t router_get_advertised_or_port(const or_options_t *options);
uint16_t router_get_advertised_dir_port(const or_options_t *options,
uint16_t dirport);