diff options
author | Victor Nepveu <victor.nepveu@imt-atlantique.net> | 2019-11-12 22:27:36 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-01-16 10:39:15 -0500 |
commit | 594e5ce635481a2aca60bbb31b656e3970ad511b (patch) | |
tree | e1a5758f4c6b446b17d3da42b3d22620e4f65200 /src/feature/nodelist | |
parent | 17c63ff9f64c9f678f566bca70497992f5d4d04d (diff) | |
download | tor-594e5ce635481a2aca60bbb31b656e3970ad511b.tar.gz tor-594e5ce635481a2aca60bbb31b656e3970ad511b.zip |
Refactor routerstatus_has_changed function
- Check all fields that might change in a routerstatus
- Document the refactoring
Signed-off-by: Victor Nepveu <victor.nepveu@imt-atlantique.net>
Diffstat (limited to 'src/feature/nodelist')
-rw-r--r-- | src/feature/nodelist/fmt_routerstatus.c | 2 | ||||
-rw-r--r-- | src/feature/nodelist/networkstatus.c | 22 | ||||
-rw-r--r-- | src/feature/nodelist/routerstatus_st.h | 4 |
3 files changed, 23 insertions, 5 deletions
diff --git a/src/feature/nodelist/fmt_routerstatus.c b/src/feature/nodelist/fmt_routerstatus.c index 8dde0088de..dc44a6ef9c 100644 --- a/src/feature/nodelist/fmt_routerstatus.c +++ b/src/feature/nodelist/fmt_routerstatus.c @@ -124,6 +124,8 @@ routerstatus_format_entry(const routerstatus_t *rs, const char *version, if (format != NS_CONTROL_PORT) { /* Blow up more or less nicely if we didn't get anything or not the * thing we expected. + * This should be kept in sync with the function + * routerstatus_has_changed and the struct routerstatus_t */ if (!desc) { char id[HEX_DIGEST_LEN+1]; diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c index 7868020477..df035ef1b3 100644 --- a/src/feature/nodelist/networkstatus.c +++ b/src/feature/nodelist/networkstatus.c @@ -101,6 +101,7 @@ #include "feature/nodelist/routerlist_st.h" #include "feature/dirauth/vote_microdesc_hash_st.h" #include "feature/nodelist/vote_routerstatus_st.h" +#include "routerstatus_st.h" #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -1603,8 +1604,14 @@ networkstatus_consensus_has_ipv6(const or_options_t* options) } } -/** Given two router status entries for the same router identity, return 1 if - * if the contents have changed between them. Otherwise, return 0. */ +/** Given two router status entries for the same router identity, return 1 + * if the contents have changed between them. Otherwise, return 0. + * It only checks for fields that are output by control port. + * This should be kept in sync with the struct routerstatus_t + * and the printing function routerstatus_format_entry in + * NS_CONTROL_PORT mode. + **/ + static int routerstatus_has_changed(const routerstatus_t *a, const routerstatus_t *b) { @@ -1625,9 +1632,14 @@ routerstatus_has_changed(const routerstatus_t *a, const routerstatus_t *b) a->is_valid != b->is_valid || a->is_possible_guard != b->is_possible_guard || a->is_bad_exit != b->is_bad_exit || - a->is_hs_dir != b->is_hs_dir; - // XXXX this function needs a huge refactoring; it has gotten out - // XXXX of sync with routerstatus_t, and it will do so again. + a->is_hs_dir != b->is_hs_dir || + a->is_staledesc != b->is_staledesc || + a->has_bandwidth != b->has_bandwidth || + a->published_on != b->published_on || + a->ipv6_orport != b->ipv6_orport || + a->is_v2_dir != b->is_v2_dir || + a->bandwidth_kb != b->bandwidth_kb || + tor_addr_compare(&a->ipv6_addr, &b->ipv6_addr, CMP_EXACT); } /** Notify controllers of any router status entries that changed between diff --git a/src/feature/nodelist/routerstatus_st.h b/src/feature/nodelist/routerstatus_st.h index 270cb871a2..eb6c3e5cfc 100644 --- a/src/feature/nodelist/routerstatus_st.h +++ b/src/feature/nodelist/routerstatus_st.h @@ -17,6 +17,10 @@ /** Contents of a single router entry in a network status object. */ struct routerstatus_t { + /* This should be kept in sync with the function + * routerstatus_has_changed and the printing function + * routerstatus_format_entry in NS_CONTROL_PORT mode. + */ time_t published_on; /**< When was this router published? */ char nickname[MAX_NICKNAME_LEN+1]; /**< The nickname this router says it * has. */ |