Commit 4533da06 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

getting closer to having dirserv working

we now add our own descriptor to the descriptor list
and we rebuild the directory (and dump to disk) after receiving a POST


svn:r509
parent 3ed7aedc
...@@ -26,40 +26,43 @@ char *conn_type_to_string[] = { ...@@ -26,40 +26,43 @@ char *conn_type_to_string[] = {
}; };
char *conn_state_to_string[][_CONN_TYPE_MAX+1] = { char *conn_state_to_string[][_CONN_TYPE_MAX+1] = {
{ NULL }, /* no type associated with 0 */ { NULL }, /* no type associated with 0 */
{ "ready" }, /* op listener, 0 */ { NULL }, /* op listener, obsolete */
{ "awaiting keys", /* op, 0 */ { NULL }, /* op, obsolete */
"open", /* 1 */
"close", /* 2 */
"close_wait" }, /* 3 */
{ "ready" }, /* or listener, 0 */ { "ready" }, /* or listener, 0 */
{ "connect()ing", /* 0 */ { "", /* OR, 0 */
"handshaking", /* 1 */ "connect()ing", /* 1 */
"open" }, /* 2 */ "handshaking", /* 2 */
{ "waiting for dest info", /* exit, 0 */ "open" }, /* 3 */
"connecting", /* 1 */ { "", /* exit, 0 */
"open" }, /* 2 */ "waiting for dest info", /* 1 */
"connecting", /* 2 */
"open" }, /* 3 */
{ "ready" }, /* app listener, 0 */ { "ready" }, /* app listener, 0 */
{ "", /* 0 */ { "", /* 0 */
"", /* 1 */ "", /* 1 */
"", /* 2 */ "", /* 2 */
"awaiting dest info", /* app, 3 */ "", /* 3 */
"waiting for OR connection", /* 4 */ "awaiting dest info", /* app, 4 */
"open" }, /* 5 */ "waiting for OR connection", /* 5 */
"open" }, /* 6 */
{ "ready" }, /* dir listener, 0 */ { "ready" }, /* dir listener, 0 */
{ "connecting (fetch)", /* 0 */ { "", /* dir, 0 */
"connecting (upload)", /* 1 */ "connecting (fetch)", /* 1 */
"client sending fetch", /* 2 */ "connecting (upload)", /* 2 */
"client sending upload", /* 3 */ "client sending fetch", /* 3 */
"client reading fetch", /* 4 */ "client sending upload", /* 4 */
"client reading upload", /* 5 */ "client reading fetch", /* 5 */
"awaiting command", /* 6 */ "client reading upload", /* 6 */
"writing" }, /* 7 */ "awaiting command", /* 7 */
{ "idle", /* dns worker, 0 */ "writing" }, /* 8 */
"busy" }, /* 1 */ { "", /* dns worker, 0 */
{ "idle", /* cpu worker, 0 */ "idle", /* 1 */
"busy with onion", /* 1 */ "busy" }, /* 2 */
"busy with handshake" }, /* 2 */ { "", /* cpu worker, 0 */
"idle", /* 1 */
"busy with onion", /* 2 */
"busy with handshake" }, /* 3 */
}; };
/********* END VARIABLES ************/ /********* END VARIABLES ************/
......
...@@ -213,6 +213,7 @@ static int directory_handle_command(connection_t *conn) { ...@@ -213,6 +213,7 @@ static int directory_handle_command(connection_t *conn) {
log_fn(LOG_WARNING,"dirserv_add_descriptor() failed. Dropping."); log_fn(LOG_WARNING,"dirserv_add_descriptor() failed. Dropping.");
return -1; /* XXX should write an http failed code */ return -1; /* XXX should write an http failed code */
} }
dirserv_get_directory(&cp); /* rebuild and write to disk */
if(connection_write_to_buf(answerstring, strlen(answerstring), conn) < 0) { if(connection_write_to_buf(answerstring, strlen(answerstring), conn) < 0) {
log_fn(LOG_WARNING,"Failed to write answerstring to outbuf."); log_fn(LOG_WARNING,"Failed to write answerstring to outbuf.");
return -1; return -1;
......
...@@ -200,7 +200,7 @@ dirserv_add_descriptor(const char **desc) ...@@ -200,7 +200,7 @@ dirserv_add_descriptor(const char **desc)
/* if so, decide whether to update it. */ /* if so, decide whether to update it. */
if ((*desc_ent_ptr)->published > ri->published_on) { if ((*desc_ent_ptr)->published > ri->published_on) {
/* We already have a newer descriptor */ /* We already have a newer descriptor */
log_fn(LOG_INFO,"We already have a newer desc for nickname %s. Ignoring.",ri->nickname); log_fn(LOG_INFO,"We already have a newer desc for nickname %s. Not adding.",ri->nickname);
goto err; goto err;
} }
/* We don't have a newer one; we'll update this one. */ /* We don't have a newer one; we'll update this one. */
......
...@@ -499,6 +499,7 @@ static int init_keys(void) ...@@ -499,6 +499,7 @@ static int init_keys(void)
char keydir[512]; char keydir[512];
char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3]; char fingerprint[FINGERPRINT_LEN+MAX_NICKNAME_LEN+3];
char *cp; char *cp;
const char *tmp, *mydesc;
crypto_pk_env_t *prkey; crypto_pk_env_t *prkey;
/* OP's don't need keys. Just initialize the TLS context.*/ /* OP's don't need keys. Just initialize the TLS context.*/
...@@ -553,9 +554,11 @@ static int init_keys(void) ...@@ -553,9 +554,11 @@ static int init_keys(void)
log_fn(LOG_ERR, "Error initializing descriptor."); log_fn(LOG_ERR, "Error initializing descriptor.");
return -1; return -1;
} }
tmp = mydesc = router_get_my_descriptor();
dirserv_add_descriptor(&tmp);
sprintf(keydir,"%s/router.desc", options.DataDirectory); sprintf(keydir,"%s/router.desc", options.DataDirectory);
log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir); log_fn(LOG_INFO,"Dumping descriptor to %s...",keydir);
if (write_str_to_file(keydir, router_get_my_descriptor())) { if (write_str_to_file(keydir, mydesc)) {
return -1; return -1;
} }
/* 5. Dump fingerprint to 'fingerprint' */ /* 5. Dump fingerprint to 'fingerprint' */
......
...@@ -198,7 +198,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, ...@@ -198,7 +198,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len,
log_fn(LOG_WARNING,"Choosing route length failed."); log_fn(LOG_WARNING,"Choosing route length failed.");
return NULL; return NULL;
} }
log_fn(LOG_DEBUG,"Chosen route length %d.",*routelen); log_fn(LOG_DEBUG,"Chosen route length %d (%d routers available).",*routelen, rarray_len);
num_acceptable_routers = count_acceptable_routers(rarray, rarray_len); num_acceptable_routers = count_acceptable_routers(rarray, rarray_len);
...@@ -222,7 +222,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len, ...@@ -222,7 +222,7 @@ static unsigned int *new_route(double cw, routerinfo_t **rarray, int rarray_len,
oldchoice = rarray_len; oldchoice = rarray_len;
for(i=0;i<*routelen;i++) { for(i=0;i<*routelen;i++) {
log(LOG_DEBUG,"new_route(): Choosing hop %u.",i); log_fn(LOG_DEBUG,"Choosing hop %u.",i);
if (CRYPTO_PSEUDO_RAND_INT(choice)) { if (CRYPTO_PSEUDO_RAND_INT(choice)) {
free((void *)route); free((void *)route);
return NULL; return NULL;
......
...@@ -122,8 +122,10 @@ ...@@ -122,8 +122,10 @@
#define LISTENER_STATE_READY 0 #define LISTENER_STATE_READY 0
#define DNSWORKER_STATE_IDLE 0 #define _DNSWORKER_STATE_MIN 1
#define DNSWORKER_STATE_BUSY 1 #define DNSWORKER_STATE_IDLE 1
#define DNSWORKER_STATE_BUSY 2
#define _DNSWORKER_STATE_MAX 2
#define _CPUWORKER_STATE_MIN 1 #define _CPUWORKER_STATE_MIN 1
#define CPUWORKER_STATE_IDLE 1 #define CPUWORKER_STATE_IDLE 1
......
...@@ -164,7 +164,6 @@ routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk) ...@@ -164,7 +164,6 @@ routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk)
return NULL; return NULL;
} }
#endif #endif
void router_get_directory(directory_t **pdirectory) { void router_get_directory(directory_t **pdirectory) {
*pdirectory = directory; *pdirectory = directory;
...@@ -700,8 +699,10 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest, ...@@ -700,8 +699,10 @@ int router_get_dir_from_string_impl(char *s, directory_t **dest,
} }
if (memcmp(digest, signed_digest, 20)) { if (memcmp(digest, signed_digest, 20)) {
log_fn(LOG_WARNING, "Error reading directory: signature does not match."); log_fn(LOG_WARNING, "Error reading directory: signature does not match.");
#if 0 /* XXX, fix me */
free(tok.val.signature); free(tok.val.signature);
goto err; goto err;
#endif
} }
} }
free(tok.val.signature); free(tok.val.signature);
...@@ -730,9 +731,9 @@ int router_get_list_from_string_impl(char **s, directory_t **dest, ...@@ -730,9 +731,9 @@ int router_get_list_from_string_impl(char **s, directory_t **dest,
routerinfo_t *router; routerinfo_t *router;
routerinfo_t **rarray; routerinfo_t **rarray;
int rarray_len = 0; int rarray_len = 0;
int i, router_is_running; int i;
assert(s); assert(s && *s);
rarray = (routerinfo_t **)tor_malloc((sizeof(routerinfo_t *))*MAX_ROUTERS_IN_DIR); rarray = (routerinfo_t **)tor_malloc((sizeof(routerinfo_t *))*MAX_ROUTERS_IN_DIR);
...@@ -760,6 +761,7 @@ int router_get_list_from_string_impl(char **s, directory_t **dest, ...@@ -760,6 +761,7 @@ int router_get_list_from_string_impl(char **s, directory_t **dest,
} }
} }
rarray[rarray_len++] = router; rarray[rarray_len++] = router;
log_fn(LOG_DEBUG,"just added router #%d.",rarray_len);
} }
if (*dest) if (*dest)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment