From 1969c8a92f628d6c4dcbd8e179d6a3e8f59bd6e3 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Mon, 10 Nov 2003 08:06:55 +0000 Subject: [PATCH] client now survives going offline better fix badness in usage() if neither socksport nor orrport is defined, quit obsolete connection_flush_buf() svn:r780 --- README | 8 ++++---- doc/TODO | 11 ++++------- src/or/config.c | 7 ++++++- src/or/connection.c | 4 ---- src/or/connection_edge.c | 6 +++--- src/or/directory.c | 30 ++++++++---------------------- src/or/or.h | 1 - src/or/routers.c | 15 +++++++++++++-- src/or/test.c | 2 +- 9 files changed, 39 insertions(+), 45 deletions(-) diff --git a/README b/README index 388cf23317..6d8294309a 100644 --- a/README +++ b/README @@ -23,10 +23,10 @@ Do you want to run a tor server? resolution works. Make sure other people can reliably resolve the Address you chose. - Then run tor to generate keys. One of the generated files is your - 'fingerprint' file. Mail it to arma@mit.edu. Remember that you won't - be able to authenticate to the other tor nodes until I've added you - to the directory. + Then run tor to generate keys. One of the files generated + in your DataDirectory is your 'fingerprint' file. Mail it to + arma@mit.edu. Remember that you won't be able to authenticate to the + other tor nodes until I've added you to the directory. Configuring tsocks: diff --git a/doc/TODO b/doc/TODO index 01596b0e10..81fed95f37 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,10 +1,7 @@ -mutiny suggests: if none of the ports is defined maybe it shouldn't start. -aaron got a crash in tor_timegm in tzset on os x, with -l warn but not with -l debug. -Oct 25 04:29:17.017 [warn] directory_initiate_command(): No running dirservers known. This is really bad. rename ACI to CircID rotate tls-level connections -- make new ones, expire old ones. dirserver shouldn't put you in running-routers list if you haven't - uploading a descriptor recently + uploaded a descriptor recently look at having smallcells and largecells separate trying to rebuild a circuit because you have none from trying to rebuild a circuit because the current one is stale @@ -32,9 +29,9 @@ ARMA - arma claims Short-term: . integrate rep_ok functions, see what breaks - update tor faq - . obey SocksBindAddress, ORBindAddress + o obey SocksBindAddress, ORBindAddress - warn if we're running as root - - make connection_flush_buf() more obviously obsolete + o make connection_flush_buf() more obviously obsolete . let hup reread the config file, eg so we can get new exit policies without restarting - use times(2) rather than gettimeofday to measure how long it @@ -78,7 +75,7 @@ Short-term: - make sure exiting from the not-last hop works - logic to find last *open* hop, not last hop, in cpath - choose exit nodes by exit policies - - Remember address and port when resolving. + - Remember address and port when beginning. - Extend by nickname/hostname/something, not by IP. On-going diff --git a/src/or/config.c b/src/or/config.c index 02948a6f01..f9518aead8 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -213,7 +213,7 @@ void print_usage(void) { "-e \t\tExit policy\n" "-l \t\tLog level\n" "-m \t\tMax number of connections\n" - "-s \t\t\tAddress to bind to for Socks\n" + "-s \t\t\tPort to bind to for Socks\n" ); /* split things up to be ANSI compliant */ printf("-n \t\tNickname of router\n" @@ -353,6 +353,11 @@ int getconfig(int argc, char **argv, or_options_t *options) { result = -1; } + if(options->SocksPort == 0 && options->ORPort == 0) { + log(LOG_WARN,"SocksPort and ORPort are both undefined? Quitting."); + result = -1; + } + if(options->DirPort < 0) { log(LOG_WARN,"DirPort option can't be negative."); result = -1; diff --git a/src/or/connection.c b/src/or/connection.c index 237e47f1ae..685c5b1ae0 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -429,10 +429,6 @@ int connection_outbuf_too_full(connection_t *conn) { return (conn->outbuf_flushlen > 10*CELL_PAYLOAD_SIZE); } -int connection_flush_buf(connection_t *conn) { - return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); -} - /* return -1 if you want to break the conn, else return 0 */ int connection_handle_write(connection_t *conn) { diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 710d4bd62d..d7927f436c 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -578,7 +578,7 @@ static int connection_ap_handshake_socks_reply(connection_t *conn, char *reply, if(replylen) { /* we already have a reply in mind */ connection_write_to_buf(reply, replylen, conn); - return connection_flush_buf(conn); /* try to flush it */ + return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); /* try to flush it */ } if(conn->socks_version == 4) { memset(buf,0,SOCKS4_NETWORK_LEN); @@ -587,7 +587,7 @@ static int connection_ap_handshake_socks_reply(connection_t *conn, char *reply, buf[1] = (success ? SOCKS4_GRANTED : SOCKS4_REJECT); /* leave version, destport, destip zero */ connection_write_to_buf(buf, SOCKS4_NETWORK_LEN, conn); - return connection_flush_buf(conn); /* try to flush it */ + return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); /* try to flush it */ } if(conn->socks_version == 5) { buf[0] = 5; /* version 5 */ @@ -598,7 +598,7 @@ static int connection_ap_handshake_socks_reply(connection_t *conn, char *reply, buf[3] = 1; /* ipv4 addr */ memset(buf+4,0,6); /* XXX set external addr/port to 0, see what breaks */ connection_write_to_buf(buf,10,conn); - return connection_flush_buf(conn); /* try to flush it */ + return flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen); /* try to flush it */ } return 0; /* if socks_version isn't 4 or 5, don't send anything */ } diff --git a/src/or/directory.c b/src/or/directory.c index fb92bf75a4..204909ee85 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -21,25 +21,16 @@ 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 */ - log_fn(LOG_WARN,"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. */ - if(connection_get_by_type(CONN_TYPE_DIR)) { /* there's already a dir conn running */ - log_fn(LOG_DEBUG,"Canceling connect, dir conn already active."); - return; - } -#endif - - if(command == DIR_CONN_STATE_CONNECTING_FETCH) + if (command == DIR_CONN_STATE_CONNECTING_FETCH) log_fn(LOG_DEBUG,"initiating directory fetch"); else log_fn(LOG_DEBUG,"initiating directory upload"); + if (!router) { /* i guess they didn't have one in mind for me to use */ + log_fn(LOG_WARN,"No running dirservers known. Not trying."); + return; + } + conn = connection_new(CONN_TYPE_DIR); /* set up conn so it's got all the data we need to remember */ @@ -47,13 +38,8 @@ void directory_initiate_command(routerinfo_t *router, int command) { conn->port = router->dir_port; conn->address = tor_strdup(router->address); conn->nickname = tor_strdup(router->nickname); - if (router->identity_pkey) - conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey); - else { - log_fn(LOG_WARN, "No signing key known for dirserver %s; signature won't be checked", conn->address); - conn->identity_pkey = NULL; - /* XXX is there really any situation where router doesn't have an identity_pkey? */ - } + assert(router->identity_pkey); + conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey); if(connection_add(conn) < 0) { /* no space, forget it */ connection_free(conn); diff --git a/src/or/or.h b/src/or/or.h index 27c9740c00..eaadbfd88a 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -560,7 +560,6 @@ int connection_find_on_inbuf(char *string, int len, connection_t *conn); int connection_wants_to_flush(connection_t *conn); int connection_outbuf_too_full(connection_t *conn); -int connection_flush_buf(connection_t *conn); int connection_handle_write(connection_t *conn); void connection_write_to_buf(const char *string, int len, connection_t *conn); diff --git a/src/or/routers.c b/src/or/routers.c index daf70b5b7a..c0e93017f5 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -55,7 +55,7 @@ void router_retry_connections(void) { routerinfo_t *router_pick_directory_server(void) { /* pick the first running router with a positive dir_port */ int i; - routerinfo_t *router; + routerinfo_t *router, *dirserver=NULL; if(!directory) return NULL; @@ -66,7 +66,18 @@ routerinfo_t *router_pick_directory_server(void) { return router; } - return NULL; + log_fn(LOG_WARN,"No dirservers are up. Giving them all another chance."); + /* no running dir servers found? go through and mark them all as up, + * and we'll cycle through the list again. */ + for(i=0;in_routers;i++) { + router = directory->routers[i]; + if(router->dir_port > 0) { + router->is_running = 1; + dirserver = router; + } + } + + return dirserver; } void router_upload_desc_to_dirservers(void) { diff --git a/src/or/test.c b/src/or/test.c index bdc6f43fb2..a653c179b0 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -449,7 +449,7 @@ test_util() { test_eq(0L, tv_udiff(&start, &end)); /* The test values here are confirmed to be correct on a platform - * with a working timgm. */ + * with a working timegm. */ a_time.tm_year = 2003-1900; a_time.tm_mon = 7; a_time.tm_mday = 30;