diff options
author | Roger Dingledine <arma@torproject.org> | 2006-09-09 03:18:39 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2006-09-09 03:18:39 +0000 |
commit | 29b6d6560eecfe7a97631b48d4af208c54e95f12 (patch) | |
tree | 3a323126bb18bcc081e6c11c8dff90c358d062ad | |
parent | 25cb9453d775250cef20a282352ba57131a8b08a (diff) | |
download | tor-29b6d6560eecfe7a97631b48d4af208c54e95f12.tar tor-29b6d6560eecfe7a97631b48d4af208c54e95f12.tar.gz |
add a "getinfo address" controller command.
svn:r8354
-rw-r--r-- | doc/control-spec.txt | 3 | ||||
-rw-r--r-- | src/or/control.c | 8 | ||||
-rw-r--r-- | src/or/or.h | 1 | ||||
-rw-r--r-- | src/or/router.c | 36 |
4 files changed, 35 insertions, 13 deletions
diff --git a/doc/control-spec.txt b/doc/control-spec.txt index b8566d603..8d96fb13e 100644 --- a/doc/control-spec.txt +++ b/doc/control-spec.txt @@ -344,6 +344,9 @@ $Id$ via the control interface; the 'all' target returns the mappings set through any mechanism. + "address" -- the best guess at our external IP address. If we + have no guess, return a 551 error. + "circuit-status" A series of lines as for a circuit status event. Each line is of the form: diff --git a/src/or/control.c b/src/or/control.c index 949ae1584..84a6173b9 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1307,6 +1307,7 @@ list_getinfo_options(void) "addr-mappings/cache Addresses remapped by DNS cache.\n" "addr-mappings/configl Addresses remapped from configuration options.\n" "addr-mappings/control Addresses remapped by a controller.\n" + "address The best guess at our external IP address.\n" "circuit-status Status of each current circuit.\n" "config-file Current location of the \"torrc\" file.\n" "config/names List of configuration options, types, and documentation.\n" @@ -1325,7 +1326,7 @@ list_getinfo_options(void) /** Lookup the 'getinfo' entry <b>question</b>, and return * the answer in <b>*answer</b> (or NULL if key not recognized). - * Return 0 if success, or -1 if internal error. */ + * Return 0 if success, or -1 if recognized but internal error. */ static int handle_getinfo_helper(const char *question, char **answer) { @@ -1520,6 +1521,11 @@ handle_getinfo_helper(const char *question, char **answer) *answer = smartlist_join_strings(mappings, "\n", 0, NULL); SMARTLIST_FOREACH(mappings, char *, cp, tor_free(cp)); smartlist_free(mappings); + } else if (!strcmp(question, "address")) { + uint32_t addr; + if (router_pick_published_address(get_options(), &addr) < 0) + return -1; + *answer = tor_dup_addr(addr); } else if (!strcmp(question, "dir-usage")) { *answer = directory_dump_request_log(); } else if (!strcmpstart(question, "dir/server/")) { diff --git a/src/or/or.h b/src/or/or.h index 1cb4446aa..eed357816 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -2464,6 +2464,7 @@ const char *router_get_my_descriptor(void); int router_digest_is_me(const char *digest); int router_is_me(routerinfo_t *router); int router_fingerprint_is_me(const char *fp); +int router_pick_published_address(or_options_t *options, uint32_t *addr); int router_rebuild_descriptor(int force); int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, crypto_pk_env_t *ident_key); diff --git a/src/or/router.c b/src/or/router.c index fb8f8904e..0c7e72a78 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -729,6 +729,24 @@ static smartlist_t *warned_nonexistent_family = NULL; static int router_guess_address_from_dir_headers(uint32_t *guess); +/** Return our current best guess at our address, either because + * it's configured in torrc, or because we've learned it from + * dirserver headers. */ +int +router_pick_published_address(or_options_t *options, uint32_t *addr) +{ + if (resolve_my_address(LOG_INFO, options, addr, NULL) < 0) { + log_info(LD_CONFIG, "Could not determine our address locally. " + "Checking if directory headers provide any hints."); + if (router_guess_address_from_dir_headers(addr) < 0) { + log_info(LD_CONFIG, "No hints from directory headers either. " + "Will try again later."); + return -1; + } + } + return 0; +} + /** If <b>force</b> is true, or our descriptor is out-of-date, rebuild * a fresh routerinfo and signed server descriptor for this OR. * Return 0 on success, -1 on temporary error. @@ -745,18 +763,12 @@ router_rebuild_descriptor(int force) if (desc_clean_since && !force) return 0; - if (resolve_my_address(LOG_INFO, options, &addr, NULL) < 0) { - log_info(LD_CONFIG, "Could not determine our address locally. " - "Checking if directory headers provide any hints."); - if (router_guess_address_from_dir_headers(&addr) < 0) { - log_info(LD_CONFIG, "No hints from directory headers either. " - "Will try again later."); - /* Stop trying to rebuild our descriptor every second. We'll - * learn that it's time to try again when server_has_changed_ip() - * marks it dirty. */ - desc_clean_since = time(NULL); - return -1; - } + if (router_pick_published_address(options, &addr) < 0) { + /* Stop trying to rebuild our descriptor every second. We'll + * learn that it's time to try again when server_has_changed_ip() + * marks it dirty. */ + desc_clean_since = time(NULL); + return -1; } ri = tor_malloc_zero(sizeof(routerinfo_t)); |