Browse Source

Debug EXTENDCIRCUIT

svn:r3849
Nick Mathewson 20 years ago
parent
commit
0cfdeb01c8
2 changed files with 16 additions and 3 deletions
  1. 7 0
      contrib/tor-control.py
  2. 9 3
      src/or/control.c

+ 7 - 0
contrib/tor-control.py

@@ -201,6 +201,12 @@ def map_address(s, kv):
   tp, body = receive_reply(s,[MSG_TYPE_DONE])
   tp, body = receive_reply(s,[MSG_TYPE_DONE])
   return _parseKV(body)
   return _parseKV(body)
 
 
+def extend_circuit(s, circid, hops):
+  msg = struct.pack("!L",circid) + ",".join(hops) + "\0"
+  send_message(s,MSG_TYPE_EXTENDCIRCUIT,msg)
+  tp, body = receive_reply(s,[MSG_TYPE_DONE])
+  return body
+
 def listen_for_events(s):
 def listen_for_events(s):
   while(1):
   while(1):
     _,type,body = receive_message(s)
     _,type,body = receive_message(s)
@@ -225,6 +231,7 @@ def do_main_loop(host,port):
                          ("1.2.3.4", "foobaz.com"),
                          ("1.2.3.4", "foobaz.com"),
                          ("frebnitz.com", "5.6.7.8"),
                          ("frebnitz.com", "5.6.7.8"),
                          (".", "abacinator.onion")])`
                          (".", "abacinator.onion")])`
+  print `extend_circuit(s,0,["moria1"])`
   send_signal(s,1)
   send_signal(s,1)
   #save_conf(s)
   #save_conf(s)
 
 

+ 9 - 3
src/or/control.c

@@ -636,6 +636,7 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
   smartlist_t *router_nicknames, *routers;
   smartlist_t *router_nicknames, *routers;
   uint32_t circ_id;
   uint32_t circ_id;
   circuit_t *circ;
   circuit_t *circ;
+  char reply[4];
   if (len<5) {
   if (len<5) {
     send_control_error(conn, ERR_SYNTAX, "extendcircuit message too short");
     send_control_error(conn, ERR_SYNTAX, "extendcircuit message too short");
     return 0;
     return 0;
@@ -643,12 +644,12 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
 
 
   router_nicknames = smartlist_create();
   router_nicknames = smartlist_create();
   routers = smartlist_create();
   routers = smartlist_create();
-  smartlist_split_string(router_nicknames, body, ",", 0, 0);
+  smartlist_split_string(router_nicknames, body+4, ",", 0, 0);
   SMARTLIST_FOREACH(router_nicknames, const char *, n,
   SMARTLIST_FOREACH(router_nicknames, const char *, n,
     {
     {
       routerinfo_t *r = router_get_by_nickname(n);
       routerinfo_t *r = router_get_by_nickname(n);
       if (!r) {
       if (!r) {
-        send_control_error(conn, ERR_NO_ROUTER, "Unrecognized router name");
+        send_control_error(conn, ERR_NO_ROUTER, n);
         goto done;
         goto done;
       }
       }
       smartlist_add(routers, r);
       smartlist_add(routers, r);
@@ -682,6 +683,8 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
   if (!circ_id) {
   if (!circ_id) {
     if (circuit_handle_first_hop(circ) < 0) {
     if (circuit_handle_first_hop(circ) < 0) {
       circuit_mark_for_close(circ);
       circuit_mark_for_close(circ);
+      send_control_error(conn, ERR_INTERNAL, "couldn't start circuit");
+      goto done;
     }
     }
   } else {
   } else {
     if (circ->state == CIRCUIT_STATE_OPEN) {
     if (circ->state == CIRCUIT_STATE_OPEN) {
@@ -689,11 +692,14 @@ handle_control_extendcircuit(connection_t *conn, uint32_t len,
       if (circuit_send_next_onion_skin(circ) < 0) {
       if (circuit_send_next_onion_skin(circ) < 0) {
         log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
         log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
         circuit_mark_for_close(circ);
         circuit_mark_for_close(circ);
+        send_control_error(conn, ERR_INTERNAL, "couldn't send onion skin");
+        goto done;
       }
       }
     }
     }
   }
   }
 
 
-  send_control_done(conn);
+  set_uint32(reply, htonl(circ->global_identifier));
+  send_control_done2(conn, reply, sizeof(reply));
  done:
  done:
   SMARTLIST_FOREACH(router_nicknames, char *, n, tor_free(n));
   SMARTLIST_FOREACH(router_nicknames, char *, n, tor_free(n));
   smartlist_free(router_nicknames);
   smartlist_free(router_nicknames);