mark all dirservers up at boot; mark a dirserver down if dir fetch fails

svn:r519
This commit is contained in:
Roger Dingledine 2003-09-30 21:27:16 +00:00
parent dc8f40e4cb
commit 5c8fc2f705
4 changed files with 21 additions and 39 deletions

View File

@ -329,13 +329,12 @@ int connection_handle_read(connection_t *conn) {
conn->state == DIR_CONN_STATE_CONNECTING_UPLOAD)) { conn->state == DIR_CONN_STATE_CONNECTING_UPLOAD)) {
/* it's a directory server and connecting failed: forget about this router */ /* it's a directory server and connecting failed: forget about this router */
/* XXX I suspect pollerr may make Windows not get to this point. :( */ /* XXX I suspect pollerr may make Windows not get to this point. :( */
router_forget_router(conn->addr,conn->port); router_mark_as_down(conn->nickname);
/* FIXME i don't think router_forget_router works. */
} }
return -1; return -1;
} }
if(connection_process_inbuf(conn) < 0) { if(connection_process_inbuf(conn) < 0) {
//log_fn(LOG_DEBUG,"connection_process_inbuf returned %d.",retval); // log_fn(LOG_DEBUG,"connection_process_inbuf returned -1.");
return -1; return -1;
} }
return 0; return 0;

View File

