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

[or-cvs] r9899: Refactor a bunch of functions that take edge_connection_t no (in tor/trunk: . src/or)



Author: nickm
Date: 2007-03-24 11:57:51 -0400 (Sat, 24 Mar 2007)
New Revision: 9899

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/command.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/connection_edge.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/dns.c
   tor/trunk/src/or/hibernate.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/relay.c
   tor/trunk/src/or/rendclient.c
   tor/trunk/src/or/rendmid.c
   tor/trunk/src/or/rendservice.c
   tor/trunk/src/or/router.c
Log:
 r12643@0-41-wifi:  nickm | 2007-03-23 14:56:35 -0400
 Refactor a bunch of functions that take edge_connection_t not to also take a crypt_path_t; the cpath is implicit.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12643] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/ChangeLog	2007-03-24 15:57:51 UTC (rev 9899)
@@ -40,7 +40,7 @@
 
   o Minor bugfixes (other):
     - Stop allowing hibernating servers to be "stable" or "fast".
-    - Check return values from pthread_mutex functions. 
+    - Check return values from pthread_mutex functions.
     - Don't save non-general-purpose router descriptors to the disk cache,
       because we have no way of remembering what their purpose was when
       we restart.
@@ -56,7 +56,11 @@
     - Correct the control spec to match how the code actually responds
       to 'getinfo addr-mappings/*'.
 
+  o Code simplifications and refactoring
+    - Stop passing around crypt_path_t pointers that are implicit in other
+      procedure arguments.
 
+
 Changes in version 0.1.2.12-rc - 2007-03-16
   o Major bugfixes:
     - Fix an infinite loop introduced in 0.1.2.7-alpha when we serve

Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/circuitbuild.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -653,7 +653,7 @@
     log_debug(LD_CIRC,"Sending extend relay cell.");
     /* send it to hop->prev, because it will transfer
      * it to a create cell and then send to hop */
-    if (connection_edge_send_command(NULL, TO_CIRCUIT(circ),
+    if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
                                      RELAY_COMMAND_EXTEND,
                                      payload, payload_len, hop->prev) < 0)
       return 0; /* circuit is closed */

Modified: tor/trunk/src/or/command.c
===================================================================
--- tor/trunk/src/or/command.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/command.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -292,7 +292,7 @@
     log_debug(LD_OR,
               "Converting created cell to extended relay cell, sending.");
     connection_edge_send_command(NULL, circ, RELAY_COMMAND_EXTENDED,
-                                 cell->payload, ONIONSKIN_REPLY_LEN, NULL);
+                                 cell->payload, ONIONSKIN_REPLY_LEN);
   }
 }
 
@@ -384,7 +384,7 @@
       log_debug(LD_OR, "Delivering 'truncated' back.");
       payload[0] = (char)reason;
       connection_edge_send_command(NULL, circ, RELAY_COMMAND_TRUNCATED,
-                                   payload, sizeof(payload), NULL);
+                                   payload, sizeof(payload));
     }
   }
 }

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/connection.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -1506,7 +1506,7 @@
     connection_close_immediate(conn); /* Don't flush; connection is dead. */
     if (CONN_IS_EDGE(conn)) {
       edge_connection_t *edge_conn = TO_EDGE_CONN(conn);
-      connection_edge_end_errno(edge_conn, edge_conn->cpath_layer);
+      connection_edge_end_errno(edge_conn);
       if (edge_conn->socks_request) /* broken, don't send a socks reply back */
         edge_conn->socks_request->has_finished = 1;
     }
@@ -1737,8 +1737,7 @@
       log_warn(LD_BUG,
                "getsockopt() syscall failed?! Please report to tor-ops.");
       if (CONN_IS_EDGE(conn))
-        connection_edge_end_errno(TO_EDGE_CONN(conn),
-                                  TO_EDGE_CONN(conn)->cpath_layer);
+        connection_edge_end_errno(TO_EDGE_CONN(conn));
       connection_mark_for_close(conn);
       return -1;
     }
@@ -1747,8 +1746,7 @@
       if (!ERRNO_IS_CONN_EINPROGRESS(e)) {
         log_info(LD_NET,"in-progress connect failed. Removing.");
         if (CONN_IS_EDGE(conn))
-          connection_edge_end_errno(TO_EDGE_CONN(conn),
-                                    TO_EDGE_CONN(conn)->cpath_layer);
+          connection_edge_end_errno(TO_EDGE_CONN(conn));
 
         connection_close_immediate(conn);
         connection_mark_for_close(conn);
@@ -1827,8 +1825,7 @@
                                 max_to_write, &conn->outbuf_flushlen));
     if (result < 0) {
       if (CONN_IS_EDGE(conn))
-        connection_edge_end_errno(TO_EDGE_CONN(conn),
-                                  TO_EDGE_CONN(conn)->cpath_layer);
+        connection_edge_end_errno(TO_EDGE_CONN(conn));
 
       connection_close_immediate(conn); /* Don't flush; connection is dead. */
       connection_mark_for_close(conn);

Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/connection_edge.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -83,7 +83,7 @@
   if (!conn->_base.marked_for_close) {
     /* only mark it if not already marked. it's possible to
      * get the 'end' right around when the client hangs up on us. */
-    connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer);
+    connection_edge_end(conn, END_STREAM_REASON_DONE);
     if (conn->socks_request) /* eof, so don't send a socks reply back */
       conn->socks_request->has_finished = 1;
     connection_mark_for_close(TO_CONN(conn));
@@ -140,7 +140,7 @@
   }
   log_warn(LD_BUG,"Got unexpected state %d. Closing.",conn->_base.state);
   tor_fragile_assert();
-  connection_edge_end(conn, END_STREAM_REASON_INTERNAL, conn->cpath_layer);
+  connection_edge_end(conn, END_STREAM_REASON_INTERNAL);
   connection_mark_for_close(TO_CONN(conn));
   return -1;
 }
@@ -173,17 +173,14 @@
   return 0;
 }
 
-/** Send a relay end cell from stream <b>conn</b> to conn's circuit,
- * with a destination of cpath_layer. (If cpath_layer is NULL, the
- * destination is the circuit's origin.) Set the relay end cell's
- * reason for closing as <b>reason</b>.
+/** Send a relay end cell from stream <b>conn</b> down conn's circuit.  Set
+ * the relay end cell's reason for closing as <b>reason</b>.
  *
  * Return -1 if this function has already been called on this conn,
  * else return 0.
  */
 int
-connection_edge_end(edge_connection_t *conn, char reason,
-                    crypt_path_t *cpath_layer)
+connection_edge_end(edge_connection_t *conn, char reason)
 {
   char payload[RELAY_PAYLOAD_SIZE];
   size_t payload_len=1;
@@ -215,7 +212,7 @@
   if (circ && !circ->marked_for_close) {
     log_debug(LD_EDGE,"Sending end on conn (fd %d).",conn->_base.s);
     connection_edge_send_command(conn, circ, RELAY_COMMAND_END,
-                                 payload, payload_len, cpath_layer);
+                                 payload, payload_len);
   } else {
     log_debug(LD_EDGE,"No circ to send end on conn (fd %d).",
               conn->_base.s);
@@ -227,16 +224,16 @@
 }
 
 /** An error has just occured on an operation on an edge connection
- * <b>conn</b>.  Extract the errno; convert it to an end reason, and send
- * an appropriate relay end cell to <b>cpath_layer</b>.
+ * <b>conn</b>.  Extract the errno; convert it to an end reason, and send an
+ * appropriate relay end cell to the other end of the connection's circuit.
  **/
 int
