[tor-commits] [tor/master] Send CIRC2 event when a circuit is cannibalized

nickm at torproject.org nickm at torproject.org
Wed Jan 11 17:10:18 UTC 2012


commit 88e0026d2f0260bb5e3ce88bf2cdead6b521b6b3
Author: Robert Ransom <rransom.8774 at gmail.com>
Date:   Sat Jun 25 13:46:20 2011 -0700

    Send CIRC2 event when a circuit is cannibalized
---
 changes/feature3457 |    3 ++-
 src/or/circuituse.c |    9 +++++++++
 src/or/control.c    |   25 ++++++++++++++++++++++---
 src/or/or.h         |    1 +
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/changes/feature3457 b/changes/feature3457
index 2180f98..eda1d38 100644
--- a/changes/feature3457
+++ b/changes/feature3457
@@ -3,6 +3,7 @@
     - Log (at debug level) whenever a circuit's purpose is changed.
 
     - Allow controllers to request an event notification whenever a
-      circuit's purpose is changed.  Implements part of ticket 3457.
+      circuit is cannibalized or its purpose is changed.  Implements
+      part of ticket 3457.
 
 
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 1b91100..cd288ab 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -1215,14 +1215,23 @@ circuit_launch_by_extend_info(uint8_t purpose,
      * internal circs rather than exit circs? -RD */
     circ = circuit_find_to_cannibalize(purpose, extend_info, flags);
     if (circ) {
+      uint8_t old_purpose = circ->_base.purpose;
+      struct timeval old_timestamp_created;
+
       log_info(LD_CIRC,"Cannibalizing circ '%s' for purpose %d (%s)",
                build_state_get_exit_nickname(circ->build_state), purpose,
                circuit_purpose_to_string(purpose));
+
       circuit_change_purpose(TO_CIRCUIT(circ), purpose);
       /* reset the birth date of this circ, else expire_building
        * will see it and think it's been trying to build since it
        * began. */
       tor_gettimeofday(&circ->_base.timestamp_created);
+
+      control_event_circuit_status_2(circ, CIRC2_EVENT_CANNIBALIZED,
+                                     (int)old_purpose,
+                                     &old_timestamp_created);
+
       switch (purpose) {
         case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
         case CIRCUIT_PURPOSE_S_ESTABLISH_INTRO:
diff --git a/src/or/control.c b/src/or/control.c
index c575ff6..5874fe1 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -3372,13 +3372,11 @@ control_event_circuit_status_2(origin_circuit_t *circ,
                                int arg1, const void *arg2)
 {
   const char *event_desc;
-  char event_tail[96] = "";
+  char event_tail[160] = "";
   if (!EVENT_IS_INTERESTING(EVENT_CIRCUIT_STATUS_2))
     return 0;
   tor_assert(circ);
 
-  (void)arg2; /* currently unused */
-
   switch (e)
     {
     case CIRC2_EVENT_PURPOSE_CHANGED:
@@ -3386,6 +3384,7 @@ control_event_circuit_status_2(origin_circuit_t *circ,
       event_desc = "PURPOSE_CHANGED";
 
       {
+        /* event_tail can currently be up to 68 chars long */
         const char *hs_state_str =
           circuit_purpose_to_controller_hs_state_string(arg1);
         tor_snprintf(event_tail, sizeof(event_tail),
@@ -3396,6 +3395,26 @@ control_event_circuit_status_2(origin_circuit_t *circ,
       }
 
       break;
+    case CIRC2_EVENT_CANNIBALIZED:
+      /* arg1 is the previous purpose of the circuit. */
+      event_desc = "CANNIBALIZED";
+
+      {
+        /* event_tail can currently be up to 130 chars long */
+        const char *hs_state_str =
+          circuit_purpose_to_controller_hs_state_string(arg1);
+        const struct timeval *old_timestamp_created = arg2;
+
+        tor_snprintf(event_tail, sizeof(event_tail),
+                     " OLD_PURPOSE=%s%s%s OLD_TIME_CREATED=%ld,%ld",
+                     circuit_purpose_to_controller_string(arg1),
+                     (hs_state_str != NULL) ? " OLD_HS_STATE=" : "",
+                     (hs_state_str != NULL) ? hs_state_str : "",
+                     old_timestamp_created->tv_sec,
+                     old_timestamp_created->tv_usec);
+      }
+
+      break;
     default:
       log_warn(LD_BUG, "Unrecognized status code %d", (int)e);
       tor_fragile_assert();
diff --git a/src/or/or.h b/src/or/or.h
index 85d812a..0ba52af 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3755,6 +3755,7 @@ typedef enum circuit_status_event_t {
  * The various types are defined in control-spec.txt . */
 typedef enum circuit_status_2_event_t {
   CIRC2_EVENT_PURPOSE_CHANGED           = 0,
+  CIRC2_EVENT_CANNIBALIZED              = 1,
 } circuit_status_2_event_t;
 
 /** Used to indicate the type of a stream event passed to the controller.





More information about the tor-commits mailing list