routerset.h 3.9 KB

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