void directory_rebuild(void) {
if(directory_dirty) {
-/* NICK: This is where the dirserver makes a new <the_directory,directorylen>
- * (or whatever it'll be called in the future) pair. */
- dump_directory_to_string(the_directory, MAX_DIR_SIZE);
+ if (dump_signed_directory_to_string(the_directory, MAX_DIR_SIZE,
+ get_signing_privatekey())) {
+ log(LOG_ERR, "Error writing directory");
+ return;
+ }
log(LOG_INFO,"New directory:\n%s",the_directory);
directorylen = strlen(the_directory);
directory_dirty = 0;
log(LOG_DEBUG,"connection_dir_process_inbuf(): Empty directory. Ignoring.");
return -1;
}
-/* NICK: This is where the client parses, checks-the-signature-of, etc the
- * new directory. conn->pkey is the signing key of the directory server we chose. */
- if(router_get_list_from_string(the_directory) < 0) {
+ if(router_get_dir_from_string(the_directory, conn->pkey) < 0) {
log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring.");
}
if(options.ORPort) { /* connect to them all */
}
-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;
routers = (routerinfo_t**) malloc(sizeof(routerinfo_t*) * (nfds+1));
if (!routers) {
/* freak out XXX */
- return;
+ return -1;
}
if (my_routerinfo) {
routers[n++] = my_routerinfo;
}
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
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);
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())
int do_main_loop(void);
void dumpstats(void);
-void dump_directory_to_string(char *s, int maxlen);
-void dump_directory_to_string_impl(char *s, int maxlen, directory_t *directory);
-int dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir, crypto_pk_env_t *private_key);
-
+int dump_signed_directory_to_string(char *s, int maxlen,
+ 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[]);
void router_forget_router(uint32_t addr, uint16_t port);
int router_get_list_from_file(char *routerfile);
int router_resolve(routerinfo_t *router);
+/* Reads a list of known routers, unsigned. */
int router_get_list_from_string(char *s);
+/* Exported for debugging */
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);
+/* Exported or debugging */
int router_get_dir_from_string_impl(char *s, directory_t **dest,
crypto_pk_env_t *pkey);
routerinfo_t *router_get_entry_from_string(char **s);