diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-05-08 03:36:53 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-05-08 03:36:53 +0000 |
commit | c3998e94f9175f588bad98fa70d674136b617212 (patch) | |
tree | 5fc3bac3cdaff83a650fee6e6f852a1d53f02da4 /src/or/main.c | |
parent | bcfbccb056a94d37f20cd528dcf052f1558770d2 (diff) | |
download | tor-c3998e94f9175f588bad98fa70d674136b617212.tar.gz tor-c3998e94f9175f588bad98fa70d674136b617212.zip |
Call the right signed-directory functions; try to describe the difference between everything; remove some unused interfaces
svn:r276
Diffstat (limited to 'src/or/main.c')
-rw-r--r-- | src/or/main.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/or/main.c b/src/or/main.c index 7d200b558f..b5199e3511 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -645,9 +645,8 @@ int dump_router_to_string(char *s, int maxlen, routerinfo_t *router) { } -void dump_directory_to_string(char *s, int maxlen) -{ - directory_t dir; +static int +build_directory(directory_t *dir) { routerinfo_t **routers = NULL; connection_t *conn; routerinfo_t *router; @@ -656,7 +655,7 @@ void dump_directory_to_string(char *s, int maxlen) routers = (routerinfo_t**) malloc(sizeof(routerinfo_t*) * (nfds+1)); if (!routers) { /* freak out XXX */ - return; + return -1; } if (my_routerinfo) { routers[n++] = my_routerinfo; @@ -675,10 +674,19 @@ void dump_directory_to_string(char *s, int maxlen) } routers[n++] = router; } - dir.routers = routers; - dir.n_routers = n; + dir->routers = routers; + dir->n_routers = n; + return 0; +} - dump_directory_to_string_impl(s, maxlen, &dir); +int +dump_signed_directory_to_string(char *s, int maxlen, + crypto_pk_env_t *private_key) +{ + directory_t dir; + if (!build_directory(&dir)) + return -1; + return dump_signed_directory_to_string_impl(s, maxlen, &dir, private_key); } int @@ -688,18 +696,31 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir, char *cp; char digest[20]; char signature[128]; - int i; + int i, written; + routerinfo_t *router; strncpy(s, "signed-directory\n" "client-software x y z\n" /* XXX make this real */ "server-software a b c\n\n" /* XXX make this real */ , maxlen); + for (i = 0; i < dir->n_routers; ++i) { + router = dir->routers[i]; + written = dump_router_to_string(s, maxlen, router); + + if(written < 0) { + log(LOG_ERR,"dump_directory_to_string(): tried to exceed string length."); + s[maxlen-1] = 0; /* make sure it's null terminated */ + return -1; + } + + maxlen -= written; + s += written; + } + + /* These multiple strlen calls are inefficient, but dwarfed by the RSA signature. */ - i = strlen(s); - - dump_directory_to_string_impl(s+i, maxlen-i, dir); i = strlen(s); strncat(s, "directory-signature\n", maxlen-i); i = strlen(s); @@ -725,26 +746,6 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir, return 0; } -void dump_directory_to_string_impl(char *s, int maxlen, directory_t *directory) { - int i; - routerinfo_t *router; - int written; - - for (i = 0; i < directory->n_routers; ++i) { - router = directory->routers[i]; - written = dump_router_to_string(s, maxlen, router); - - if(written < 0) { - log(LOG_ERR,"dump_directory_to_string(): tried to exceed string length."); - s[maxlen-1] = 0; /* make sure it's null terminated */ - return; - } - - maxlen -= written; - s += written; - } -} - void daemonize(void) { /* Fork; parent exits. */ if (fork()) |