Back to index

tor  0.2.3.19-rc
dirserv.h
Go to the documentation of this file.
00001 /* Copyright (c) 2001 Matej Pfajfar.
00002  * Copyright (c) 2001-2004, Roger Dingledine.
00003  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
00004  * Copyright (c) 2007-2012, The Tor Project, Inc. */
00005 /* See LICENSE for licensing information */
00006 
00012 #ifndef _TOR_DIRSERV_H
00013 #define _TOR_DIRSERV_H
00014 
00018 #define REACHABILITY_MODULO_PER_TEST 128
00019 
00021 #define REACHABILITY_TEST_INTERVAL 10
00022 
00024 #define REACHABILITY_TEST_CYCLE_PERIOD \
00025   (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST)
00026 
00028 #define MAX_EXITPOLICY_SUMMARY_LEN 1000
00029 
00031 #define MAX_V_LINE_LEN 128
00032 
00034 #define MAX_FLAG_LINE_LEN 96
00035 
00037 #define MAX_WEIGHT_LINE_LEN (12+10+10+10+1)
00038 
00039 #define MAX_POLICY_LINE_LEN (3+MAX_EXITPOLICY_SUMMARY_LEN)
00040 
00041 #define RS_ENTRY_LEN                                                    \
00042   ( /* first line */                                                    \
00043    MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
00044    5*2 /* ports */ + 10 /* punctuation */ +                             \
00045    /* second line */                                                    \
00046    MAX_FLAG_LINE_LEN +                                                  \
00047    /* weight line */                                                    \
00048    MAX_WEIGHT_LINE_LEN +                                                \
00049    /* p line. */                                                        \
00050    MAX_POLICY_LINE_LEN +                                                \
00051    /* v line. */                                                        \
00052    MAX_V_LINE_LEN                                                       \
00053    )
00054 
00055 int connection_dirserv_flushed_some(dir_connection_t *conn);
00056 
00057 int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_t *pk);
00058 int dirserv_load_fingerprint_file(void);
00059 void dirserv_free_fingerprint_list(void);
00060 const char *dirserv_get_nickname_by_digest(const char *digest);
00061 enum was_router_added_t dirserv_add_multiple_descriptors(
00062                                      const char *desc, uint8_t purpose,
00063                                      const char *source,
00064                                      const char **msg);
00065 enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
00066                                                const char **msg,
00067                                                const char *source);
00068 void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
00069 int list_server_status_v1(smartlist_t *routers, char **router_status_out,
00070                           int for_controller);
00071 int dirserv_dump_directory_to_string(char **dir_out,
00072                                      crypto_pk_t *private_key);
00073 
00074 int directory_fetches_from_authorities(const or_options_t *options);
00075 int directory_fetches_dir_info_early(const or_options_t *options);
00076 int directory_fetches_dir_info_later(const or_options_t *options);
00077 int directory_caches_v2_dir_info(const or_options_t *options);
00078 #define directory_caches_v1_dir_info(o) directory_caches_v2_dir_info(o)
00079 int directory_caches_unknown_auth_certs(const or_options_t *options);
00080 int directory_caches_dir_info(const or_options_t *options);
00081 int directory_permits_begindir_requests(const or_options_t *options);
00082 int directory_permits_controller_requests(const or_options_t *options);
00083 int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
00084                                             time_t now);
00085 
00086 void directory_set_dirty(void);
00087 cached_dir_t *dirserv_get_directory(void);
00088 cached_dir_t *dirserv_get_runningrouters(void);
00089 cached_dir_t *dirserv_get_consensus(const char *flavor_name);
00090 void dirserv_set_cached_directory(const char *directory, time_t when,
00091                                   int is_running_routers);
00092 void dirserv_set_cached_networkstatus_v2(const char *directory,
00093                                          const char *identity,
00094                                          time_t published);
00095 void dirserv_set_cached_consensus_networkstatus(const char *consensus,
00096                                                 const char *flavor_name,
00097                                                 const digests_t *digests,
00098                                                 time_t published);
00099 void dirserv_clear_old_networkstatuses(time_t cutoff);
00100 void dirserv_clear_old_v1_info(time_t now);
00101 void dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
00102 void dirserv_get_networkstatus_v2_fingerprints(smartlist_t *result,
00103                                                const char *key);
00104 int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
00105                                         const char **msg,
00106                                         int for_unencrypted_conn,
00107                                         int is_extrainfo);
00108 int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
00109                             const char **msg);
00110 void dirserv_orconn_tls_done(const char *address,
00111                              uint16_t or_port,
00112                              const char *digest_rcvd);
00113 int dirserv_should_launch_reachability_test(const routerinfo_t *ri,
00114                                             const routerinfo_t *ri_old);
00115 void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
00116 void dirserv_test_reachability(time_t now);
00117 int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
00118                                    int complain,
00119                                    int *valid_out);
00120 uint32_t dirserv_router_get_status(const routerinfo_t *router,
00121                                    const char **msg);
00122 void dirserv_set_node_flags_from_authoritative_status(node_t *node,
00123                                                       uint32_t authstatus);
00124 
00125 int dirserv_would_reject_router(const routerstatus_t *rs);
00126 int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
00127 int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
00128 int dirserv_have_any_microdesc(const smartlist_t *fps);
00129 size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
00130                                   int compressed);
00131 size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
00132 
00133 int routerstatus_format_entry(char *buf, size_t buf_len,
00134                               const routerstatus_t *rs, const char *platform,
00135                               routerstatus_format_type_t format);
00136 void dirserv_free_all(void);
00137 void cached_dir_decref(cached_dir_t *d);
00138 cached_dir_t *new_cached_dir(char *s, time_t published);
00139 
00140 #ifdef DIRSERV_PRIVATE
00141 int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
00142 
00143 int measured_bw_line_apply(measured_bw_line_t *parsed_line,
00144                            smartlist_t *routerstatuses);
00145 #endif
00146 
00147 int dirserv_read_measured_bandwidths(const char *from_file,
00148                                      smartlist_t *routerstatuses);
00149 
00150 #endif
00151