[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] work around a tsocks bug



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	connection.c connection_edge.c or.h 
Log Message:
work around a tsocks bug

when an AP connection dies early, be sure to do a socks reject
for it. if you just hang up, tsocks goes into an infinite loop.


Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -d -r1.186 -r1.187
--- connection.c	27 Mar 2004 01:28:14 -0000	1.186
+++ connection.c	27 Mar 2004 05:45:51 -0000	1.187
@@ -199,8 +199,14 @@
       }
       /* No special processing needed. */
       break;
-    case CONN_TYPE_EXIT:
     case CONN_TYPE_AP:
+      if (conn->socks_request->has_finished == 0) {
+        log_fn(LOG_INFO,"Cleaning up AP -- sending socks reject.");
+        connection_ap_handshake_socks_reply(conn, NULL, 0, 0);
+        conn->socks_request->has_finished = 1;
+      }
+      /* fall through, to do things for both ap and exit */
+    case CONN_TYPE_EXIT:
       if (conn->state == EXIT_CONN_STATE_RESOLVING)
         connection_dns_remove(conn);
       if (!conn->has_sent_end && reason &&
@@ -1004,13 +1010,16 @@
     assert(!conn->done_sending);
     assert(!conn->done_receiving);
   } else {
-    if(conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_OPEN)
-      assert(conn->cpath_layer);
-    if(conn->cpath_layer)
-      assert_cpath_layer_ok(conn->cpath_layer);
     /* XXX unchecked: package window, deliver window. */
   }
-  if (conn->type != CONN_TYPE_AP) {
+  if (conn->type == CONN_TYPE_AP) {
+    assert(conn->socks_request);
+    if (conn->state == AP_CONN_STATE_OPEN) {
+      assert(conn->socks_request->has_finished);
+      assert(conn->cpath_layer);
+      assert_cpath_layer_ok(conn->cpath_layer);
+    }
+  } else {
     assert(!conn->socks_request);
   }
 

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- connection_edge.c	20 Mar 2004 09:30:30 -0000	1.118
+++ connection_edge.c	27 Mar 2004 05:45:52 -0000	1.119
@@ -12,8 +12,6 @@
 static int connection_ap_handshake_attach_circuit(connection_t *conn);
 static int connection_ap_handshake_attach_circuit_helper(connection_t *conn);
 static void connection_ap_handshake_send_begin(connection_t *ap_conn, circuit_t *circ);
-static void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
-                                                int replylen, char success);
 
 static int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
 static void connection_edge_consider_sending_sendme(connection_t *conn);
@@ -284,6 +282,7 @@
              (int)(time(NULL) - conn->timestamp_lastread));
       circuit_log_path(LOG_INFO,circ);
       connection_ap_handshake_socks_reply(conn, NULL, 0, 1);
+      conn->socks_request->has_finished = 1;
       return 0;
     } else {
       log_fn(LOG_WARN,"Got an unexpected relay command %d, in state %d (%s). Closing.",
@@ -704,6 +703,8 @@
     } else {
       log_fn(LOG_DEBUG,"socks handshake not all here yet.");
     }
+    if (sockshere == -1)
+      conn->socks_request->has_finished = 1;
     return sockshere;
   } /* else socks handshake is done, continue processing */
 
@@ -848,8 +849,8 @@
   return;
 }
 
-static void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
-                                               int replylen, char success) {
+void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
+                                         int replylen, char success) {
   char buf[256];
 
   if(replylen) { /* we already have a reply in mind */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.256
retrieving revision 1.257
diff -u -d -r1.256 -r1.257
--- or.h	21 Mar 2004 03:03:10 -0000	1.256
+++ or.h	27 Mar 2004 05:45:52 -0000	1.257
@@ -554,6 +554,7 @@
   char socks_version;
   int replylen;
   char reply[MAX_SOCKS_REPLY_LEN];
+  int has_finished; /* has the socks handshake finished? */
   char address[MAX_SOCKS_ADDR_LEN];
   uint16_t port;
 };
@@ -750,6 +751,9 @@
 
 int connection_edge_package_raw_inbuf(connection_t *conn);
 
+void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
+                                         int replylen, char success);
+
 void connection_exit_connect(connection_t *conn);
 int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit);
 void connection_ap_expire_beginning(void);