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) {
}
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);
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;
// 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 &&
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++) {
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);