aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-09-30 21:27:16 +0000
committerRoger Dingledine <arma@torproject.org>2003-09-30 21:27:16 +0000
commit5c8fc2f7059c87d283603c59b21dea541cbf19aa (patch)
tree1ae7b14b01782ed75834087338c73ce1a3d6c1fe /src
parentdc8f40e4cb6ab40f42bd5557aeea1e2b4d97f6b5 (diff)
downloadtor-5c8fc2f7059c87d283603c59b21dea541cbf19aa.tar
tor-5c8fc2f7059c87d283603c59b21dea541cbf19aa.tar.gz
mark all dirservers up at boot; mark a dirserver down if dir fetch fails
svn:r519
Diffstat (limited to 'src')
-rw-r--r--src/or/connection.c5
-rw-r--r--src/or/directory.c10
-rw-r--r--src/or/or.h6
-rw-r--r--src/or/routers.c39
4 files changed, 21 insertions, 39 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index a0fea8c70..ab401771b 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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;
diff --git a/src/or/directory.c b/src/or/directory.c
index b936484f4..4cbae07b2 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -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 */
diff --git a/src/or/or.h b/src/or/or.h
index c3eb26512..7a3034061 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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);
diff --git a/src/or/routers.c b/src/or/routers.c
index e1f01df6e..a991a3933 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -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);