28#define ROUTERSET_PRIVATE
53 routerset_t *result = tor_malloc_zero(
sizeof(routerset_t));
55 result->names = strmap_new();
56 result->digests = digestmap_new();
70 if (strlen(c) < 4 || c[0] !=
'{' || c[3] !=
'}')
73 country = tor_strndup(c+1, 2);
85 bitarray_free(target->countries);
88 target->countries = NULL;
89 target->n_countries = 0;
100 log_warn(
LD_CONFIG,
"Country code '%s' is not recognized.",
103 } SMARTLIST_FOREACH_END(country);
118 int added_countries = 0;
123 SPLIT_SKIP_SPACE | SPLIT_IGNORE_BLANK, 0);
132 log_debug(
LD_CONFIG,
"Adding identity %s to %s", nick, description);
134 digestmap_set(target->digests, d, (
void*)1);
136 log_debug(
LD_CONFIG,
"Adding nickname %s to %s", nick, description);
139 log_debug(
LD_CONFIG,
"Adding country %s to %s", nick,
143 }
else if ((strchr(nick,
'.') || strchr(nick,
':') || strchr(nick,
'*'))
145 nick, ADDR_POLICY_REJECT,
149 log_debug(
LD_CONFIG,
"Adding address %s to %s", nick, description);
151 }
else if (malformed_list) {
152 log_warn(
LD_CONFIG,
"Entry '%s' in %s is malformed. Discarding entire"
153 " list.", nick, description);
158 log_notice(
LD_CONFIG,
"Entry '%s' in %s is ignored. Using the"
159 " remainder of the list.", nick, description);
163 } SMARTLIST_FOREACH_END(nick);
166 smartlist_free(list);
178 if (!source || !source->list)
190 return smartlist_len(set->country_names) == 0 &&
191 smartlist_len(set->policies) == 0;
199 return set && smartlist_len(set->country_names);
206 return !set || smartlist_len(set->list) == 0;
217 return smartlist_len(set->list);
230 uint16_t orport2,
const char *nickname,
231 const char *id_digest,
country_t country)
233 if (!set || !set->list)
237 if (id_digest && digestmap_get(set->digests, id_digest))
245 if (set->countries) {
246 if (country < 0 && addr)
249 if (country >= 0 && country < set->n_countries &&
260 uint16_t orport,
const char *nickname,
261 const char *id_digest,
country_t country)
264 nickname, id_digest, country);
275 int add_unknown, add_a1;
276 if (only_if_some_cc_set) {
277 if (!*setp || smartlist_len((*setp)->country_names) == 0)
299 if (add_unknown || add_a1) {
316 ap1 ? &ap1->addr : NULL,
318 ap2 ? &ap2->addr : NULL,
380 const routerset_t *excludeset,
int running_only)
383 if (!routerset || !routerset->list)
390 const node_t *node = node_get_by_nickname(name, 0);
392 if (!running_only || node->is_running)
393 if (!routerset_contains_node(excludeset, node))
394 smartlist_add(out, (void*)node);
402 if (running_only && !node->is_running)
431 if (!set || !set->list)
432 return tor_strdup(
"");
451 if (smartlist_len(old->list) != smartlist_len(new->list))
455 const char *cp2 = smartlist_get(new->list, cp1_sl_idx);
456 if (strcmp(cp1, cp2))
471 smartlist_free(routerset->list);
473 addr_policy_free(p));
474 smartlist_free(routerset->policies);
476 smartlist_free(routerset->country_names);
478 strmap_free(routerset->names, NULL);
479 digestmap_free(routerset->digests, NULL);
480 bitarray_free(routerset->countries);
503 routerset_t **lines = target;
505 if (*lines && (*lines)->fragile) {
507 (*lines)->fragile = 0;
509 routerset_free(*lines);
516 *errmsg = tor_strdup(
"Invalid router list.");
541 const routerset_t **p = (
const routerset_t**)value;
554 routerset_t **p = (routerset_t**)value;
569 routerset_t **output = (routerset_t**)dest;
570 const routerset_t *input = *(routerset_t**)src;
571 routerset_free(*output);
580routerset_mark_fragile(
void *target,
const void *params)
583 routerset_t **ptr = (routerset_t **)target;
596 .mark_fragile = routerset_mark_fragile,
609 .
name =
"RouterList",
Address policy structures.
int tor_addr_is_null(const tor_addr_t *addr)
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
static bitarray_t * bitarray_init_zero(unsigned int n_bits)
static void bitarray_set(bitarray_t *b, int bit)
static unsigned int bitarray_is_set(bitarray_t *b, int bit)
const uint8_t * bridge_get_rsa_id_digest(const bridge_info_t *bridge)
const tor_addr_port_t * bridge_get_addr_port(const bridge_info_t *bridge)
Header file for circuitbuild.c.
#define CONFIG_LINE_APPEND
Types used to specify configurable options.
int geoip_is_loaded(sa_family_t family)
country_t geoip_get_country(const char *country)
int geoip_get_country_by_addr(const tor_addr_t *addr)
int geoip_get_n_countries(void)
void * strmap_get_lc(const strmap_t *map, const char *key)
void * strmap_set_lc(strmap_t *map, const char *key, void *val)
int is_legal_nickname(const char *s)
int is_legal_hexdigest(const char *s)
Header file for nickname.c.
Node information structure.
const smartlist_t * nodelist_get_list(void)
Header file for nodelist.c.
Master header file for Tor-specific functionality.
addr_policy_result_t compare_tor_addr_to_addr_policy(const tor_addr_t *addr, uint16_t port, const smartlist_t *policy)
void policy_expand_unspec(smartlist_t **policy)
Header file for policies.c.
addr_policy_t * router_parse_addr_policy_item_from_string(const char *s, int assume_action, int *malformed_list)
Header file for policy_parse.c.
Router descriptor structure.
int routerset_needs_geoip(const routerset_t *set)
char * routerset_to_string(const routerset_t *set)
STATIC int routerset_contains(const routerset_t *set, const tor_addr_t *addr, uint16_t orport, const char *nickname, const char *id_digest, country_t country)
int routerset_is_empty(const routerset_t *set)
void routerset_refresh_countries(routerset_t *target)
routerset_t * routerset_new(void)
STATIC char * routerset_get_countryname(const char *c)
static const var_type_fns_t routerset_type_fns
void routerset_free_(routerset_t *routerset)
int routerset_equal(const routerset_t *old, const routerset_t *new)
int routerset_is_list(const routerset_t *set)
int routerset_contains_routerstatus(const routerset_t *set, const routerstatus_t *rs, country_t country)
const var_type_def_t ROUTERSET_type_defn
int routerset_contains_node(const routerset_t *set, const node_t *node)
void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset, const routerset_t *excludeset, int running_only)
int routerset_add_unknown_ccs(routerset_t **setp, int only_if_some_cc_set)
int routerset_contains_extendinfo(const routerset_t *set, const extend_info_t *ei)
int routerset_parse(routerset_t *target, const char *s, const char *description)
int routerset_len(const routerset_t *set)
static void routerset_clear(void *value, const void *params)
static int routerset_kv_parse(void *target, const config_line_t *line, char **errmsg, const void *params)
static int routerset_contains2(const routerset_t *set, const tor_addr_t *addr, uint16_t orport, const tor_addr_t *addr2, uint16_t orport2, const char *nickname, const char *id_digest, country_t country)
static int routerset_copy(void *dest, const void *src, const void *params)
void routerset_subtract_nodes(smartlist_t *lst, const routerset_t *routerset)
void routerset_union(routerset_t *target, const routerset_t *source)
int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri, country_t country)
int routerset_contains_bridge(const routerset_t *set, const bridge_info_t *bridge)
static char * routerset_encode(const void *value, const void *params)
Header file for routerset.c.
Routerstatus (consensus entry) structure.
int smartlist_contains_string_case(const smartlist_t *sl, const char *element)
char * smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, size_t *len_out)
void smartlist_add_all(smartlist_t *s1, const smartlist_t *s2)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
#define SMARTLIST_DEL_CURRENT(sl, var)
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep, int flags, int max)
tor_addr_port_t orports[EXTEND_INFO_MAX_ADDRS]
char identity_digest[DIGEST_LEN]
char nickname[MAX_HEX_NICKNAME_LEN+1]
char identity_digest[DIGEST_LEN]
char nickname[MAX_NICKNAME_LEN+1]
char identity_digest[DIGEST_LEN]
int(* kv_parse)(void *target, const struct config_line_t *line, char **errmsg, const void *params)
Header for lib/confmgt/typedvar.c.
void tor_strlower(char *s)
Structure declarations for typedvar type definitions.