Split directory/router parsing functionality into separate file from routerlist.c

svn:r1846
This commit is contained in:
Nick Mathewson
2004-05-10 17:30:51 +00:00
parent cfcb032a1e
commit b45fafa3d0
7 changed files with 1082 additions and 1064 deletions
+2 -2
View File
@@ -8,7 +8,7 @@ tor_SOURCES = buffers.c circuit.c command.c config.c \
connection.c connection_edge.c connection_or.c \
cpuworker.c directory.c dirserv.c dns.c main.c \
onion.c rendcommon.c rendclient.c rendmid.c \
rendservice.c rephist.c router.c routerlist.c \
rendservice.c rephist.c router.c routerlist.c routerparse.c \
tor_main.c
tor_LDADD = ../common/libor.a
@@ -17,7 +17,7 @@ test_SOURCES = buffers.c circuit.c command.c config.c \
connection.c connection_edge.c connection_or.c \
cpuworker.c directory.c dirserv.c dns.c main.c \
onion.c rendcommon.c rendclient.c rendmid.c \
rendservice.c rephist.c router.c routerlist.c \
rendservice.c rephist.c router.c routerlist.c routerparse.c \
test.c
test_LDADD = ../common/libor.a
+1 -1
View File
@@ -268,7 +268,7 @@ dirserv_add_descriptor(const char **desc)
cp = desc_tmp = tor_strndup(start, desc_len);
/* Check: is the descriptor syntactically valid? */
ri = router_get_entry_from_string(cp, NULL);
ri = router_parse_entry_from_string(cp, NULL);
tor_free(desc_tmp);
if (!ri) {
log(LOG_WARN, "Couldn't parse descriptor");
+15 -4
View File
@@ -1185,16 +1185,13 @@ routerinfo_t *router_choose_random_node(routerlist_t *dir,
routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
routerinfo_t *router_get_by_nickname(char *nickname);
void router_get_routerlist(routerlist_t **prouterlist);
void routerlist_free(routerlist_t *routerlist);
void routerinfo_free(routerinfo_t *router);
routerinfo_t *routerinfo_copy(const routerinfo_t *router);
void router_mark_as_down(char *nickname);
int router_set_routerlist_from_file(char *routerfile);
int router_set_routerlist_from_string(const char *s);
int router_get_dir_hash(const char *s, char *digest);
int router_get_router_hash(const char *s, char *digest);
int router_set_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey);
routerinfo_t *router_get_entry_from_string(const char *s, const char *end);
int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
struct exit_policy_t *policy);
#define ADDR_POLICY_ACCEPTED 0
@@ -1203,6 +1200,20 @@ int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port);
int router_exit_policy_rejects_all(routerinfo_t *router);
/********************************* routerparse.c ************************/
int router_get_router_hash(const char *s, char *digest);
int router_get_dir_hash(const char *s, char *digest);
int router_parse_list_from_string(const char **s,
routerlist_t **dest,
int n_good_nicknames,
const char **good_nickname_lst);
int router_parse_routerlist_from_directory(const char *s,
routerlist_t **dest,
crypto_pk_env_t *pkey);
routerinfo_t *router_parse_entry_from_string(const char *s, const char *end);
int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
/********************************* dirserv.c ***************************/
int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
int dirserv_parse_fingerprint_file(const char *fname);
+1 -1
View File
@@ -652,7 +652,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
#ifdef DEBUG_ROUTER_DUMP_ROUTER_TO_STRING
cp = s_tmp = s_dup = tor_strdup(s);
ri_tmp = router_get_entry_from_string(cp, NULL);
ri_tmp = router_parse_entry_from_string(cp, NULL);
if (!ri_tmp) {
log_fn(LOG_ERR, "We just generated a router descriptor we can't parse: <<%s>>",
s);
+8 -1051
View File
File diff suppressed because it is too large Load Diff
+1052
View File
File diff suppressed because it is too large Load Diff
+3 -5
View File
@@ -20,8 +20,6 @@ extern or_options_t options;
int have_failed = 0;
/* These functions are file-local, but are exposed so we can test. */
int router_get_routerlist_from_directory_impl(
const char *s, routerlist_t **dest, crypto_pk_env_t *pkey);
void add_fingerprint_to_dir(const char *nickname, const char *fp);
void get_platform_str(char *platform, int len);
@@ -727,7 +725,7 @@ test_dir_format()
test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
cp = buf;
rp1 = router_get_entry_from_string((const char*)cp,NULL);
rp1 = router_parse_entry_from_string((const char*)cp,NULL);
test_assert(rp1);
test_streq(rp1->address, r1.address);
test_eq(rp1->or_port, r1.or_port);
@@ -750,7 +748,7 @@ test_dir_format()
test_streq(buf, buf2);
cp = buf;
rp2 = router_get_entry_from_string(&cp);
rp2 = router_parse_entry_from_string(&cp);
test_assert(rp2);
test_streq(rp2->address, r2.address);
test_eq(rp2->or_port, r2.or_port);
@@ -787,7 +785,7 @@ test_dir_format()
options.Nickname = "DirServer";
test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3));
cp = buf;
test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3));
test_assert(!router_parse_routerlist_from_directory(buf, &dir1, pk3));
test_eq(2, smartlist_len(dir1->routers));
dirserv_free_fingerprint_list();