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)) {
/* it's a directory server and connecting failed: forget about this router */
/* XXX I suspect pollerr may make Windows not get to this point. :( */
router_forget_router(conn->addr,conn->port);
/* FIXME i don't think router_forget_router works. */
router_mark_as_down(conn->nickname);
}
return -1;
}
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 0;

View File

@ -21,8 +21,11 @@ static int directorylen=0;
void directory_initiate_command(routerinfo_t *router, int command) {
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;
}
#if 0 /* there's no problem with parallel get/posts now. whichever 'get' ends
last is the directory. */
@ -43,6 +46,7 @@ void directory_initiate_command(routerinfo_t *router, int command) {
conn->addr = router->addr;
conn->port = router->dir_port;
conn->address = strdup(router->address);
conn->nickname = strdup(router->nickname);
if (router->identity_pkey)
conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
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)) {
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);
return;
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(!ERRNO_CONN_EINPROGRESS(errno)) {
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;
} else {
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);
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);
#if 0
routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk);
#endif
routerinfo_t *router_get_by_nickname(char *nickname);
void router_get_directory(directory_t **pdirectory);
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_router_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) {
/* currently, pick the first router with a positive dir_port */
/* pick the first running router with a positive dir_port */
int i;
routerinfo_t *router;
@ -99,7 +99,7 @@ routerinfo_t *router_pick_directory_server(void) {
for(i=0;i<directory->n_routers;i++) {
router = directory->routers[i];
if(router->dir_port > 0)
if(router->dir_port > 0 && router->is_running)
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))
return router;
}
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))
return router;
}
return NULL;
}
#if 0
routerinfo_t *router_get_by_identity_pk(crypto_pk_env_t *pk)
routerinfo_t *router_get_by_nickname(char *nickname)
{
int i;
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++) {
router = directory->routers[i];
/* XXX Should this really be a separate link key? */
if (0 == crypto_pk_cmp_keys(router->identity_pkey, pk))
if (0 == strcmp(router->nickname, nickname))
return router;
}
return NULL;
}
#endif
void router_get_directory(directory_t **pdirectory) {
*pdirectory = directory;
@ -238,27 +232,12 @@ void directory_free(directory_t *directory)
free(directory);
}
void router_forget_router(uint32_t addr, uint16_t port) {
int i;
routerinfo_t *router;
router = router_get_by_addr_port(addr,port);
void router_mark_as_down(char *nickname) {
routerinfo_t *router = router_get_by_nickname(nickname);
if(!router) /* we don't seem to know about him in the first place */
return;
/* now walk down router_array until we get to router */
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 */
log_fn(LOG_DEBUG,"Marking %s as down.",router->nickname);
router->is_running = 0;
}
/* load the router list */
@ -769,6 +748,8 @@ int router_get_list_from_string_impl(char **s, directory_t **dest,
break;
}
}
} else {
router->is_running = 1; /* start out assuming all dirservers are up */
}
rarray[rarray_len++] = router;
log_fn(LOG_DEBUG,"just added router #%d.",rarray_len);