add a "getinfo address" controller command.

svn:r8354
This commit is contained in:
Roger Dingledine 2006-09-09 03:18:39 +00:00
parent 25cb9453d7
commit 29b6d6560e
4 changed files with 35 additions and 13 deletions

View file

@ -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:

View file

@ -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/")) {

View file

@ -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);

View file

@ -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));