Back to index

tor  0.2.3.18-rc
routerlist.h
Go to the documentation of this file.
00001 /* Copyright (c) 2001-2004, Roger Dingledine.
00002  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
00003  * Copyright (c) 2007-2012, The Tor Project, Inc. */
00004 /* See LICENSE for licensing information */
00005 
00011 #ifndef _TOR_ROUTERLIST_H
00012 #define _TOR_ROUTERLIST_H
00013 
00014 int get_n_authorities(dirinfo_type_t type);
00015 int trusted_dirs_reload_certs(void);
00016 int trusted_dirs_load_certs_from_string(const char *contents, int from_store,
00017                                         int flush);
00018 void trusted_dirs_flush_certs_to_disk(void);
00019 authority_cert_t *authority_cert_get_newest_by_id(const char *id_digest);
00020 authority_cert_t *authority_cert_get_by_sk_digest(const char *sk_digest);
00021 authority_cert_t *authority_cert_get_by_digests(const char *id_digest,
00022                                                 const char *sk_digest);
00023 void authority_cert_get_all(smartlist_t *certs_out);
00024 void authority_cert_dl_failed(const char *id_digest, int status);
00025 void authority_certs_fetch_missing(networkstatus_t *status, time_t now);
00026 int router_reload_router_list(void);
00027 int authority_cert_dl_looks_uncertain(const char *id_digest);
00028 smartlist_t *router_get_trusted_dir_servers(void);
00029 
00030 const routerstatus_t *router_pick_directory_server(dirinfo_type_t type,
00031                                                    int flags);
00032 trusted_dir_server_t *router_get_trusteddirserver_by_digest(const char *d);
00033 trusted_dir_server_t *trusteddirserver_get_by_v3_auth_digest(const char *d);
00034 const routerstatus_t *router_pick_trusteddirserver(dirinfo_type_t type,
00035                                                    int flags);
00036 int router_get_my_share_of_directory_requests(double *v2_share_out,
00037                                               double *v3_share_out);
00038 void router_reset_status_download_failures(void);
00039 int routers_have_same_or_addr(const routerinfo_t *r1, const routerinfo_t *r2);
00040 int router_nickname_is_in_list(const routerinfo_t *router, const char *list);
00041 const routerinfo_t *routerlist_find_my_routerinfo(void);
00042 const node_t *router_find_exact_exit_enclave(const char *address,
00043                                              uint16_t port);
00044 int node_is_unreliable(const node_t *router, int need_uptime,
00045                          int need_capacity, int need_guard);
00046 uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
00047 uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router);
00048 
00049 const node_t *node_sl_choose_by_bandwidth(smartlist_t *sl,
00050                                           bandwidth_weight_rule_t rule);
00051 
00052 const node_t *router_choose_random_node(smartlist_t *excludedsmartlist,
00053                                         struct routerset_t *excludedset,
00054                                         router_crn_flags_t flags);
00055 
00056 const routerinfo_t *router_get_by_nickname(const char *nickname,
00057                                      int warn_if_unnamed);
00058 int router_is_named(const routerinfo_t *router);
00059 int router_digest_is_trusted_dir_type(const char *digest,
00060                                       dirinfo_type_t type);
00061 #define router_digest_is_trusted_dir(d) \
00062   router_digest_is_trusted_dir_type((d), NO_DIRINFO)
00063 
00064 int router_addr_is_trusted_dir(uint32_t addr);
00065 int hexdigest_to_digest(const char *hexdigest, char *digest);
00066 const routerinfo_t *router_get_by_hexdigest(const char *hexdigest);
00067 const routerinfo_t *router_get_by_id_digest(const char *digest);
00068 routerinfo_t *router_get_mutable_by_digest(const char *digest);
00069 signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
00070 signed_descriptor_t *router_get_by_extrainfo_digest(const char *digest);
00071 signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
00072 const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
00073 const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
00074 routerlist_t *router_get_routerlist(void);
00075 void routerinfo_free(routerinfo_t *router);
00076 void extrainfo_free(extrainfo_t *extrainfo);
00077 void routerlist_free(routerlist_t *rl);
00078 void dump_routerlist_mem_usage(int severity);
00079 void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
00080                        time_t now);
00081 void routerlist_free_all(void);
00082 void routerlist_reset_warnings(void);
00083 void router_set_status(const char *digest, int up);
00084 
00085 static int WRA_WAS_ADDED(was_router_added_t s);
00086 static int WRA_WAS_OUTDATED(was_router_added_t s);
00087 static int WRA_WAS_REJECTED(was_router_added_t s);
00092 static INLINE int
00093 WRA_WAS_ADDED(was_router_added_t s) {
00094   return s == ROUTER_ADDED_SUCCESSFULLY || s == ROUTER_ADDED_NOTIFY_GENERATOR;
00095 }
00102 static INLINE int WRA_WAS_OUTDATED(was_router_added_t s)
00103 {
00104   return (s == ROUTER_WAS_NOT_NEW ||
00105           s == ROUTER_NOT_IN_CONSENSUS ||
00106           s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS);
00107 }
00110 static INLINE int WRA_WAS_REJECTED(was_router_added_t s)
00111 {
00112   return (s == ROUTER_AUTHDIR_REJECTS);
00113 }
00114 was_router_added_t router_add_to_routerlist(routerinfo_t *router,
00115                                             const char **msg,
00116                                             int from_cache,
00117                                             int from_fetch);
00118 was_router_added_t router_add_extrainfo_to_routerlist(
00119                                         extrainfo_t *ei, const char **msg,
00120                                         int from_cache, int from_fetch);
00121 void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
00122 void routerlist_remove_old_routers(void);
00123 int router_load_single_router(const char *s, uint8_t purpose, int cache,
00124                               const char **msg);
00125 int router_load_routers_from_string(const char *s, const char *eos,
00126                                      saved_location_t saved_location,
00127                                      smartlist_t *requested_fingerprints,
00128                                      int descriptor_digests,
00129                                      const char *prepend_annotations);
00130 void router_load_extrainfo_from_string(const char *s, const char *eos,
00131                                        saved_location_t saved_location,
00132                                        smartlist_t *requested_fingerprints,
00133                                        int descriptor_digests);
00134 
00135 void routerlist_retry_directory_downloads(time_t now);
00136 int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
00137                                         int need_uptime);
00138 
00139 int router_exit_policy_rejects_all(const routerinfo_t *router);
00140 trusted_dir_server_t *add_trusted_dir_server(const char *nickname,
00141                            const char *address,
00142                            uint16_t dir_port, uint16_t or_port,
00143                            const char *digest, const char *v3_auth_digest,
00144                            dirinfo_type_t type);
00145 void authority_cert_free(authority_cert_t *cert);
00146 void clear_trusted_dir_servers(void);
00147 int any_trusted_dir_is_v1_authority(void);
00148 void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
00149                                                   networkstatus_t *consensus);
00150 void update_router_descriptor_downloads(time_t now);
00151 void update_all_descriptor_downloads(time_t now);
00152 void update_extrainfo_downloads(time_t now);
00153 int router_have_minimum_dir_info(void);
00154 void router_dir_info_changed(void);
00155 const char *get_dir_info_status_string(void);
00156 int count_loading_descriptors_progress(void);
00157 void router_reset_descriptor_download_failures(void);
00158 int router_differences_are_cosmetic(const routerinfo_t *r1,
00159                                     const routerinfo_t *r2);
00160 int routerinfo_incompatible_with_extrainfo(const routerinfo_t *ri,
00161                                            extrainfo_t *ei,
00162                                            signed_descriptor_t *sd,
00163                                            const char **msg);
00164 
00165 void routerlist_assert_ok(const routerlist_t *rl);
00166 const char *esc_router_info(const routerinfo_t *router);
00167 void routers_sort_by_identity(smartlist_t *routers);
00168 
00169 routerset_t *routerset_new(void);
00170 void routerset_refresh_countries(routerset_t *rs);
00171 int routerset_parse(routerset_t *target, const char *s,
00172                     const char *description);
00173 void routerset_union(routerset_t *target, const routerset_t *source);
00174 int routerset_is_list(const routerset_t *set);
00175 int routerset_needs_geoip(const routerset_t *set);
00176 int routerset_is_empty(const routerset_t *set);
00177 int routerset_contains_router(const routerset_t *set, const routerinfo_t *ri,
00178                               country_t country);
00179 int routerset_contains_routerstatus(const routerset_t *set,
00180                                     const routerstatus_t *rs,
00181                                     country_t country);
00182 int routerset_contains_extendinfo(const routerset_t *set,
00183                                   const extend_info_t *ei);
00184 
00185 int routerset_contains_node(const routerset_t *set, const node_t *node);
00186 void routerset_get_all_nodes(smartlist_t *out, const routerset_t *routerset,
00187                              const routerset_t *excludeset,
00188                              int running_only);
00189 #if 0
00190 void routersets_get_node_disjunction(smartlist_t *target,
00191                                 const smartlist_t *source,
00192                                 const routerset_t *include,
00193                                 const routerset_t *exclude, int running_only);
00194 #endif
00195 void routerset_subtract_nodes(smartlist_t *out,
00196                                 const routerset_t *routerset);
00197 
00198 char *routerset_to_string(const routerset_t *routerset);
00199 int routerset_equal(const routerset_t *old, const routerset_t *new);
00200 void routerset_free(routerset_t *routerset);
00201 void refresh_all_country_info(void);
00202 
00203 int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
00204                                          const char *id);
00205 int hid_serv_acting_as_directory(void);
00206 int hid_serv_responsible_for_desc_id(const char *id);
00207 
00208 void list_pending_microdesc_downloads(digestmap_t *result);
00209 void launch_descriptor_downloads(int purpose,
00210                                  smartlist_t *downloadable,
00211                                  const routerstatus_t *source,
00212                                  time_t now);
00213 
00214 int hex_digest_nickname_decode(const char *hexdigest,
00215                                char *digest_out,
00216                                char *nickname_qualifier_out,
00217                                char *nickname_out);
00218 
00219 #endif
00220