-connection_edge_end_errno(edge_connection_t *conn, crypt_path_t *cpath_layer)
+connection_edge_end_errno(edge_connection_t *conn)
 {
   uint8_t reason;
   tor_assert(conn);
   reason = (uint8_t)errno_to_end_reason(tor_socket_errno(conn->_base.s));
-  return connection_edge_end(conn, reason, cpath_layer);
+  return connection_edge_end(conn, reason);
 }
 
 /** Connection <b>conn</b> has finished writing and has no bytes left on
@@ -305,8 +302,7 @@
   if (connection_edge_is_rendezvous_stream(edge_conn)) {
     if (connection_edge_send_command(edge_conn,
                                      circuit_get_by_edge_conn(edge_conn),
-                                     RELAY_COMMAND_CONNECTED, NULL, 0,
-                                     edge_conn->cpath_layer) < 0)
+                                     RELAY_COMMAND_CONNECTED, NULL, 0) < 0)
       return 0; /* circuit is closed, don't continue */
   } else {
     char connected_payload[8];
@@ -316,8 +312,7 @@
     if (connection_edge_send_command(edge_conn,
                                      circuit_get_by_edge_conn(edge_conn),
                                      RELAY_COMMAND_CONNECTED,
-                                     connected_payload, 8,
-                                     edge_conn->cpath_layer) < 0)
+                                     connected_payload, 8) < 0)
       return 0; /* circuit is closed, don't continue */
   }
   tor_assert(edge_conn->package_window > 0);
@@ -408,8 +403,7 @@
                " '%s.onion'.",
                seconds_idle,
                safe_str(conn->socks_request->address));
-        connection_edge_end(conn, END_STREAM_REASON_TIMEOUT,
-                            conn->cpath_layer);
+        connection_edge_end(conn, END_STREAM_REASON_TIMEOUT);
         connection_mark_unattached_ap(conn, END_STREAM_REASON_TIMEOUT);
       }
       continue;
@@ -423,7 +417,7 @@
            seconds_idle, safe_str(conn->socks_request->address),
            nickname ? nickname : "*unnamed*");
     /* send an end down the circuit */
-    connection_edge_end(conn, END_STREAM_REASON_TIMEOUT, conn->cpath_layer);
+    connection_edge_end(conn, END_STREAM_REASON_TIMEOUT);
     /* un-mark it as ending, since we're going to reuse it */
     conn->_base.edge_has_sent_end = 0;
     conn->end_reason = 0;
@@ -1782,8 +1776,7 @@
 
   if (connection_edge_send_command(ap_conn, TO_CIRCUIT(circ), begin_type,
                   begin_type == RELAY_COMMAND_BEGIN ? payload : NULL,
-                  begin_type == RELAY_COMMAND_BEGIN ? payload_len : 0,
-                                   ap_conn->cpath_layer) < 0)
+                  begin_type == RELAY_COMMAND_BEGIN ? payload_len : 0) < 0)
     return -1; /* circuit is closed, don't continue */
 
   ap_conn->package_window = STREAMWINDOW_START;
@@ -1850,7 +1843,7 @@
 
   if (connection_edge_send_command(ap_conn, TO_CIRCUIT(circ),
                            RELAY_COMMAND_RESOLVE,
-                           string_addr, payload_len, ap_conn->cpath_layer) < 0)
+                           string_addr, payload_len) < 0)
     return -1; /* circuit is closed, don't continue */
 
   ap_conn->_base.state = AP_CONN_STATE_RESOLVE_WAIT;
@@ -2340,8 +2333,7 @@
       router_compare_to_my_exit_policy(edge_conn)) {
     log_info(LD_EXIT,"%s:%d failed exit policy. Closing.",
              escaped_safe_str(conn->address), conn->port);
-    connection_edge_end(edge_conn, END_STREAM_REASON_EXITPOLICY,
-                        edge_conn->cpath_layer);
+    connection_edge_end(edge_conn, END_STREAM_REASON_EXITPOLICY);
     circuit_detach_stream(circuit_get_by_edge_conn(edge_conn), edge_conn);
     connection_free(conn);
     return;
@@ -2373,7 +2365,7 @@
   log_debug(LD_EXIT,"about to try connecting");
   switch (connection_connect(conn, conn->address, addr, port)) {
     case -1:
-      connection_edge_end_errno(edge_conn, edge_conn->cpath_layer);
+      connection_edge_end_errno(edge_conn);
       circuit_detach_stream(circuit_get_by_edge_conn(edge_conn), edge_conn);
       connection_free(conn);
       return;
@@ -2402,7 +2394,7 @@
     connection_edge_send_command(edge_conn,
                                  circuit_get_by_edge_conn(edge_conn),
                                  RELAY_COMMAND_CONNECTED,
-                                 NULL, 0, edge_conn->cpath_layer);
+                                 NULL, 0);
   } else { /* normal stream */
     /* This must be the original address, not the redirected address. */
     char connected_payload[8];
@@ -2412,7 +2404,7 @@
     connection_edge_send_command(edge_conn,
                                  circuit_get_by_edge_conn(edge_conn),
                                  RELAY_COMMAND_CONNECTED,
-                                 connected_payload, 8, edge_conn->cpath_layer);
+                                 connected_payload, 8);
   }
 }
 
