[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[or-cvs] expire unfinished handshakes too



Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or

Modified Files:
	connection.c connection_ap.c main.c 
Log Message:
expire unfinished handshakes too
don't list non-open ORs in the directory



Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- connection.c	2 Oct 2002 22:54:20 -0000	1.31
+++ connection.c	13 Oct 2002 13:17:27 -0000	1.32
@@ -103,8 +103,11 @@
 
   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 @@
   }
 
   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);

Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- connection_ap.c	2 Oct 2002 22:54:20 -0000	1.20
+++ connection_ap.c	13 Oct 2002 13:17:27 -0000	1.21
@@ -346,7 +346,8 @@
   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 */
 }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- main.c	2 Oct 2002 22:54:20 -0000	1.31
+++ main.c	13 Oct 2002 13:17:27 -0000	1.32
@@ -347,13 +347,10 @@
     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 @@
 //            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 @@
   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 @@
 
     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);