diff --git a/src/or/config.c b/src/or/config.c index 3c6bf1e068..d62b17171d 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -100,6 +100,7 @@ static config_var_t _option_vars[] = { VAR("AccountingStart", STRING, AccountingStart, NULL), VAR("Address", STRING, Address, NULL), VAR("AllowUnverifiedNodes",CSV, AllowUnverifiedNodes, "middle,rendezvous"), + VAR("AssumeReachable", BOOL, AssumeReachable, "0"), VAR("AuthoritativeDirectory",BOOL, AuthoritativeDir, "0"), VAR("BandwidthBurst", MEMUNIT, BandwidthBurst, "5 MB"), VAR("BandwidthRate", MEMUNIT, BandwidthRate, "2 MB"), @@ -1141,7 +1142,7 @@ print_usage(void) /** * Based on options-\>Address, guess our public IP address and put it - * in *addr_out. If hostname_out is provided, set + * (in host order) into *addr_out. If hostname_out is provided, set * *hostname_out to a new string holding the hostname we used to get * the address. Return 0 if all is well, or -1 if we can't find a suitable * public IP address. diff --git a/src/or/connection.c b/src/or/connection.c index ea627620ca..1adfc08a69 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -669,10 +669,9 @@ connection_handle_listener_read(connection_t *conn, int new_type) newconn->s = news; /* remember the remote address */ - newconn->address = tor_malloc(INET_NTOA_BUF_LEN); - tor_inet_ntoa(&remote.sin_addr, newconn->address, INET_NTOA_BUF_LEN); newconn->addr = ntohl(remote.sin_addr.s_addr); newconn->port = ntohs(remote.sin_port); + newconn->address = tor_dup_addr(newconn->addr); if (connection_add(newconn) < 0) { /* no space, forget it */ connection_free(newconn); diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 58ccd4e274..b69301df9f 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -240,7 +240,6 @@ connection_or_init_conn_from_address(connection_t *conn, uint32_t addr, uint16_t port, const char *id_digest) { - struct in_addr in; const char *n; or_options_t *options = get_options(); routerinfo_t *r = router_get_by_digest(id_digest); @@ -265,10 +264,7 @@ connection_or_init_conn_from_address(connection_t *conn, conn->identity_digest, DIGEST_LEN); } tor_free(conn->address); - in.s_addr = htonl(addr); - - conn->address = tor_malloc(INET_NTOA_BUF_LEN); - tor_inet_ntoa(&in,conn->address,INET_NTOA_BUF_LEN); + conn->address = tor_dup_addr(addr); } /** "update an OR connection nickname on the fly" diff --git a/src/or/or.h b/src/or/or.h index a9bf51622c..b5c9f3bae1 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1092,6 +1092,7 @@ typedef struct { int SocksPort; /**< Port to listen on for SOCKS connections. */ int ControlPort; /**< Port to listen on for control connections. */ int DirPort; /**< Port to listen on for directory connections. */ + int AssumeReachable; /**< Whether to publish our descriptor regardless. */ int AuthoritativeDir; /**< Boolean: is this an authoritative directory? */ int ClientOnly; /**< Boolean: should we never evolve into a server role? */ int NoPublish; /**< Boolean: should we never publish a descriptor? */ diff --git a/src/or/router.c b/src/or/router.c index 174f96f7fb..44079db608 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -401,14 +401,20 @@ static int can_reach_dir_port = 0; int check_whether_orport_reachable(void) { - return clique_mode(get_options()) || can_reach_or_port; + or_options_t *options = get_options(); + return clique_mode(options) || + options->AssumeReachable || + can_reach_or_port; } /** Return 1 if we don't have a dirport configured, or if it's reachable. */ int check_whether_dirport_reachable(void) { - return !get_options()->DirPort || can_reach_dir_port; + or_options_t *options = get_options(); + return !options->DirPort || + options->AssumeReachable || + can_reach_dir_port; } /**DOCDOC*/ @@ -720,10 +726,8 @@ router_rebuild_descriptor(int force) routerinfo_t *ri; uint32_t addr; char platform[256]; - struct in_addr in; int hibernating = we_are_hibernating(); or_options_t *options = get_options(); - char addrbuf[INET_NTOA_BUF_LEN]; if (desc_clean_since && !force) return 0; @@ -734,9 +738,7 @@ router_rebuild_descriptor(int force) } ri = tor_malloc_zero(sizeof(routerinfo_t)); - in.s_addr = htonl(addr); - tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf)); - ri->address = tor_strdup(addrbuf); + ri->address = tor_dup_addr(addr); ri->nickname = tor_strdup(options->Nickname); ri->addr = addr; ri->or_port = options->ORPort; diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 7d5887d2b2..e6a858f05c 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1461,15 +1461,25 @@ add_trusted_dir_server(const char *address, uint16_t port, const char *digest) if (!trusted_dir_servers) trusted_dir_servers = smartlist_create(); - if (tor_lookup_hostname(address, &a)) { + if (!address) { /* need to guess */ + if (resolve_my_address(get_options(), &a, NULL) < 0) { + log_fn(LOG_WARN, "Couldn't find a suitable address. Returning."); + return; + } + } else if (tor_lookup_hostname(address, &a)) { log_fn(LOG_WARN, "Unable to lookup address for directory server at %s", address); return; + a = ntohl(a); } ent = tor_malloc(sizeof(trusted_dir_server_t)); - ent->address = tor_strdup(address); - ent->addr = ntohl(a); + if (address) { + ent->address = tor_strdup(address); + } else { + ent->address = tor_dup_addr(a); + } + ent->addr = a; ent->dir_port = port; ent->is_running = 1; memcpy(ent->digest, digest, DIGEST_LEN);