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

[or-cvs] r17007: {tor} Include circuit purposes in circuit events. Now all circuit (in tor/trunk: . src/or)



Author: nickm
Date: 2008-09-29 18:34:22 -0400 (Mon, 29 Sep 2008)
New Revision: 17007

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/or/circuitlist.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/or.h
Log:
Include circuit purposes in circuit events.  Now all circuit events are extended; this makes the code simpler.

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-09-29 20:44:29 UTC (rev 17006)
+++ tor/trunk/ChangeLog	2008-09-29 22:34:22 UTC (rev 17007)
@@ -64,6 +64,7 @@
       people find host:port too confusing.
     - Make TrackHostExit mappings expire a while after their last use, not
       after their creation.  Patch from Robert Hogan.
+    - Provide circuit purposes along with circuit events to the controller.
 
   o Minor bugfixes:
     - Fix compile on OpenBSD 4.4-current. Bugfix on 0.2.1.5-alpha.

Modified: tor/trunk/src/or/circuitlist.c
===================================================================
--- tor/trunk/src/or/circuitlist.c	2008-09-29 20:44:29 UTC (rev 17006)
+++ tor/trunk/src/or/circuitlist.c	2008-09-29 22:34:22 UTC (rev 17007)
@@ -319,6 +319,50 @@
   }
 }
 
+/** Map a circuit purpose to a string suitable to be displayed to a
+ * controller. */
+const char *
+circuit_purpose_to_controller_string(uint8_t purpose)
+{
+  static char buf[32];
+  switch (purpose) {
+    case CIRCUIT_PURPOSE_OR:
+    case CIRCUIT_PURPOSE_INTRO_POINT:
+    case CIRCUIT_PURPOSE_REND_POINT_WAITING:
+    case CIRCUIT_PURPOSE_REND_ESTABLISHED:
+      return "SERVER"; /* A controller should never see these, actually. */
+
+    case CIRCUIT_PURPOSE_C_GENERAL:
+      return "GENERAL";
+    case CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT:
+    case CIRCUIT_PURPOSE_C_INTRODUCE_ACKED:
+      return "HS_CLIENT_INTRO";
+
+    case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
+    case CIRCUIT_PURPOSE_C_REND_READY:
+    case CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED:
+    case CIRCUIT_PURPOSE_C_REND_JOINED:
+      return "HS_CLIENT_REND";
+
+    case CIRCUIT_PURPOSE_S_ESTABLISH_INTRO:
+    case CIRCUIT_PURPOSE_S_INTRO:
+      return "HS_SERVICE_INTRO";
+
+    case CIRCUIT_PURPOSE_S_CONNECT_REND:
+    case CIRCUIT_PURPOSE_S_REND_JOINED:
+      return "HS_SERVICE_REND";
+
+    case CIRCUIT_PURPOSE_TESTING:
+      return "TESTING";
+    case CIRCUIT_PURPOSE_CONTROLLER:
+      return "CONTROLLER";
+
+    default:
+      tor_snprintf(buf, sizeof(buf), "UNKNOWN_%d", (int)purpose);
+      return buf;
+  }
+}
+
 /** Initialize the common elements in a circuit_t, and add it to the global
  * list. */
 static void

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2008-09-29 20:44:29 UTC (rev 17006)
+++ tor/trunk/src/or/control.c	2008-09-29 22:34:22 UTC (rev 17007)
@@ -2964,7 +2964,7 @@
                              int reason_code)
 {
   const char *status;
-  char reason_buf[64];
+  char extended_buf[96];
   int providing_reason=0;
   char *path=NULL;
   if (!EVENT_IS_INTERESTING(EVENT_CIRCUIT_STATUS))
@@ -2986,9 +2986,13 @@
       return 0;
     }
 
+  tor_snprintf(extended_buf, sizeof(extended_buf), "PURPOSE=%s",
+               circuit_purpose_to_controller_string(circ->_base.purpose));
+
   if (tp == CIRC_EVENT_FAILED || tp == CIRC_EVENT_CLOSED) {
     const char *reason_str = circuit_end_reason_to_control_string(reason_code);
     char *reason = NULL;
+    size_t n=strlen(extended_buf);
     providing_reason=1;
     if (!reason_str) {
       reason = tor_malloc(16);
@@ -2996,41 +3000,29 @@
       reason_str = reason;
     }
     if (reason_code > 0 && reason_code & END_CIRC_REASON_FLAG_REMOTE) {
-      tor_snprintf(reason_buf, sizeof(reason_buf),
-                   "REASON=DESTROYED REMOTE_REASON=%s", reason_str);
+      tor_snprintf(extended_buf+n, sizeof(extended_buf)-n,
+                   " REASON=DESTROYED REMOTE_REASON=%s", reason_str);
     } else {
-      tor_snprintf(reason_buf, sizeof(reason_buf),
-                   "REASON=%s", reason_str);
+      tor_snprintf(extended_buf+n, sizeof(extended_buf)-n,
+                   " REASON=%s", reason_str);
     }
     tor_free(reason);
   }
 
   if (EVENT_IS_INTERESTING1S(EVENT_CIRCUIT_STATUS)) {
     const char *sp = strlen(path) ? " " : "";
-    if (providing_reason)
-      send_control_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
-                            "650 CIRC %lu %s%s%s@%s\r\n",
-                            (unsigned long)circ->global_identifier,
-                            status, sp, path, reason_buf);
-    else
-      send_control_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
-                            "650 CIRC %lu %s%s%s\r\n",
-                            (unsigned long)circ->global_identifier,
-                            status, sp, path);
+    send_control_event_extended(EVENT_CIRCUIT_STATUS, SHORT_NAMES,
+                                "650 CIRC %lu %s%s%s@%s\r\n",
+                                (unsigned long)circ->global_identifier,
+                                status, sp, path, extended_buf);
   }
   if (EVENT_IS_INTERESTING1L(EVENT_CIRCUIT_STATUS)) {
     char *vpath = circuit_list_path_for_controller(circ);
     const char *sp = strlen(vpath) ? " " : "";
-    if (providing_reason)
-      send_control_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
-                            "650 CIRC %lu %s%s%s@%s\r\n",
-                            (unsigned long)circ->global_identifier,
-                            status, sp, vpath, reason_buf);
-    else
-      send_control_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
-                            "650 CIRC %lu %s%s%s\r\n",
-                            (unsigned long)circ->global_identifier,
-                            status, sp, vpath);
+    send_control_event_extended(EVENT_CIRCUIT_STATUS, LONG_NAMES,
+                                "650 CIRC %lu %s%s%s@%s\r\n",
+                                (unsigned long)circ->global_identifier,
+                                status, sp, vpath, extended_buf);
     tor_free(vpath);
   }
 

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-09-29 20:44:29 UTC (rev 17006)
+++ tor/trunk/src/or/or.h	2008-09-29 22:34:22 UTC (rev 17007)
@@ -2703,6 +2703,7 @@
 
 circuit_t * _circuit_get_global_list(void);
 const char *circuit_state_to_string(int state);
+const char *circuit_purpose_to_controller_string(uint8_t purpose);
 void circuit_dump_by_conn(connection_t *conn, int severity);
 void circuit_set_p_circid_orconn(or_circuit_t *circ, circid_t id,
                                  or_connection_t *conn);