mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Call the right signed-directory functions; try to describe the difference between everything; remove some unused interfaces
svn:r276
This commit is contained in:
parent
bcfbccb056
commit
c3998e94f9
@ -117,9 +117,11 @@ void directory_set_dirty(void) {
|
|||||||
|
|
||||||
void directory_rebuild(void) {
|
void directory_rebuild(void) {
|
||||||
if(directory_dirty) {
|
if(directory_dirty) {
|
||||||
/* NICK: This is where the dirserver makes a new <the_directory,directorylen>
|
if (dump_signed_directory_to_string(the_directory, MAX_DIR_SIZE,
|
||||||
* (or whatever it'll be called in the future) pair. */
|
get_signing_privatekey())) {
|
||||||
dump_directory_to_string(the_directory, MAX_DIR_SIZE);
|
log(LOG_ERR, "Error writing directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
log(LOG_INFO,"New directory:\n%s",the_directory);
|
log(LOG_INFO,"New directory:\n%s",the_directory);
|
||||||
directorylen = strlen(the_directory);
|
directorylen = strlen(the_directory);
|
||||||
directory_dirty = 0;
|
directory_dirty = 0;
|
||||||
@ -144,9 +146,7 @@ int connection_dir_process_inbuf(connection_t *conn) {
|
|||||||
log(LOG_DEBUG,"connection_dir_process_inbuf(): Empty directory. Ignoring.");
|
log(LOG_DEBUG,"connection_dir_process_inbuf(): Empty directory. Ignoring.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* NICK: This is where the client parses, checks-the-signature-of, etc the
|
if(router_get_dir_from_string(the_directory, conn->pkey) < 0) {
|
||||||
* new directory. conn->pkey is the signing key of the directory server we chose. */
|
|
||||||
if(router_get_list_from_string(the_directory) < 0) {
|
|
||||||
log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring.");
|
log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring.");
|
||||||
}
|
}
|
||||||
if(options.ORPort) { /* connect to them all */
|
if(options.ORPort) { /* connect to them all */
|
||||||
|
@ -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)
|
static int
|
||||||
{
|
build_directory(directory_t *dir) {
|
||||||
directory_t dir;
|
|
||||||
routerinfo_t **routers = NULL;
|
routerinfo_t **routers = NULL;
|
||||||
connection_t *conn;
|
connection_t *conn;
|
||||||
routerinfo_t *router;
|
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));
|
routers = (routerinfo_t**) malloc(sizeof(routerinfo_t*) * (nfds+1));
|
||||||
if (!routers) {
|
if (!routers) {
|
||||||
/* freak out XXX */
|
/* freak out XXX */
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
if (my_routerinfo) {
|
if (my_routerinfo) {
|
||||||
routers[n++] = my_routerinfo;
|
routers[n++] = my_routerinfo;
|
||||||
@ -675,10 +674,19 @@ void dump_directory_to_string(char *s, int maxlen)
|
|||||||
}
|
}
|
||||||
routers[n++] = router;
|
routers[n++] = router;
|
||||||
}
|
}
|
||||||
dir.routers = routers;
|
dir->routers = routers;
|
||||||
dir.n_routers = n;
|
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
|
int
|
||||||
@ -688,19 +696,32 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
|
|||||||
char *cp;
|
char *cp;
|
||||||
char digest[20];
|
char digest[20];
|
||||||
char signature[128];
|
char signature[128];
|
||||||
int i;
|
int i, written;
|
||||||
|
routerinfo_t *router;
|
||||||
strncpy(s,
|
strncpy(s,
|
||||||
"signed-directory\n"
|
"signed-directory\n"
|
||||||
"client-software x y z\n" /* XXX make this real */
|
"client-software x y z\n" /* XXX make this real */
|
||||||
"server-software a b c\n\n" /* XXX make this real */
|
"server-software a b c\n\n" /* XXX make this real */
|
||||||
, maxlen);
|
, 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
|
/* These multiple strlen calls are inefficient, but dwarfed by the RSA
|
||||||
signature.
|
signature.
|
||||||
*/
|
*/
|
||||||
i = strlen(s);
|
i = strlen(s);
|
||||||
|
|
||||||
dump_directory_to_string_impl(s+i, maxlen-i, dir);
|
|
||||||
i = strlen(s);
|
|
||||||
strncat(s, "directory-signature\n", maxlen-i);
|
strncat(s, "directory-signature\n", maxlen-i);
|
||||||
i = strlen(s);
|
i = strlen(s);
|
||||||
cp = s + i;
|
cp = s + i;
|
||||||
@ -725,26 +746,6 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
|
|||||||
return 0;
|
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) {
|
void daemonize(void) {
|
||||||
/* Fork; parent exits. */
|
/* Fork; parent exits. */
|
||||||
if (fork())
|
if (fork())
|
||||||
|
14
src/or/or.h
14
src/or/or.h
@ -740,10 +740,12 @@ int prepare_for_poll(int *timeout);
|
|||||||
int do_main_loop(void);
|
int do_main_loop(void);
|
||||||
|
|
||||||
void dumpstats(void);
|
void dumpstats(void);
|
||||||
void dump_directory_to_string(char *s, int maxlen);
|
int dump_signed_directory_to_string(char *s, int maxlen,
|
||||||
void dump_directory_to_string_impl(char *s, int maxlen, directory_t *directory);
|
crypto_pk_env_t *private_key);
|
||||||
int dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir, crypto_pk_env_t *private_key);
|
/* Exported for debugging */
|
||||||
|
int dump_signed_directory_to_string_impl(char *s, int maxlen,
|
||||||
|
directory_t *dir,
|
||||||
|
crypto_pk_env_t *private_key);
|
||||||
|
|
||||||
int main(int argc, char *argv[]);
|
int main(int argc, char *argv[]);
|
||||||
|
|
||||||
@ -796,9 +798,13 @@ int router_is_me(uint32_t addr, uint16_t port);
|
|||||||
void router_forget_router(uint32_t addr, uint16_t port);
|
void router_forget_router(uint32_t addr, uint16_t port);
|
||||||
int router_get_list_from_file(char *routerfile);
|
int router_get_list_from_file(char *routerfile);
|
||||||
int router_resolve(routerinfo_t *router);
|
int router_resolve(routerinfo_t *router);
|
||||||
|
/* Reads a list of known routers, unsigned. */
|
||||||
int router_get_list_from_string(char *s);
|
int router_get_list_from_string(char *s);
|
||||||
|
/* Exported for debugging */
|
||||||
int router_get_list_from_string_impl(char *s, directory_t **dest);
|
int router_get_list_from_string_impl(char *s, directory_t **dest);
|
||||||
|
/* Reads a signed directory. */
|
||||||
int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey);
|
int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey);
|
||||||
|
/* Exported or debugging */
|
||||||
int router_get_dir_from_string_impl(char *s, directory_t **dest,
|
int router_get_dir_from_string_impl(char *s, directory_t **dest,
|
||||||
crypto_pk_env_t *pkey);
|
crypto_pk_env_t *pkey);
|
||||||
routerinfo_t *router_get_entry_from_string(char **s);
|
routerinfo_t *router_get_entry_from_string(char **s);
|
||||||
|
Loading…
Reference in New Issue
Block a user