diff options
author | Roger Dingledine <arma@torproject.org> | 2002-10-13 13:17:27 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-10-13 13:17:27 +0000 |
commit | 84a34edfa1490a1503b8d7fc9e0a95f9bcd2a175 (patch) | |
tree | 859c62b1cbafbc692114a78560032d6baa860f2e /src | |
parent | 74787aa2d4845501b5ccd72dec46eaaa4c45a664 (diff) | |
download | tor-84a34edfa1490a1503b8d7fc9e0a95f9bcd2a175.tar tor-84a34edfa1490a1503b8d7fc9e0a95f9bcd2a175.tar.gz |
expire unfinished handshakes too
don't list non-open ORs in the directory
svn:r134
Diffstat (limited to 'src')
-rw-r--r-- | src/or/connection.c | 7 | ||||
-rw-r--r-- | src/or/connection_ap.c | 3 | ||||
-rw-r--r-- | src/or/main.c | 25 |
3 files changed, 21 insertions, 14 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index 1a8ab8ae4..6784580cb 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -103,8 +103,11 @@ connection_t *connection_new(int type) { conn->receiver_bucket = 10240; /* should be enough to do the handshake */ conn->bandwidth = conn->receiver_bucket / 10; /* give it a default */ + conn->timestamp_created = now.tv_sec; - + conn->timestamp_lastread = now.tv_sec; + conn->timestamp_lastwritten = now.tv_sec; + if (connection_speaks_cells(conn)) { conn->f_crypto = crypto_new_cipher_env(CRYPTO_CIPHER_DES); if (!conn->f_crypto) { @@ -224,6 +227,8 @@ int connection_handle_listener_read(connection_t *conn, int new_type, int new_st } newconn->address = strdup(inet_ntoa(remote.sin_addr)); /* remember the remote address */ + newconn->addr = ntohl(remote.sin_addr.s_addr); + newconn->port = ntohs(remote.sin_port); if(connection_add(newconn) < 0) { /* no space, forget it */ connection_free(newconn); diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index d268f5b78..adfceda90 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -346,7 +346,8 @@ int ap_handshake_socks_reply(connection_t *conn, char result) { socks4_info.destport[0] = socks4_info.destport[1] = 0; socks4_info.destip[0] = socks4_info.destip[1] = socks4_info.destip[2] = socks4_info.destip[3] = 0; - connection_write_to_buf((char *)&socks4_info, sizeof(socks4_t), conn); + if(connection_write_to_buf((char *)&socks4_info, sizeof(socks4_t), conn) < 0) + return -1; return connection_flush_buf(conn); /* try to flush it, in case we're about to close the conn */ } diff --git a/src/or/main.c b/src/or/main.c index 36df1f1a4..6295bf0d6 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -347,13 +347,10 @@ int prepare_for_poll(int *timeout) { tmpconn = connection_array[i]; if(!connection_speaks_cells(tmpconn)) continue; /* this conn type doesn't send cells */ - if(!connection_state_is_open(tmpconn)) { - continue; /* only conns in state 'open' need a keepalive */ - /* XXX should time-out unfinished connections someday too */ - } if(now.tv_sec >= tmpconn->timestamp_lastwritten + options.KeepalivePeriod) { - if(!(options.Role & ROLE_OR_CONNECT_ALL) && !circuit_get_by_conn(tmpconn)) { - /* we're an onion proxy, with no circuits. kill it. */ + if((!(options.Role & ROLE_OR_CONNECT_ALL) && !circuit_get_by_conn(tmpconn)) || + (!connection_state_is_open(tmpconn))) { + /* we're an onion proxy, with no circuits; or our handshake has expired. kill it. */ log(LOG_DEBUG,"prepare_for_poll(): Expiring connection to %d (%s:%d).", i,tmpconn->address, tmpconn->port); tmpconn->marked_for_close = 1; @@ -363,7 +360,8 @@ int prepare_for_poll(int *timeout) { // tmpconn->address, tmpconn->port); memset(&cell,0,sizeof(cell_t)); cell.command = CELL_PADDING; - connection_write_cell_to_buf(&cell, tmpconn); + if(connection_write_cell_to_buf(&cell, tmpconn) < 0) + tmpconn->marked_for_close = 1; } } if(!tmpconn->marked_for_close && @@ -603,10 +601,11 @@ void dump_directory_to_string(char *s, int maxlen) { int written; /* first write my own info */ - /* XXX should check for errors here too */ - written = dump_router_to_string(s, maxlen, my_routerinfo); - maxlen -= written; - s += written; + if(my_routerinfo) { + written = dump_router_to_string(s, maxlen, my_routerinfo); + maxlen -= written; + s += written; + } /* now write info for other routers */ for(i=0;i<nfds;i++) { @@ -614,10 +613,12 @@ void dump_directory_to_string(char *s, int maxlen) { if(conn->type != CONN_TYPE_OR) continue; /* we only want to list ORs */ + if(conn->state != OR_CONN_STATE_OPEN) + continue; /* we only want to list ones that successfully handshaked */ router = router_get_by_addr_port(conn->addr,conn->port); if(!router) { log(LOG_ERR,"dump_directory_to_string(): couldn't find router %d:%d!",conn->addr,conn->port); - return; + continue; } written = dump_router_to_string(s, maxlen, router); |