[or-cvs] kill -USR1 the or and it will dump conn/circuit stats to st...

Roger Dingledine arma at seul.org
Sat Sep 21 22:41:51 UTC 2002


Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or

Modified Files:
	circuit.c connection.c main.c or.h 
Log Message:
kill -USR1 the or and it will dump conn/circuit stats to stdout


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- circuit.c	24 Aug 2002 07:55:49 -0000	1.12
+++ circuit.c	21 Sep 2002 22:41:48 -0000	1.13
@@ -8,6 +8,12 @@
 
 static circuit_t *global_circuitlist=NULL;
 
+char *circuit_state_to_string[] = {
+  "receiving the onion",    /* 0 */
+  "connecting to firsthop", /* 1 */
+  "open"                    /* 2 */
+};
+
 /********* END VARIABLES ************/
 
 void circuit_add(circuit_t *circ) {
@@ -397,5 +403,20 @@
       connection_send_destroy(circ->n_aci, circ->n_conn);
     circuit_free(circ);
   }  
+}
+
+void circuit_dump_by_conn(connection_t *conn) {
+  circuit_t *circ;
+
+  for(circ=global_circuitlist;circ;circ = circ->next) {
+    if(circ->p_conn == conn) {
+      printf("Conn %d has App-ward circuit:  aci %d (other side %d), state %d (%s)\n",
+        conn->poll_index, circ->p_aci, circ->n_aci, circ->state, circuit_state_to_string[circ->state]);
+    }
+    if(circ->n_conn == conn) {
+      printf("Conn %d has Exit-ward circuit: aci %d (other side %d), state %d (%s)\n",
+        conn->poll_index, circ->n_aci, circ->p_aci, circ->state, circuit_state_to_string[circ->state]);
+    }
+  }
 }
 

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- connection.c	17 Sep 2002 08:14:37 -0000	1.21
+++ connection.c	21 Sep 2002 22:41:48 -0000	1.22
@@ -8,38 +8,43 @@
 
 extern or_options_t options; /* command-line and config-file options */
 
-#if 0
-/* these are now out of date :( -RD */
 char *conn_type_to_string[] = {
-  "OP listener", /* 0 */
-  "OP",          /* 1 */
-  "OR listener", /* 2 */
-  "OR",          /* 3 */
-  "App"          /* 4 */
+  "",            /* 0 */
+  "OP listener", /* 1 */
+  "OP",          /* 2 */
+  "OR listener", /* 3 */
+  "OR",          /* 4 */
+  "Exit",        /* 5 */
+  "App listener",/* 6 */
+  "App"          /* 7 */
 };
 
 char *conn_state_to_string[][10] = {
+  { },         /* no type associated with 0 */
   { "ready" }, /* op listener, 0 */
   { "awaiting keys", /* op, 0 */
     "open",              /* 1 */
     "close",             /* 2 */
     "close_wait" },      /* 3 */
   { "ready" }, /* or listener, 0 */
-  { "connecting (as client)",   /* or, 0 */
-    "sending auth (as client)",     /* 1 */
-    "waiting for auth (as client)", /* 2 */
-    "sending nonce (as client)",    /* 3 */
-    "waiting for auth (as server)", /* 4 */
-    "sending auth (as server)",     /* 5 */
-    "waiting for nonce (as server)",/* 6 */
-    "open" },                       /* 7 */
-  { "connecting",                /* exit, 0 */
-    "open",                            /* 1 */
-    "waiting for dest info",           /* 2 */
-    "flushing buffer, then will close",/* 3 */
-    "close_wait" }                     /* 4 */
+  { "connecting (as OP)",       /* or, 0 */
+    "sending keys (as OP)",         /* 1 */
+    "connecting (as client)",       /* 2 */
+    "sending auth (as client)",     /* 3 */
+    "waiting for auth (as client)", /* 4 */
+    "sending nonce (as client)",    /* 5 */
+    "waiting for auth (as server)", /* 6 */
+    "sending auth (as server)",     /* 7 */
+    "waiting for nonce (as server)",/* 8 */
+    "open" },                       /* 9 */
+  { "waiting for dest info",     /* exit, 0 */
+    "connecting",                      /* 1 */
+    "open" },                          /* 2 */
+  { "ready" }, /* app listener, 0 */
+  { "awaiting dest info",         /* app, 0 */
+    "waiting for OR connection",       /* 1 */
+    "open" }                           /* 2 */
 };
