diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-07-01 01:16:59 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-07-01 01:16:59 +0000 |
commit | 541add90a16a2b7b75e5aa3a54071f3a5db00502 (patch) | |
tree | e6fbde49f0a12931e102a5211651fd014d06f9b9 /src/or/routerlist.c | |
parent | f42f04c859a68dab45d021dd4197da816ec72b07 (diff) | |
download | tor-541add90a16a2b7b75e5aa3a54071f3a5db00502.tar.gz tor-541add90a16a2b7b75e5aa3a54071f3a5db00502.zip |
Track routers by hash of identity key; use hex hash of identity key in place of nickname; accept (and use) hash of identity key in EXTEND cells.
svn:r1994
Diffstat (limited to 'src/or/routerlist.c')
-rw-r--r-- | src/or/routerlist.c | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 68ab10a178..24553bc1bf 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -206,21 +206,59 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) { return NULL; } -/** Return the router in our routerlist whose nickname is <b>nickname</b> - * (case insensitive). Return NULL if no such router is known. +/** Return the router in our routerlist whose (case-insensitive) + * nickname or (case-sensitive) hexadecimal key digest is + * <b>nickname</b>. Return NULL if no such router is known. */ -routerinfo_t *router_get_by_nickname(char *nickname) +routerinfo_t *router_get_by_nickname(const char *nickname) { - int i; + int i, maybedigest; routerinfo_t *router; + char digest[DIGEST_LEN]; tor_assert(nickname); if (!routerlist) return NULL; + maybedigest = (strlen(nickname) == HEX_DIGEST_LEN) && + (base16_decode(digest,DIGEST_LEN,nickname,HEX_DIGEST_LEN) == 0); + + for(i=0;i<smartlist_len(routerlist->routers);i++) { + router = smartlist_get(routerlist->routers, i); + if (0 == strcasecmp(router->nickname, nickname) || + (maybedigest && 0 == memcmp(digest, router->identity_digest, + DIGEST_LEN))) + return router; + } + + return NULL; +} + +/** Return the router in our routerlist whose hexadecimal key digest + * is <b>hexdigest</b>. Return NULL if no such router is known. */ +routerinfo_t *router_get_by_hexdigest(const char *hexdigest) { + char digest[DIGEST_LEN]; + + tor_assert(hexdigest); + if (!routerlist) + return NULL; + if (strlen(hexdigest) != HEX_DIGEST_LEN || + base16_decode(digest,DIGEST_LEN,hexdigest,HEX_DIGEST_LEN) < 0) + return NULL; + + return router_get_by_digest(digest); +} + +/** Return the router in our routerlist whose 20-byte key digest + * is <b>hexdigest</b>. Return NULL if no such router is known. */ +routerinfo_t *router_get_by_digest(const char *digest) { + int i; + routerinfo_t *router; + + tor_assert(digest); for(i=0;i<smartlist_len(routerlist->routers);i++) { router = smartlist_get(routerlist->routers, i); - if (0 == strcasecmp(router->nickname, nickname)) + if (0 == memcmp(router->identity_digest, digest, DIGEST_LEN)) return router; } |