[or-cvs] Revise all calls to connection_edge_end to avoid sending MI...

Nick Mathewson nickm at seul.org
Tue Mar 1 22:42:34 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv22324/src/or

Modified Files:
	connection.c connection_edge.c dns.c hibernate.c or.h relay.c 
Log Message:
Revise all calls to connection_edge_end to avoid sending MISC, and to take errno into account where possible.

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.334
retrieving revision 1.335
diff -u -d -r1.334 -r1.335
--- connection.c	1 Mar 2005 22:16:15 -0000	1.334
+++ connection.c	1 Mar 2005 22:42:31 -0000	1.335
@@ -913,9 +913,7 @@
     /* There's a read error; kill the connection.*/
     connection_close_immediate(conn); /* Don't flush; connection is dead. */
     if (CONN_IS_EDGE(conn)) {
-      connection_edge_end(conn, (char)(connection_state_is_open(conn) ?
-                  END_STREAM_REASON_MISC : END_STREAM_REASON_CONNECTREFUSED),
-                  conn->cpath_layer);
+      connection_edge_end_errno(conn, conn->cpath_layer);
     }
     connection_mark_for_close(conn);
     return -1;
@@ -1083,7 +1081,7 @@
     if (getsockopt(conn->s, SOL_SOCKET, SO_ERROR, (void*)&e, &len) < 0) {
       log_fn(LOG_WARN,"getsockopt() syscall failed?! Please report to tor-ops.");
       if (CONN_IS_EDGE(conn))
-        connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+        connection_edge_end_errno(conn, conn->cpath_layer);
       connection_mark_for_close(conn);
       return -1;
     }
@@ -1092,8 +1090,7 @@
       if (!ERRNO_IS_CONN_EINPROGRESS(e)) {
         log_fn(LOG_INFO,"in-progress connect failed. Removing.");
         if (CONN_IS_EDGE(conn))
-          connection_edge_end(conn, END_STREAM_REASON_CONNECTREFUSED,
-                              conn->cpath_layer);
+          connection_edge_end_errno(conn, conn->cpath_layer);
 
         connection_close_immediate(conn);
         connection_mark_for_close(conn);
@@ -1157,11 +1154,9 @@
   } else {
     result = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen);
     if (result < 0) {
-      /* XXXX Is this right? -NM
       if (CONN_IS_EDGE(conn))
-        connection_edge_end(conn, END_STREAM_REASON_MISC,
-                            conn->cpath_layer);
-      */
+        connection_edge_end_errno(conn, conn->cpath_layer);
+
       connection_close_immediate(conn); /* Don't flush; connection is dead. */
       conn->has_sent_end = 1;
       connection_mark_for_close(conn);

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.286
retrieving revision 1.287
diff -u -d -r1.286 -r1.287
--- connection_edge.c	1 Mar 2005 22:16:15 -0000	1.286
+++ connection_edge.c	1 Mar 2005 22:42:31 -0000	1.287
@@ -78,6 +78,7 @@
     case AP_CONN_STATE_OPEN:
     case EXIT_CONN_STATE_OPEN:
       if (connection_edge_package_raw_inbuf(conn, package_partial) < 0) {
+        /* XXXX We can't tell *why* package failed. -NM */
         connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
         connection_mark_for_close(conn);
         return -1;
@@ -96,7 +97,7 @@
 #ifdef TOR_FRAGILE
   tor_assert(0);
 #endif
-  connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+  connection_edge_end(conn, END_STREAM_REASON_INTERNAL, conn->cpath_layer);
   connection_mark_for_close(conn);
   return -1;
 }
@@ -161,6 +162,17 @@
   return 0;
 }
 
+/** DOCDOC **/
+int
+connection_edge_end_errno(connection_t *conn, crypt_path_t *cpath_layer)
+{
+  uint8_t reason;
+  tor_assert(conn);
+  reason = (uint8_t)errno_to_end_reason(tor_socket_errno(conn->s));
+  return connection_edge_end(conn, reason, cpath_layer);
+}
+
+
 /** Connection <b>conn</b> has finished writing and has no bytes left on
  * its outbuf.
  *
@@ -1036,7 +1048,7 @@
   /* default to failed, change in dns_resolve if it turns out not to fail */
 
   if (we_are_hibernating()) {
-    connection_edge_end(n_stream, END_STREAM_REASON_EXITPOLICY, n_stream->cpath_layer);
+    connection_edge_end(n_stream, END_STREAM_REASON_HIBERNATING, n_stream->cpath_layer);
     connection_free(n_stream);
     return 0;
   }
