From ee8dce3084261447420f0bb7abeb6807583325ee Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 24 Feb 2008 22:11:12 +0000 Subject: [PATCH] r14421@tombo: nickm | 2008-02-24 17:05:18 -0500 Patch from mwenge: always willingly serve our own extrainfo from the controlport svn:r13699 --- ChangeLog | 3 +++ src/or/control.c | 13 +++++++++++-- src/or/dirserv.c | 3 ++- src/or/or.h | 1 + src/or/router.c | 13 +++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2e5ebb0bf..6d4492c85a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -55,6 +55,9 @@ Changes in version 0.2.0.20-?? - 2008-02-?? get saved to disk by SAVECONF. Make Tor automatically convert "HashedControlPassword" to this new option but only when it's given on the command line. Partial fix for bug 586. + - If we have an extra-info document for our server, always make + it available on the control port, even if we haven't gotten + a copy of it from an authority yet. Patch from mwenge. o Minor features (logging): - When SafeLogging is disabled, log addresses along with all TLS diff --git a/src/or/control.c b/src/or/control.c index 5b0d7c2ca2..fb4af9112b 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1523,8 +1523,17 @@ getinfo_helper_dir(control_connection_t *control_conn, if (strlen(question) == HEX_DIGEST_LEN) { char d[DIGEST_LEN]; signed_descriptor_t *sd = NULL; - if (base16_decode(d, sizeof(d), question, strlen(question))==0) - sd = extrainfo_get_by_descriptor_digest(d); + if (base16_decode(d, sizeof(d), question, strlen(question))==0) { + /* XXXX this test should move into extrainfo_get_by_descriptor_digest, + * but I don't want to risk affecting other parts of the code, + * especially since the rules for using our own extrainfo (including + * when it might be freed) are different from those for using one + * we have downloaded. */ + if (router_extrainfo_digest_is_me(d)) + sd = &(router_get_my_extrainfo()->cache_info); + else + sd = extrainfo_get_by_descriptor_digest(d); + } if (sd) { const char *body = signed_descriptor_get_body(sd); if (body) diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 5570a3905a..29aff2872e 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -2673,7 +2673,8 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key, SMARTLIST_FOREACH(digests, const char *, d, { if (router_digest_is_me(d)) { - smartlist_add(descs_out, &(router_get_my_routerinfo()->cache_info)); + if (router_get_my_routerinfo()) /* make sure desc_routerinfo exists */ + smartlist_add(descs_out, &(router_get_my_routerinfo()->cache_info)); } else { routerinfo_t *ri = router_get_by_digest(d); /* Don't actually serve a descriptor that everyone will think is diff --git a/src/or/or.h b/src/or/or.h index f7af3e7c91..b00b4dd9c7 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3794,6 +3794,7 @@ routerinfo_t *router_get_my_routerinfo(void); extrainfo_t *router_get_my_extrainfo(void); const char *router_get_my_descriptor(void); int router_digest_is_me(const char *digest); +int router_extrainfo_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); diff --git a/src/or/router.c b/src/or/router.c index 2a2493998d..9b22d86ed1 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -1094,6 +1094,19 @@ router_digest_is_me(const char *digest) return identitykey && !memcmp(identitykey_digest, digest, DIGEST_LEN); } +/** Return true iff I'm a server and digest is equal to + * my identity digest. */ +int +router_extrainfo_digest_is_me(const char *digest) +{ + if (!router_get_my_extrainfo()) + return 0; + + return !memcmp(digest, + &(router_get_my_extrainfo()->cache_info).signed_descriptor_digest, + DIGEST_LEN); +} + /** A wrapper around router_digest_is_me(). */ int router_is_me(routerinfo_t *router)