@@ -2437,8 +2429,7 @@
              "Couldn't construct socketpair (%s). "
              "Network down? Out of sockets?",
              tor_socket_strerror(-err));
-    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT,
-                        exit_conn->cpath_layer);
+    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT);
     connection_free(TO_CONN(exit_conn));
     return 0;
   }
@@ -2463,16 +2454,14 @@
   dir_conn->_base.state = DIR_CONN_STATE_SERVER_COMMAND_WAIT;
 
   if (connection_add(TO_CONN(exit_conn))<0) {
-    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT,
-                        exit_conn->cpath_layer);
+    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT);
     connection_free(TO_CONN(exit_conn));
     connection_free(TO_CONN(dir_conn));
     return 0;
   }
 
   if (connection_add(TO_CONN(dir_conn))<0) {
-    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT,
-                        exit_conn->cpath_layer);
+    connection_edge_end(exit_conn, END_STREAM_REASON_RESOURCELIMIT);
     connection_close_immediate(TO_CONN(exit_conn));
     connection_mark_for_close(TO_CONN(exit_conn));
     connection_free(TO_CONN(dir_conn));
@@ -2487,8 +2476,7 @@
 
   if (connection_edge_send_command(exit_conn,
                                    circuit_get_by_edge_conn(exit_conn),
-                                   RELAY_COMMAND_CONNECTED, NULL, 0,
-                                   exit_conn->cpath_layer) < 0) {
+                                   RELAY_COMMAND_CONNECTED, NULL, 0) < 0) {
     connection_mark_for_close(TO_CONN(exit_conn));
     connection_mark_for_close(TO_CONN(dir_conn));
     return 0;

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/control.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -1931,8 +1931,7 @@
   /* Do we need to detach it first? */
   if (ap_conn->_base.state != AP_CONN_STATE_CONTROLLER_WAIT) {
     circuit_t *tmpcirc = circuit_get_by_edge_conn(ap_conn);
-    connection_edge_end(ap_conn, END_STREAM_REASON_TIMEOUT,
-                        ap_conn->cpath_layer);
+    connection_edge_end(ap_conn, END_STREAM_REASON_TIMEOUT);
     /* Un-mark it as ending, since we're going to reuse it. */
     ap_conn->_base.edge_has_sent_end = 0;
     ap_conn->end_reason = 0;

Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/dns.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -348,8 +348,7 @@
         /* Connections should only be pending if they have no socket. */
         tor_assert(pend->conn->_base.s == -1);
         pendconn = pend->conn;
-        connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT,
-                            pendconn->cpath_layer);
+        connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT);
         circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
         connection_free(TO_CONN(pendconn));
         tor_free(pend);
