[or-cvs] Improve conn_*_to_string; add circuit_state_to_string; make...

Nick Mathewson nickm at seul.org
Thu Apr 7 21:07:22 UTC 2005


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

Modified Files:
	circuitbuild.c circuitlist.c circuituse.c connection.c 
	dirserv.c or.h rendservice.c 
Log Message:
Improve conn_*_to_string; add circuit_state_to_string; make skewed-descriptor messages better. 

Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -d -r1.106 -r1.107
--- circuitbuild.c	6 Apr 2005 05:45:07 -0000	1.106
+++ circuitbuild.c	7 Apr 2005 21:07:18 -0000	1.107
@@ -185,7 +185,7 @@
                      const char *type, int this_circid, int other_circid) {
   log(severity,"Conn %d has %s circuit: circID %d (other side %d), state %d (%s), born %d:",
       poll_index, type, this_circid, other_circid, circ->state,
-      circuit_state_to_string[circ->state], (int)circ->timestamp_created);
+      circuit_state_to_string(circ->state), (int)circ->timestamp_created);
   if (CIRCUIT_IS_ORIGIN(circ)) { /* circ starts at this node */
     circuit_log_path(severity, circ);
   }

Index: circuitlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitlist.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- circuitlist.c	7 Apr 2005 05:09:19 -0000	1.42
+++ circuitlist.c	7 Apr 2005 21:07:19 -0000	1.43
@@ -15,14 +15,6 @@
 
 /********* START VARIABLES **********/
 
-/** Array of strings to make circ-\>state human-readable */
-const char *circuit_state_to_string[] = {
-  "doing handshakes",        /* 0 */
-  "processing the onion",    /* 1 */
-  "connecting to firsthop",  /* 2 */
-  "open"                     /* 3 */
-};
-
 /** A global list of all circuits at this hop. */
 circuit_t *global_circuitlist=NULL;
 
@@ -156,6 +148,22 @@
   }
 }
 
+/** Function to make circ-\>state human-readable */
+const char *
+circuit_state_to_string(int state) {
+  static buf[64];
+  switch (state) {
+    case CIRCUIT_STATE_BUILDING: return "doing handshakes";
+    case CIRCUIT_STATE_ONIONSKIN_PENDING: return "processing the onion";
+    case CIRCUIT_STATE_OR_WAIT: return "connecting to firsthop";
+    case CIRCUIT_STATE_OPEN: return "open";
+    default:
+      log_fn(LOG_WARN, "Bug: unknown circuit state %d", state);
+      tor_snprintf(buf, sizeof(buf), "unknown state [%d], state");
+      return buf;
+  }
+}
+
 /** Allocate space for a new circuit, initializing with <b>p_circ_id</b>
  * and <b>p_conn</b>. Add it to the global circuit list.
  */

Index: circuituse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuituse.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- circuituse.c	6 Apr 2005 06:43:21 -0000	1.68
+++ circuituse.c	7 Apr 2005 21:07:19 -0000	1.69
@@ -240,10 +240,10 @@
       if (victim->n_conn)
         log_fn(LOG_INFO,"Abandoning circ %s:%d:%d (state %d:%s, purpose %d)",
                victim->n_conn->address, victim->n_port, victim->n_circ_id,
-               victim->state, circuit_state_to_string[victim->state], victim->purpose);
+               victim->state, circuit_state_to_string(victim->state), victim->purpose);
       else
         log_fn(LOG_INFO,"Abandoning circ %d (state %d:%s, purpose %d)", victim->n_circ_id,
-               victim->state, circuit_state_to_string[victim->state], victim->purpose);
+               victim->state, circuit_state_to_string(victim->state), victim->purpose);
       circuit_log_path(LOG_INFO,victim);
       circuit_mark_for_close(victim);
     }

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.359
retrieving revision 1.360
diff -u -d -r1.359 -r1.360
--- connection.c	7 Apr 2005 20:25:22 -0000	1.359
+++ connection.c	7 Apr 2005 21:07:19 -0000	1.360
@@ -44,6 +44,7 @@
     case CONN_TYPE_CONTROL_LISTENER: return "Control listener";
     case CONN_TYPE_CONTROL: return "Control";
     default:
+      log_fn(LOG_WARN, "Bug: unknown connection type %d", type);
       tor_snprintf(buf, sizeof(buf), "unknown [%d]", type);
       return buf;
   }
@@ -117,6 +118,7 @@
       break;
   }
 
+  log_fn(LOG_WARN, "Bug: unknown connection state %d (type %d)", state, type);
   tor_snprintf(buf, sizeof(buf),
                "unknown state [%d] on unknown [%s] connection",
                state, conn_type_to_string(type));

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- dirserv.c	7 Apr 2005 21:00:59 -0000	1.156
+++ dirserv.c	7 Apr 2005 21:07:19 -0000	1.157
@@ -357,14 +357,16 @@
   /* Is there too much clock skew? */
   now = time(NULL);
   if (ri->published_on > now+ROUTER_ALLOW_SKEW) {
-    log_fn(LOG_NOTICE, "Publication time for nickname '%s' is too far in the future; possible clock skew. Not adding.", ri->nickname);
+    log_fn(LOG_NOTICE, "Publication time for nickname '%s' is too far (%d minutes) in the future; possible clock skew. Not adding.",
+           ri->nickname, (int)((ri->published_on-now)/60));
     *msg = "Rejected: Your clock is set too far in the future, or your timezone is not correct.";
     routerinfo_free(ri);
     *desc = end;
     return -1;
   }
   if (ri->published_on < now-ROUTER_MAX_AGE) {
-    log_fn(LOG_NOTICE, "Publication time for router with nickname '%s' is too far in the past. Not adding.", ri->nickname);
+    log_fn(LOG_NOTICE, "Publication time for router with nickname '%s' is too far (%d minutes) in the past. Not adding.",
+           ri->nickname, (int)((now-ri->published_on)/60));
     *msg = "Rejected: Server is expired, or your clock is too far in the past, or your timezone is not correct.";
     routerinfo_free(ri);
     *desc = end;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.590
retrieving revision 1.591
diff -u -d -r1.590 -r1.591
--- or.h	7 Apr 2005 20:25:22 -0000	1.590
+++ or.h	7 Apr 2005 21:07:19 -0000	1.591
@@ -1165,7 +1165,7 @@
 
 /********************************* circuitlist.c ***********************/
 
-extern const char *circuit_state_to_string[];
+const char *circuit_state_to_string(int state);
 enum which_conn_changed_t { P_CONN_CHANGED=1, N_CONN_CHANGED=0 };
 void circuit_set_circid_orconn(circuit_t *circ, uint16_t id,
                                connection_t *conn,

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendservice.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- rendservice.c	1 Apr 2005 20:15:55 -0000	1.121
+++ rendservice.c	7 Apr 2005 21:07:19 -0000	1.122
@@ -988,7 +988,7 @@
         continue;
       }
       log(severity, "  Intro point at %s: circuit is %s",nickname,
-          circuit_state_to_string[circ->state]);
+          circuit_state_to_string(circ->state));
     }
   }
 }



More information about the tor-commits mailing list