[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] stop setting, or using, router->address
commit 74e6a47a808803c985f55b626dff294dbe425043
Author: Roger Dingledine <arma@xxxxxxxxxxxxxx>
Date: Sat Feb 9 22:07:22 2013 -0500
stop setting, or using, router->address
resolves ticket 5528.
---
changes/ticket5528 | 4 ++++
src/or/entrynodes.c | 2 --
src/or/or.h | 1 -
src/or/router.c | 7 +++++--
src/or/routerlist.c | 3 +--
src/or/routerparse.c | 3 +--
src/test/test_dir.c | 8 +++-----
7 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/changes/ticket5528 b/changes/ticket5528
new file mode 100644
index 0000000..69b2c1d
--- /dev/null
+++ b/changes/ticket5528
@@ -0,0 +1,4 @@
+ o Code simplifications and refactoring:
+ - Get rid of router->address, since in all cases it was just the
+ string representation of router->addr. Resolves ticket 5528.
+
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 282a9a0..263b9f1 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -1876,8 +1876,6 @@ rewrite_node_address_for_bridge(const bridge_info_t *bridge, node_t *node)
} else {
if (tor_addr_family(&bridge->addr) == AF_INET) {
ri->addr = tor_addr_to_ipv4h(&bridge->addr);
- tor_free(ri->address);
- ri->address = tor_dup_ip(ri->addr);
ri->or_port = bridge->port;
log_info(LD_DIR,
"Adjusted bridge routerinfo for '%s' to match configured "
diff --git a/src/or/or.h b/src/or/or.h
index 04640d0..70a22aa 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1925,7 +1925,6 @@ typedef int16_t country_t;
/** Information about another onion router in the network. */
typedef struct {
signed_descriptor_t cache_info;
- char *address; /**< Location of OR: either a hostname or an IP address. */
char *nickname; /**< Human-readable OR name. */
uint32_t addr; /**< IPv4 address of OR, in host order. */
diff --git a/src/or/router.c b/src/or/router.c
index c7932d1..f8678ac 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1759,7 +1759,6 @@ router_rebuild_descriptor(int force)
ri = tor_malloc_zero(sizeof(routerinfo_t));
ri->cache_info.routerlist_index = -1;
- ri->address = tor_dup_ip(addr);
ri->nickname = tor_strdup(options->Nickname);
ri->addr = addr;
ri->or_port = router_get_advertised_or_port(options);
@@ -2218,6 +2217,7 @@ int
router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
crypto_pk_t *ident_key)
{
+ char *address;
char *onion_pkey; /* Onion key, PEM-encoded. */
char *identity_pkey; /* Identity key, PEM-encoded. */
char digest[DIGEST_LEN];
@@ -2292,6 +2292,8 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
}
}
+ address = tor_dup_ip(router->addr);
+
/* Generate the easy portion of the router descriptor. */
result = tor_snprintf(s, maxlen,
"router %s %s %d 0 %d\n"
@@ -2307,7 +2309,7 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
"signing-key\n%s"
"%s%s%s%s",
router->nickname,
- router->address,
+ address,
router->or_port,
decide_to_advertise_dirport(options, router->dir_port),
extra_or_address ? extra_or_address : "",
@@ -2328,6 +2330,7 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
options->HidServDirectoryV2 ? "hidden-service-dir\n" : "",
options->AllowSingleHopExits ? "allow-single-hop-exits\n" : "");
+ tor_free(address);
tor_free(family_line);
tor_free(onion_pkey);
tor_free(identity_pkey);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 8f19947..d1ecca5 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -2538,7 +2538,6 @@ routerinfo_free(routerinfo_t *router)
return;
tor_free(router->cache_info.signed_descriptor_body);
- tor_free(router->address);
tor_free(router->nickname);
tor_free(router->platform);
tor_free(router->contact_info);
@@ -4743,7 +4742,7 @@ router_differences_are_cosmetic(const routerinfo_t *r1, const routerinfo_t *r2)
}
/* If any key fields differ, they're different. */
- if (strcasecmp(r1->address, r2->address) ||
+ if (r1->addr != r2->addr ||
strcasecmp(r1->nickname, r2->nickname) ||
r1->or_port != r2->or_port ||
!tor_addr_eq(&r1->ipv6_addr, &r2->ipv6_addr) ||
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 2a3de12..ce8247d 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1206,8 +1206,7 @@ router_parse_entry_from_string(const char *s, const char *end,
log_warn(LD_DIR,"Router nickname is invalid");
goto err;
}
- router->address = tor_strdup(tok->args[1]);
- if (!tor_inet_aton(router->address, &in)) {
+ if (!tor_inet_aton(tok->args[1], &in)) {
log_warn(LD_DIR,"Router address is not an IP address.");
goto err;
}
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index f1c745e..150a2ac 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -94,7 +94,6 @@ test_dir_formats(void)
get_platform_str(platform, sizeof(platform));
r1 = tor_malloc_zero(sizeof(routerinfo_t));
- r1->address = tor_strdup("18.244.0.1");
r1->addr = 0xc0a80001u; /* 192.168.0.1 */
r1->cache_info.published_on = 0;
r1->or_port = 9000;
@@ -121,7 +120,6 @@ test_dir_formats(void)
ex2->maskbits = 8;
ex2->prt_min = ex2->prt_max = 24;
r2 = tor_malloc_zero(sizeof(routerinfo_t));
- r2->address = tor_strdup("1.1.1.1");
r2->addr = 0x0a030201u; /* 10.3.2.1 */
r2->platform = tor_strdup(platform);
r2->cache_info.published_on = 5;
@@ -145,7 +143,7 @@ test_dir_formats(void)
memset(buf, 0, 2048);
test_assert(router_dump_router_to_string(buf, 2048, r1, pk2)>0);
- strlcpy(buf2, "router Magri 18.244.0.1 9000 0 9003\n"
+ strlcpy(buf2, "router Magri 192.168.0.1 9000 0 9003\n"
"or-address [1:2:3:4::]:9999\n"
"platform Tor "VERSION" on ", sizeof(buf2));
strlcat(buf2, get_uname(), sizeof(buf2));
@@ -175,7 +173,7 @@ test_dir_formats(void)
cp = buf;
rp1 = router_parse_entry_from_string((const char*)cp,NULL,1,0,NULL);
test_assert(rp1);
- test_streq(rp1->address, r1->address);
+ test_eq(rp1->addr, r1->addr);
test_eq(rp1->or_port, r1->or_port);
//test_eq(rp1->dir_port, r1->dir_port);
test_eq(rp1->bandwidthrate, r1->bandwidthrate);
@@ -198,7 +196,7 @@ test_dir_formats(void)
cp = buf;
rp2 = router_parse_entry_from_string(&cp,1);
test_assert(rp2);
- test_streq(rp2->address, r2.address);
+ test_eq(rp2->addr, r2.addr);
test_eq(rp2->or_port, r2.or_port);
test_eq(rp2->dir_port, r2.dir_port);
test_eq(rp2->bandwidth, r2.bandwidth);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits