[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r8354: add a "getinfo address" controller command. (in tor/trunk: doc src/or)
Author: arma
Date: 2006-09-08 23:18:39 -0400 (Fri, 08 Sep 2006)
New Revision: 8354
Modified:
tor/trunk/doc/control-spec.txt
tor/trunk/src/or/control.c
tor/trunk/src/or/or.h
tor/trunk/src/or/router.c
Log:
add a "getinfo address" controller command.
Modified: tor/trunk/doc/control-spec.txt
===================================================================
--- tor/trunk/doc/control-spec.txt 2006-09-08 20:48:43 UTC (rev 8353)
+++ tor/trunk/doc/control-spec.txt 2006-09-09 03:18:39 UTC (rev 8354)
@@ -344,6 +344,9 @@
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:
Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c 2006-09-08 20:48:43 UTC (rev 8353)
+++ tor/trunk/src/or/control.c 2006-09-09 03:18:39 UTC (rev 8354)
@@ -1307,6 +1307,7 @@
"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 @@
/** 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 @@
*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/")) {
Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h 2006-09-08 20:48:43 UTC (rev 8353)
+++ tor/trunk/src/or/or.h 2006-09-09 03:18:39 UTC (rev 8354)
@@ -2464,6 +2464,7 @@
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);
Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c 2006-09-08 20:48:43 UTC (rev 8353)
+++ tor/trunk/src/or/router.c 2006-09-09 03:18:39 UTC (rev 8354)
@@ -729,6 +729,24 @@
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 @@
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));