diff options
author | David Goulet <dgoulet@torproject.org> | 2020-06-23 10:06:19 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-06-24 13:51:37 -0400 |
commit | 7795dd7ef6fa01202b91d20a0ac82eda1456cef8 (patch) | |
tree | 2290d7b7cc56ad625f89ccfb2830426adf6662af /src/app | |
parent | b8042c9d9a44eaf78c5580a1b0a3d15a90f125ce (diff) | |
download | tor-7795dd7ef6fa01202b91d20a0ac82eda1456cef8.tar.gz tor-7795dd7ef6fa01202b91d20a0ac82eda1456cef8.zip |
addr: Refactor last resolved address cache accessors
Series of things done in this commit:
1. Rename the functions to better reflect the namespace of the file.
2. Make both reset and get function to operate on the last_resolved_addrs
cache that is per family.
3. Make the get function to take a tor_addr_t.
4. Change all callsite to use the new convention.
Part of #33233
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/config/resolve_addr.c | 19 | ||||
-rw-r--r-- | src/app/config/resolve_addr.h | 4 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c index 9a7fbde160..1e861217de 100644 --- a/src/app/config/resolve_addr.c +++ b/src/app/config/resolve_addr.c @@ -47,18 +47,23 @@ static tor_addr_t last_resolved_addrs[IDX_SIZE]; /** Last value actually set by resolve_my_address. */ static uint32_t last_resolved_addr_v4 = 0; -/** Accessor for last_resolved_addr_v4 from outside this file. */ -uint32_t -get_last_resolved_addr_v4(void) +/** Copy the last resolved address of family into addr_out. + * + * If not last resolved address existed, the addr_out is a null address (use + * tor_addr_is_null()). */ +void +resolved_addr_get_last(int family, tor_addr_t *addr_out) { - return last_resolved_addr_v4; + tor_addr_copy(addr_out, &last_resolved_addrs[family]); } -/** Reset last_resolved_addr_v4 from outside this file. */ +/** Reset the last resolved address of family. + * + * This makes it null address. */ void -reset_last_resolved_addr_v4(void) +resolved_addr_reset_last(int family) { - last_resolved_addr_v4 = 0; + tor_addr_make_null(&last_resolved_addrs[family], family); } /** @brief Return true iff the given IP address can be used as a valid diff --git a/src/app/config/resolve_addr.h b/src/app/config/resolve_addr.h index 2cd27d1700..17e9402033 100644 --- a/src/app/config/resolve_addr.h +++ b/src/app/config/resolve_addr.h @@ -19,8 +19,8 @@ bool find_my_address(const or_options_t *options, int family, int warn_severity, tor_addr_t *addr_out, const char **method_out, char **hostname_out); -uint32_t get_last_resolved_addr_v4(void); -void reset_last_resolved_addr_v4(void); +void resolved_addr_get_last(int family, tor_addr_t *addr_out); +void resolved_addr_reset_last(int family); MOCK_DECL(int, is_local_addr, (const tor_addr_t *addr)); |