routerset.h (4263B)
1 /* Copyright (c) 2001-2004, Roger Dingledine. 2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. 3 * Copyright (c) 2007-2021, The Tor Project, Inc. */ 4 /* See LICENSE for licensing information */ 5 6 /** 7 * \file routerset.h 8 * \brief Header file for routerset.c 9 **/ 10 11 #ifndef TOR_ROUTERSET_H 12 #define TOR_ROUTERSET_H 13 14 routerset_t *routerset_new(void); 15 void routerset_refresh_countries(routerset_t *rs); 16 int routerset_parse(routerset_t *target, const char *s, 17 const char *description); 18 void routerset_union(routerset_t *target, const routerset_t *source); 19 int routerset_is_list(const routerset_t *set); 20 int routerset_needs_geoip(const routerset_t *set); 21 int routerset_is_empty(const routerset_t *set); 22 int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri, 23 country_t country); 24 int routerset_contains_routerstatus(const routerset_t *set, 25 const routerstatus_t *rs, 26 country_t country); 27 int routerset_contains_extendinfo(const routerset_t *set, 28 const extend_info_t *ei); 29 struct bridge_info_t; 30 int routerset_contains_bridge(const routerset_t *set, 31 const struct bridge_info_t *bridge); 32 int routerset_contains_node(const routerset_t *set, const node_t *node); 33 34 void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset, 35 const routerset_t *excludeset, 36 int running_only); 37 int routerset_add_unknown_ccs(routerset_t **setp, int only_if_some_cc_set); 38 void routerset_subtract_nodes(smartlist_t *out, 39 const routerset_t *routerset); 40 41 char *routerset_to_string(const routerset_t *routerset); 42 int routerset_equal(const routerset_t *old, const routerset_t *new); 43 void routerset_free_(routerset_t *routerset); 44 #define routerset_free(rs) FREE_AND_NULL(routerset_t, routerset_free_, (rs)) 45 int routerset_len(const routerset_t *set); 46 47 struct var_type_def_t; 48 extern const struct var_type_def_t ROUTERSET_type_defn; 49 typedef routerset_t *config_decl_ROUTERSET; 50 51 #ifdef ROUTERSET_PRIVATE 52 #include "lib/container/bitarray.h" 53 54 STATIC char * routerset_get_countryname(const char *c); 55 STATIC int routerset_contains(const routerset_t *set, const tor_addr_t *addr, 56 uint16_t orport, 57 const char *nickname, const char *id_digest, 58 country_t country); 59 60 /** A routerset specifies constraints on a set of possible routerinfos, based 61 * on their names, identities, or addresses. It is optimized for determining 62 * whether a router is a member or not, in O(1+P) time, where P is the number 63 * of address policy constraints. */ 64 struct routerset_t { 65 /** A list of strings for the elements of the policy. Each string is either 66 * a nickname, a hexadecimal identity fingerprint, or an address policy. A 67 * router belongs to the set if its nickname OR its identity OR its address 68 * matches an entry here. */ 69 smartlist_t *list; 70 /** A map from lowercase nicknames of routers in the set to (void*)1 */ 71 strmap_t *names; 72 /** A map from identity digests routers in the set to (void*)1 */ 73 digestmap_t *digests; 74 /** An address policy for routers in the set. For implementation reasons, 75 * a router belongs to the set if it is _rejected_ by this policy. */ 76 smartlist_t *policies; 77 78 /** A human-readable description of what this routerset is for. Used in 79 * log messages. */ 80 char *description; 81 82 /** A list of the country codes in this set. */ 83 smartlist_t *country_names; 84 /** Total number of countries we knew about when we built <b>countries</b>.*/ 85 int n_countries; 86 /** Bit array mapping the return value of geoip_get_country() to 1 iff the 87 * country is a member of this routerset. Note that we MUST call 88 * routerset_refresh_countries() whenever the geoip country list is 89 * reloaded. */ 90 bitarray_t *countries; 91 /** If true, subsequent assignments to this routerset should replace 92 * it, not extend it. Set only on the first item in a routerset in an 93 * or_options_t. */ 94 unsigned int fragile:1; 95 }; 96 #endif /* defined(ROUTERSET_PRIVATE) */ 97 #endif /* !defined(TOR_ROUTERSET_H) */