@@ -433,8 +432,7 @@
   }
 
   connection_edge_send_command(conn, TO_CIRCUIT(circ),
-                               RELAY_COMMAND_RESOLVED, buf, buflen,
-                               conn->cpath_layer);
+                               RELAY_COMMAND_RESOLVED, buf, buflen);
 }
 
 /** Send a response to the RESOLVE request of a connection for an in-addr.arpa
@@ -472,8 +470,7 @@
 
   // log_notice(LD_EXIT, "Sending a reply RESOLVED reply: %s", hostname);
   connection_edge_send_command(conn, TO_CIRCUIT(circ),
-                               RELAY_COMMAND_RESOLVED, buf, buflen,
-                               conn->cpath_layer);
+                               RELAY_COMMAND_RESOLVED, buf, buflen);
   // log_notice(LD_EXIT, "Sent");
 }
 
@@ -817,8 +814,7 @@
     assert_connection_ok(TO_CONN(pendconn), 0);
     tor_assert(pendconn->_base.s == -1);
     if (!pendconn->_base.marked_for_close) {
-      connection_edge_end(pendconn, END_STREAM_REASON_RESOURCELIMIT,
-                          pendconn->cpath_layer);
+      connection_edge_end(pendconn, END_STREAM_REASON_RESOURCELIMIT);
     }
     circ = circuit_get_by_edge_conn(pendconn);
     if (circ)
@@ -953,8 +949,7 @@
       /* prevent double-remove. */
       pendconn->_base.state = EXIT_CONN_STATE_RESOLVEFAILED;
       if (pendconn->_base.purpose == EXIT_PURPOSE_CONNECT) {
-        connection_edge_end(pendconn, END_STREAM_REASON_RESOLVEFAILED,
-                            pendconn->cpath_layer);
+        connection_edge_end(pendconn, END_STREAM_REASON_RESOLVEFAILED);
         /* This detach must happen after we send the end cell. */
         circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
       } else {

Modified: tor/trunk/src/or/hibernate.c
===================================================================
--- tor/trunk/src/or/hibernate.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/hibernate.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -849,8 +849,7 @@
          (conn = connection_get_by_type(CONN_TYPE_AP)) ||
          (conn = connection_get_by_type(CONN_TYPE_EXIT))) {
     if (CONN_IS_EDGE(conn))
-      connection_edge_end(TO_EDGE_CONN(conn), END_STREAM_REASON_HIBERNATING,
-                          TO_EDGE_CONN(conn)->cpath_layer);
+      connection_edge_end(TO_EDGE_CONN(conn), END_STREAM_REASON_HIBERNATING);
     log_info(LD_NET,"Closing conn type %d", conn->type);
     if (conn->type == CONN_TYPE_AP) /* send socks failure if needed */
       connection_mark_unattached_ap(TO_EDGE_CONN(conn),

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/main.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -433,8 +433,7 @@
       tor_fragile_assert();
 #endif
       if (CONN_IS_EDGE(conn))
-        connection_edge_end_errno(TO_EDGE_CONN(conn),
-                                  TO_EDGE_CONN(conn)->cpath_layer);
+        connection_edge_end_errno(TO_EDGE_CONN(conn));
       connection_mark_for_close(conn);
     }
   }

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/or.h	2007-03-24 15:57:51 UTC (rev 9899)
@@ -2190,10 +2190,8 @@
 int connection_edge_process_inbuf(edge_connection_t *conn,
                                   int package_partial);
 int connection_edge_destroy(uint16_t circ_id, edge_connection_t *conn);
-int connection_edge_end(edge_connection_t *conn, char reason,
-                        crypt_path_t *cpath_layer);
-int connection_edge_end_errno(edge_connection_t *conn,
-                              crypt_path_t *cpath_layer);
+int connection_edge_end(edge_connection_t *conn, char reason);
+int connection_edge_end_errno(edge_connection_t *conn);
 int connection_edge_finished_flushing(edge_connection_t *conn);
 int connection_edge_finished_connecting(edge_connection_t *conn);
 
@@ -2623,8 +2621,7 @@
                                size_t payload_len, crypt_path_t *cpath_layer);
 int connection_edge_send_command(edge_connection_t *fromconn, circuit_t *circ,
                                  int relay_command, const char *payload,
-                                 size_t payload_len,
-                                 crypt_path_t *cpath_layer);
+                                 size_t payload_len);
 int connection_edge_package_raw_inbuf(edge_connection_t *conn,
                                       int package_partial);
 void connection_edge_consider_sending_sendme(edge_connection_t *conn);

Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/relay.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -514,9 +514,10 @@
 int
 connection_edge_send_command(edge_connection_t *fromconn, circuit_t *circ,
                              int relay_command, const char *payload,
-                             size_t payload_len, crypt_path_t *cpath_layer)
+                             size_t payload_len)
 {
   /* XXXX NM Split this function into a separate versions per circuit type? */
+  crypt_path_t *cpath_layer = fromconn ? fromconn->cpath_layer : NULL;
 
   if (fromconn && fromconn->_base.marked_for_close) {
     log_warn(LD_BUG,
@@ -882,8 +883,7 @@
       if (!addr) {
         log_info(LD_APP,
                  "...but it claims the IP address was 0.0.0.0. Closing.");
-        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL,
-                            conn->cpath_layer);
+        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL);
         connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);
         return 0;
       }