@@ -1156,8 +1168,7 @@
   log_fn(LOG_DEBUG,"about to try connecting");
   switch (connection_connect(conn, conn->address, addr, port)) {
     case -1:
-      connection_edge_end(conn, END_STREAM_REASON_CONNECTREFUSED,
-                          conn->cpath_layer);
+      connection_edge_end_errno(conn, conn->cpath_layer);
       circuit_detach_stream(circuit_get_by_conn(conn), conn);
       connection_free(conn);
       return;

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dns.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -d -r1.136 -r1.137
--- dns.c	11 Feb 2005 01:26:46 -0000	1.136
+++ dns.c	1 Mar 2005 22:42:31 -0000	1.137
@@ -154,7 +154,7 @@
         /* Connections should only be pending if they have no socket. */
         tor_assert(pend->conn->s == -1);
         pendconn = pend->conn;
-        connection_edge_end(pendconn, END_STREAM_REASON_MISC,
+        connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT,
                             pendconn->cpath_layer);
         circuit_detach_stream(circuit_get_by_conn(pendconn), pendconn);
         connection_free(pendconn);

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- hibernate.c	22 Feb 2005 07:03:03 -0000	1.46
+++ hibernate.c	1 Mar 2005 22:42:31 -0000	1.47
@@ -739,7 +739,8 @@
          (conn = connection_get_by_type(CONN_TYPE_AP)) ||
          (conn = connection_get_by_type(CONN_TYPE_EXIT))) {
     if (CONN_IS_EDGE(conn))
-      connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+      connection_edge_end(conn, END_STREAM_REASON_HIBERNATING,
+                          conn->cpath_layer);
     log_fn(LOG_INFO,"Closing conn type %d", conn->type);
     connection_mark_for_close(conn);
   }

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.546
retrieving revision 1.547
diff -u -d -r1.546 -r1.547
--- or.h	1 Mar 2005 22:16:15 -0000	1.546
+++ or.h	1 Mar 2005 22:42:31 -0000	1.547
@@ -425,6 +425,7 @@
 #define END_STREAM_REASON_INTERNAL 10
 #define END_STREAM_REASON_RESOURCELIMIT 11
 #define END_STREAM_REASON_CONNRESET 12
+#define END_STREAM_REASON_TORPROTOCOL 13
 
 #define RESOLVED_TYPE_IPV4 4
 #define RESOLVED_TYPE_IPV6 6
@@ -1286,6 +1287,7 @@
 int connection_edge_process_inbuf(connection_t *conn, int package_partial);
 int connection_edge_destroy(uint16_t circ_id, connection_t *conn);
 int connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer);
+int connection_edge_end_errno(connection_t *conn, crypt_path_t *cpath_layer);
 int connection_edge_finished_flushing(connection_t *conn);
 int connection_edge_finished_connecting(connection_t *conn);
 
@@ -1527,9 +1529,7 @@
 int connection_edge_package_raw_inbuf(connection_t *conn, int package_partial);
 void connection_edge_consider_sending_sendme(connection_t *conn);
 socks5_reply_status_t connection_edge_end_reason_sock5_response(char *payload, uint16_t length);
-int errno_to_end_reasaon(int e);
-
-
+int errno_to_end_reason(int e);
 
 extern uint64_t stats_n_data_cells_packaged;
 extern uint64_t stats_n_data_bytes_packaged;

Index: relay.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/relay.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- relay.c	1 Mar 2005 22:16:15 -0000	1.42
+++ relay.c	1 Mar 2005 22:42:31 -0000	1.43
@@ -474,6 +474,7 @@
     case END_STREAM_REASON_INTERNAL:       return "internal error at server";
     case END_STREAM_REASON_RESOURCELIMIT:  return "server out of resources";
     case END_STREAM_REASON_CONNRESET:      return "connection reset";
+    case END_STREAM_REASON_TORPROTOCOL:    return "Tor protocol error";
     default:
       log_fn(LOG_WARN,"Reason for ending (%d) not recognized.",*payload);
       return "unknown";
@@ -509,6 +510,8 @@
       return SOCKS5_GENERAL_ERROR;
     case END_STREAM_REASON_CONNRESET:
       return SOCKS5_CONNECTION_REFUSED;
+    case END_STREAM_REASON_TORPROTOCOL:
+      return SOCKS5_GENERAL_ERROR;
     default:
       log_fn(LOG_WARN,"Reason for ending (%d) not recognized.",*payload);
       return SOCKS5_GENERAL_ERROR;
@@ -524,7 +527,7 @@
 #endif
 
 int
-errno_to_end_reasaon(int e)
+errno_to_end_reason(int e)
 {
   switch (e) {
     E_CASE(EPIPE):
@@ -668,7 +671,7 @@
       addr = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE));
       if (!addr) {
         log_fn(LOG_INFO,"...but it claims the IP address was 0.0.0.0. Closing.");
-        connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL, conn->cpath_layer);
         connection_mark_for_close(conn);
         return 0;
       }
@@ -680,6 +683,7 @@
     conn->socks_request->has_finished = 1;
     /* handle anything that might have queued */
     if (connection_edge_package_raw_inbuf(conn, 1) < 0) {
+      /* XXXX we can't tell why package failed. -NM */
       connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
       connection_mark_for_close(conn);
       return 0;
@@ -710,7 +714,7 @@
 
   log_fn(LOG_WARN,"Got an unexpected relay command %d, in state %d (%s). Closing.",
          rh->command, conn->state, conn_state_to_string[conn->type][conn->state]);
-  connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+  connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL, conn->cpath_layer);
   connection_mark_for_close(conn);
   return -1;
 }
@@ -771,7 +775,7 @@
       if (( layer_hint && --layer_hint->deliver_window < 0) ||
           (!layer_hint && --circ->deliver_window < 0)) {
         log_fn(LOG_WARN,"(relay data) circ deliver_window below 0. Killing.");
-        connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
+        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL, conn->cpath_layer);
         connection_mark_for_close(conn);
         return -1;
       }



More information about the tor-commits mailing list