From e591aafca420b673a63881573581a9cdb178c3f9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 18 Mar 2009 19:30:26 +0000 Subject: Add a function to get a LongName from a routerstatus. Needed for partial bug 941 fix. svn:r19077 --- src/or/or.h | 3 ++- src/or/router.c | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/or/or.h b/src/or/or.h index e55d32428..a6843b780 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -4238,7 +4238,8 @@ char *extrainfo_get_client_geoip_summary(time_t); int is_legal_nickname(const char *s); int is_legal_nickname_or_hexdigest(const char *s); int is_legal_hexdigest(const char *s); -void router_get_verbose_nickname(char *buf, routerinfo_t *router); +void router_get_verbose_nickname(char *buf, const routerinfo_t *router); +void routerstatus_get_verbose_nickname(char *buf, const routerstatus_t *router); void router_reset_warnings(void); void router_reset_reachability(void); void router_free_all(void); diff --git a/src/or/router.c b/src/or/router.c index f3e09e6db..ec33eb590 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1980,7 +1980,7 @@ is_legal_hexdigest(const char *s) * The router's nickname. **/ void -router_get_verbose_nickname(char *buf, routerinfo_t *router) +router_get_verbose_nickname(char *buf, const routerinfo_t *router) { buf[0] = '$'; base16_encode(buf+1, HEX_DIGEST_LEN+1, router->cache_info.identity_digest, @@ -1989,6 +1989,23 @@ router_get_verbose_nickname(char *buf, routerinfo_t *router) strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1); } +/** Set buf (which must have MAX_VERBOSE_NICKNAME_LEN+1 bytes) to the + * verbose representation of the identity of router. The format is: + * A dollar sign. + * The upper-case hexadecimal encoding of the SHA1 hash of router's identity. + * A "=" if the router is named; a "~" if it is not. + * The router's nickname. + **/ +void +routerstatus_get_verbose_nickname(char *buf, const routerstatus_t *router) +{ + buf[0] = '$'; + base16_encode(buf+1, HEX_DIGEST_LEN+1, router->identity_digest, + DIGEST_LEN); + buf[1+HEX_DIGEST_LEN] = router->is_named ? '=' : '~'; + strlcpy(buf+1+HEX_DIGEST_LEN+1, router->nickname, MAX_NICKNAME_LEN+1); +} + /** Forget that we have issued any router-related warnings, so that we'll * warn again if we see the same errors. */ void -- cgit v1.2.3