diff options
author | George Kadianakis <desnacked@riseup.net> | 2019-04-09 17:57:04 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-05-03 18:15:26 +0300 |
commit | 0ed5c6edf9c905276d462ed2402568216ecb1dee (patch) | |
tree | 63c2c46dd962acbe517acfa1b2147114ced74549 /src/core/or/crypt_path.c | |
parent | 58fbbc1409f65bbb65c9da03a035a5767820146b (diff) | |
download | tor-0ed5c6edf9c905276d462ed2402568216ecb1dee.tar.gz tor-0ed5c6edf9c905276d462ed2402568216ecb1dee.zip |
Hiding crypt_path_t: Move some more crypt_path-specific functions.
- Move test-only cpath_get_n_hops() to crypt_path.c.
- Move onion_next_hop_in_cpath() and rename to cpath_get_next_non_open_hop().
The latter function was directly accessing cpath->state, and it's a first step
at hiding ->state.
Diffstat (limited to 'src/core/or/crypt_path.c')
-rw-r--r-- | src/core/or/crypt_path.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index 13063e5da8..8fcbcc2a12 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -210,3 +210,44 @@ cpath_set_cell_forward_digest(crypt_path_t *cpath, cell_t *cell) tor_assert(cpath->private); relay_set_digest(cpath->private->crypto.f_digest, cell); } + +/************ other cpath functions ***************************/ + +/** Return the first non-open hop in cpath, or return NULL if all + * hops are open. */ +crypt_path_t * +cpath_get_next_non_open_hop(crypt_path_t *cpath) +{ + crypt_path_t *hop = cpath; + do { + if (hop->state != CPATH_STATE_OPEN) + return hop; + hop = hop->next; + } while (hop != cpath); + return NULL; +} + +#ifdef TOR_UNIT_TESTS + +/** Unittest helper function: Count number of hops in cpath linked list. */ +unsigned int +cpath_get_n_hops(crypt_path_t **head_ptr) +{ + unsigned int n_hops = 0; + crypt_path_t *tmp; + + if (!*head_ptr) { + return 0; + } + + tmp = *head_ptr; + do { + n_hops++; + tmp = tmp->next; + } while (tmp != *head_ptr); + + return n_hops; +} + +#endif /* defined(TOR_UNIT_TESTS) */ + |