@@ -953,8 +953,7 @@
          rh->command, conn->_base.state,
          conn_state_to_string(conn->_base.type, conn->_base.state));
   return 0; /* for forward compatibility, don't kill the circuit */
-//  connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL,
-//                      conn->cpath_layer);
+//  connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL);
 //  connection_mark_for_close(conn);
 //  return -1;
 }
@@ -1023,8 +1022,7 @@
           (!layer_hint && --circ->deliver_window < 0)) {
         log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
                "(relay data) circ deliver_window below 0. Killing.");
-        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL,
-                            conn->cpath_layer);
+        connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL);
         connection_mark_for_close(TO_CONN(conn));
         return -END_CIRC_REASON_TORPROTOCOL;
       }
@@ -1117,7 +1115,7 @@
         char payload[1];
         payload[0] = (char)END_CIRC_REASON_REQUESTED;
         connection_edge_send_command(NULL, circ, RELAY_COMMAND_TRUNCATED,
-                                     payload, sizeof(payload), NULL);
+                                     payload, sizeof(payload));
       }
       return 0;
     case RELAY_COMMAND_TRUNCATED:
@@ -1280,7 +1278,7 @@
             (int)length, (int)buf_datalen(conn->_base.inbuf));
 
   if (connection_edge_send_command(conn, circ, RELAY_COMMAND_DATA,
-                                   payload, length, conn->cpath_layer) < 0)
+                                   payload, length) < 0 )
     /* circuit got marked for close, don't continue, don't need to mark conn */
     return 0;
 
@@ -1332,7 +1330,7 @@
               (int)conn->_base.outbuf_flushlen);
     conn->deliver_window += STREAMWINDOW_INCREMENT;
     if (connection_edge_send_command(conn, circ, RELAY_COMMAND_SENDME,
-                                     NULL, 0, conn->cpath_layer) < 0) {
+                                     NULL, 0) < 0) {
       log_warn(LD_APP,"connection_edge_send_command failed. Returning.");
       return; /* the circuit's closed, don't continue */
     }
@@ -1447,7 +1445,7 @@
       layer_hint->deliver_window += CIRCWINDOW_INCREMENT;
     else
       circ->deliver_window += CIRCWINDOW_INCREMENT;