-#endif
 
 /********* END VARIABLES ************/
 
@@ -399,6 +404,14 @@
   if(conn->type == CONN_TYPE_OR || conn->type == CONN_TYPE_OP)
     return 1;
 
+  return 0;
+}
+
+int connection_is_listener(connection_t *conn) {
+  if(conn->type == CONN_TYPE_OP_LISTENER ||
+     conn->type == CONN_TYPE_OR_LISTENER ||
+     conn->type == CONN_TYPE_AP_LISTENER)
+    return 1;
   return 0;
 }
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- main.c	4 Sep 2002 06:29:28 -0000	1.21
+++ main.c	21 Sep 2002 22:41:48 -0000	1.22
@@ -18,6 +18,8 @@
 
 static int nfds=0; /* number of connections currently active */
 
+static int please_dumpstats=0; /* whether we should dump stats during the loop */
+
 /* private key */
 static crypto_pk_env_t *prkey;
 
@@ -439,6 +441,9 @@
 		        options.ORPort, options.OPPort, options.APPort);
 
   for(;;) {
+    if(please_dumpstats) {
+      dumpstats();
+    }
     if(prepare_for_poll(&timeout) < 0) {
       log(LOG_DEBUG,"do_main_loop(): prepare_for_poll failed, exiting.");
       return -1;
@@ -483,18 +488,46 @@
   }
 }
 
-void catch () {
+void catchint () {
   errno = 0; /* netcat does this. it looks fun. */
 
-  log(LOG_DEBUG,"Catching ^c, exiting cleanly.");
+  log(LOG_NOTICE,"Catching ^c, exiting cleanly.");
    
   exit(0);
 }
 
+void catchusr1 () {
+  please_dumpstats = 1;
+}
+
+void dumpstats (void) { /* dump stats to stdout */
+  int i;
+  connection_t *conn;
+  extern char *conn_type_to_string[];
+  extern char *conn_state_to_string[][10];
+
+  printf("Dumping stats:\n");
+
+  for(i=0;i<nfds;i++) {
+    conn = connection_array[i];
+    printf("Conn %d (socket %d) type %d (%s), state %d (%s)\n",
+      i, conn->s, conn->type, conn_type_to_string[conn->type],
+      conn->state, conn_state_to_string[conn->type][conn->state]);
+    if(!connection_is_listener(conn)) {
+      printf("Conn %d is to '%s:%d'.\n",i,conn->address, conn->port);
+    }
+    circuit_dump_by_conn(conn); /* dump info about all the circuits using this conn */
+    printf("\n");
+  }
+
+  please_dumpstats = 0;
+}
+
 int main(int argc, char *argv[]) {
   int retval = 0;
 
-  signal (SIGINT, catch); /* to catch ^c so we can exit cleanly */
+  signal (SIGINT, catchint); /* to catch ^c so we can exit cleanly */
+  signal (SIGUSR1, catchusr1); /* to dump stats to stdout */
 
   if ( getoptions(argc,argv,&options) ) exit(1);
   log(options.loglevel,NULL);         /* assign logging severity level from options */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- or.h	19 Sep 2002 20:13:27 -0000	1.22
+++ or.h	21 Sep 2002 22:41:48 -0000	1.23
@@ -386,6 +386,8 @@
 void circuit_about_to_close_connection(connection_t *conn);
   /* flush and send destroys for all circuits using conn */
 
+void circuit_dump_by_conn(connection_t *conn);
+
 /********************************* command.c ***************************/
 
 void command_process_cell(cell_t *cell, connection_t *conn);
@@ -439,6 +441,7 @@
 void connection_init_timeval(connection_t *conn);
 
 int connection_speaks_cells(connection_t *conn);
+int connection_is_listener(connection_t *conn);
 int connection_state_is_open(connection_t *conn);
 
 int connection_send_destroy(aci_t aci, connection_t *conn);
@@ -554,6 +557,10 @@
 int prepare_for_poll(int *timeout);
 
 int do_main_loop(void);
+
+void catchint();
+void catchusr1();
+void dumpstats(void);
 
 int main(int argc, char *argv[]);
 



More information about the tor-commits mailing list