@ -21,8 +21,11 @@ static int directorylen=0;
void directory_initiate_command(routerinfo_t *router, int command) { void directory_initiate_command(routerinfo_t *router, int command) {
connection_t *conn; connection_t *conn;
if(!router) /* i guess they didn't have one in mind for me to use */ if(!router) { /* i guess they didn't have one in mind for me to use */
log_fn(LOG_WARNING,"No running dirservers known. This is really bad.");
/* XXX never again will a directory fetch work. Should we exit here, or what? */
return; return;
}
#if 0 /* there's no problem with parallel get/posts now. whichever 'get' ends #if 0 /* there's no problem with parallel get/posts now. whichever 'get' ends
last is the directory. */ last is the directory. */
@ -43,6 +46,7 @@ void directory_initiate_command(routerinfo_t *router, int command) {
conn->addr = router->addr; conn->addr = router->addr;
conn->port = router->dir_port; conn->port = router->dir_port;
conn->address = strdup(router->address); conn->address = strdup(router->address);
conn->nickname = strdup(router->nickname);
if (router->identity_pkey) if (router->identity_pkey)
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey); conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
else { else {
@ -58,7 +62,7 @@ void directory_initiate_command(routerinfo_t *router, int command) {
switch(connection_connect(conn, router->address, router->addr, router->dir_port)) { switch(connection_connect(conn, router->address, router->addr, router->dir_port)) {
case -1: case -1:
router_forget_router(conn->addr, conn->port); /* XXX don't try him again */ router_mark_as_down(conn->nickname); /* don't try him again */
connection_free(conn); connection_free(conn);
return; return;
case 0: case 0:
@ -237,7 +241,7 @@ int connection_dir_finished_flushing(connection_t *conn) {
if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */ if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) { /* not yet */
if(!ERRNO_CONN_EINPROGRESS(errno)) { if(!ERRNO_CONN_EINPROGRESS(errno)) {
log_fn(LOG_DEBUG,"in-progress connect failed. Removing."); log_fn(LOG_DEBUG,"in-progress connect failed. Removing.");
router_forget_router(conn->addr, conn->port); /* don't try him again */ router_mark_as_down(conn->nickname); /* don't try him again */
return -1; return -1;
} else { } else {
return 0; /* no change, see if next time is better */ return 0; /* no change, see if next time is better */

View File

@ -671,12 +671,10 @@ routerinfo_t *router_pick_directory_server(void);
void router_upload_desc_to_dirservers(void); void router_upload_desc_to_dirservers(void);
routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port); routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port);
routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk); routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
#if 0 routerinfo_t *router_get_by_nickname(char *nickname);
routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk);
#endif
void router_get_directory(directory_t **pdirectory); void router_get_directory(directory_t **pdirectory);
int router_is_me(uint32_t addr, uint16_t port); int router_is_me(uint32_t addr, uint16_t port);
void router_forget_router(uint32_t addr, uint16_t port); void router_mark_as_down(char *nickname);
int router_get_list_from_file(char *routerfile); int router_get_list_from_file(char *routerfile);
int router_get_router_hash(char *s, char *digest); int router_get_router_hash(char *s, char *digest);
int router_get_dir_hash(char *s, char *digest); int router_get_dir_hash(char *s, char *digest);

View File

@ -90,7 +90,7 @@ void router_retry_connections(void) {
} }
routerinfo_t *router_pick_directory_server(void) { routerinfo_t *router_pick_directory_server(void) {
/* currently, pick the first router with a positive dir_port */ /* pick the first running router with a positive dir_port */
int i; int i;
routerinfo_t *router; routerinfo_t *router;
@ -99,7 +99,7 @@ routerinfo_t *router_pick_directory_server(void) {
for(i=0;i<directory->n_routers;i++) { for(i=0;i<directory->n_routers;i++) {
router = directory->routers[i]; router = directory->routers[i];
if(router->dir_port > 0) if(router->dir_port > 0 && router->is_running)
return router; return router;
} }
@ -131,7 +131,6 @@ routerinfo_t *router_get_by_addr_port(uint32_t addr, uint16_t port) {
if ((router->addr == addr) && (router->or_port == port)) if ((router->addr == addr) && (router->or_port == port))
return router; return router;
} }
return NULL; return NULL;
} }
@ -147,12 +146,10 @@ routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk)
if (0 == crypto_pk_cmp_keys(router->link_pkey, pk)) if (0 == crypto_pk_cmp_keys(router->link_pkey, pk))
return router; return router;
} }
return NULL; return NULL;
} }
#if 0 routerinfo_t *router_get_by_nickname(char *nickname)
routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk)
{ {
int i; int i;
routerinfo_t *router; routerinfo_t *router;
@ -161,14 +158,11 @@ routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk)
for(i=0;i<directory->n_routers;i++) { for(i=0;i<directory->n_routers;i++) {
router = directory->routers[i]; router = directory->routers[i];
/* XXX Should this really be a separate link key? */ if (0 == strcmp(router->nickname, nickname))
if (0 == crypto_pk_cmp_keys(router->identity_pkey, pk))
return router; return router;
} }
return NULL; return NULL;
} }
#endif
void router_get_directory(directory_t **pdirectory) { void router_get_directory(directory_t **pdirectory) {
*pdirectory = directory; *pdirectory = directory;
@ -238,27 +232,12 @@ void directory_free(directory_t *directory)
free(directory); free(directory);
} }
void router_forget_router(uint32_t addr, uint16_t port) { void router_mark_as_down(char *nickname) {
int i; routerinfo_t *router = router_get_by_nickname(nickname);
routerinfo_t *router;
router = router_get_by_addr_port(addr,port);
if(!router) /* we don't seem to know about him in the first place */ if(!router) /* we don't seem to know about him in the first place */
return; return;
log_fn(LOG_DEBUG,"Marking %s as down.",router->nickname);
/* now walk down router_array until we get to router */ router->is_running = 0;
for(i=0;i<directory->n_routers;i++)
if(directory->routers[i] == router)
break;
assert(i != directory->n_routers); /* if so then router_get_by_addr_port should have returned null */
// free(router); /* don't actually free; we'll free it when we free the whole thing */
// log(LOG_DEBUG,"router_forget_router(): Forgot about router %d:%d",addr,port);
for(; i<directory->n_routers-1;i++)
directory->routers[i] = directory->routers[i+1];
/* XXX bug, we're not decrementing n_routers here? needs more attention. -RD */
} }
/* load the router list */ /* load the router list */
@ -769,6 +748,8 @@ int router_get_list_from_string_impl(char **s, directory_t **dest,
break; break;
} }
} }
} else {
router->is_running = 1; /* start out assuming all dirservers are up */
} }
rarray[rarray_len++] = router; rarray[rarray_len++] = router;
log_fn(LOG_DEBUG,"just added router #%d.",rarray_len); log_fn(LOG_DEBUG,"just added router #%d.",rarray_len);