-    if (connection_edge_send_command(NULL, circ, RELAY_COMMAND_SENDME,
+    if (relay_send_command_from_edge(0, circ, RELAY_COMMAND_SENDME,
                                      NULL, 0, layer_hint) < 0) {
       log_warn(LD_CIRC,
                "connection_edge_send_command failed. Circuit's closed.");

Modified: tor/trunk/src/or/rendclient.c
===================================================================
--- tor/trunk/src/or/rendclient.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/rendclient.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -37,7 +37,7 @@
     circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
     return -1;
   }
-  if (connection_edge_send_command(NULL,TO_CIRCUIT(circ),
+  if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
                                    RELAY_COMMAND_ESTABLISH_RENDEZVOUS,
                                    circ->rend_cookie, REND_COOKIE_LEN,
                                    circ->cpath->prev)<0) {
@@ -144,7 +144,7 @@
   tor_assert(DIGEST_LEN + r <= RELAY_PAYLOAD_SIZE); /* we overran something */
   payload_len = DIGEST_LEN + r;
 
-  if (connection_edge_send_command(NULL, TO_CIRCUIT(introcirc),
+  if (relay_send_command_from_edge(0, TO_CIRCUIT(introcirc),
                                    RELAY_COMMAND_INTRODUCE1,
                                    payload, payload_len,
                                    introcirc->cpath->prev)<0) {

Modified: tor/trunk/src/or/rendmid.c
===================================================================
--- tor/trunk/src/or/rendmid.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/rendmid.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -98,7 +98,7 @@
   /* Acknowledge the request. */
   if (connection_edge_send_command(NULL,TO_CIRCUIT(circ),
                                    RELAY_COMMAND_INTRO_ESTABLISHED,
-                                   "", 0, NULL)<0) {
+                                   "", 0)<0) {
     log_info(LD_GENERAL, "Couldn't send INTRO_ESTABLISHED cell.");
     goto err;
   }
@@ -172,7 +172,7 @@
   /* Great.  Now we just relay the cell down the circuit. */
   if (connection_edge_send_command(NULL, TO_CIRCUIT(intro_circ),
                                    RELAY_COMMAND_INTRODUCE2,
-                                   request, request_len, NULL)) {
+                                   request, request_len)) {
     log_warn(LD_GENERAL,
              "Unable to send INTRODUCE2 cell to Tor client.");
     goto err;
@@ -180,7 +180,7 @@
   /* And sent an ack down Alice's circuit.  Empty body means succeeded. */
   if (connection_edge_send_command(NULL,TO_CIRCUIT(circ),
                                    RELAY_COMMAND_INTRODUCE_ACK,
-                                   NULL,0,NULL)) {
+                                   NULL,0)) {
     log_warn(LD_GENERAL, "Unable to send INTRODUCE_ACK cell to Tor client.");
     circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
     return -1;
@@ -192,7 +192,7 @@
   nak_body[0] = 1;
   if (connection_edge_send_command(NULL,TO_CIRCUIT(circ),
                                    RELAY_COMMAND_INTRODUCE_ACK,
-                                   nak_body, 1, NULL)) {
+                                   nak_body, 1)) {
     log_warn(LD_GENERAL, "Unable to send NAK to Tor client.");
     /* Is this right? */
     circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
@@ -230,7 +230,7 @@
   /* Acknowledge the request. */
   if (connection_edge_send_command(NULL,TO_CIRCUIT(circ),
                                    RELAY_COMMAND_RENDEZVOUS_ESTABLISHED,
-                                   "", 0, NULL)<0) {
+                                   "", 0)<0) {
     log_warn(LD_PROTOCOL, "Couldn't send RENDEZVOUS_ESTABLISHED cell.");
     reason = END_CIRC_REASON_INTERNAL;
     goto err;
@@ -299,7 +299,7 @@
   if (connection_edge_send_command(NULL, TO_CIRCUIT(rend_circ),
                                    RELAY_COMMAND_RENDEZVOUS2,
                                    request+REND_COOKIE_LEN,
-                                   request_len-REND_COOKIE_LEN, NULL)) {
+                                   request_len-REND_COOKIE_LEN)) {
     log_warn(LD_GENERAL,
              "Unable to send RENDEZVOUS2 cell to client on circuit %d.",
              rend_circ->p_circ_id);

Modified: tor/trunk/src/or/rendservice.c
===================================================================
--- tor/trunk/src/or/rendservice.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/rendservice.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -768,7 +768,7 @@
   }
   len += r;
 
-  if (connection_edge_send_command(NULL, TO_CIRCUIT(circuit),
+  if (relay_send_command_from_edge(0, TO_CIRCUIT(circuit),
                                    RELAY_COMMAND_ESTABLISH_INTRO,
                                    buf, len, circuit->cpath->prev)<0) {
     log_info(LD_GENERAL,
@@ -862,7 +862,7 @@
          DIGEST_LEN);
 
   /* Send the cell */
-  if (connection_edge_send_command(NULL, TO_CIRCUIT(circuit),
+  if (relay_send_command_from_edge(0, TO_CIRCUIT(circuit),
                                    RELAY_COMMAND_RENDEZVOUS1,
                                    buf, REND_COOKIE_LEN+DH_KEY_LEN+DIGEST_LEN,
                                    circuit->cpath->prev)<0) {

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2007-03-24 12:21:36 UTC (rev 9898)
+++ tor/trunk/src/or/router.c	2007-03-24 15:57:51 UTC (rev 9899)
@@ -576,7 +576,7 @@
       continue;
     circ->_base.timestamp_dirty = now;
     while (i-- > 0) {
-      if (connection_edge_send_command(NULL, TO_CIRCUIT(circ),
+      if (relay_send_command_from_edge(0, TO_CIRCUIT(circ),
                                        RELAY_COMMAND_DROP,
                                        NULL, 0, circ->cpath->prev)<0) {
         return; /* stop if error */