mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-23 14:40:51 +01:00
expire unfinished handshakes too
don't list non-open ORs in the directory svn:r134
This commit is contained in:
parent
74787aa2d4
commit
84a34edfa1
3 changed files with 21 additions and 14 deletions
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue