[or-cvs] move closer to being able to reload config on HUP

Roger Dingledine arma at seul.org
Tue Oct 21 09:48:20 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	circuit.c config.c connection.c connection_or.c dirserv.c 
	main.c onion.c or.h routers.c test.c 
Log Message:
move closer to being able to reload config on HUP
rename APPort to SocksPort
introduce new tor_free() macro


Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- circuit.c	21 Oct 2003 08:37:07 -0000	1.80
+++ circuit.c	21 Oct 2003 09:48:17 -0000	1.81
@@ -481,7 +481,7 @@
   circuit_t *youngest=NULL;
 
   assert(circ);
-  if(options.APPort) {
+  if(options.SocksPort) {
     youngest = circuit_get_newest_open();
     log_fn(LOG_DEBUG,"youngest %d, circ %d.",(int)youngest, (int)circ);
   }
@@ -496,7 +496,7 @@
   for(conn=circ->p_streams; conn; conn=conn->next_stream) {
     connection_send_destroy(circ->p_aci, conn); 
   }
-  if(options.APPort && youngest == circ) { /* check this after we've sent the destroys, to reduce races */
+  if(options.SocksPort && youngest == circ) { /* check this after we've sent the destroys, to reduce races */
     /* our current circuit just died. Launch another one pronto. */
     log_fn(LOG_INFO,"Youngest circuit dying. Launching a replacement.");
     circuit_launch_new(1);
@@ -616,7 +616,7 @@
 void circuit_launch_new(int failure_status) {
   static int failures=0;
 
-  if(!options.APPort) /* we're not an application proxy. no need for circuits. */
+  if(!options.SocksPort) /* we're not an application proxy. no need for circuits. */
     return;
 
   if(failure_status == -1) { /* I was called because a circuit succeeded */

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- config.c	20 Oct 2003 01:19:54 -0000	1.60
+++ config.c	21 Oct 2003 09:48:17 -0000	1.61
@@ -131,6 +131,7 @@
       *(int *)arg = i;
       break;
     case CONFIG_TYPE_STRING:
+      tor_free(*(char **)arg);
       *(char **)arg = tor_strdup(c->value);
       break;
     case CONFIG_TYPE_DOUBLE:
@@ -159,10 +160,12 @@
     config_compare(list, "Nickname",       CONFIG_TYPE_STRING, &options->Nickname) ||
     config_compare(list, "Address",        CONFIG_TYPE_STRING, &options->Address) ||
     config_compare(list, "ExitPolicy",     CONFIG_TYPE_STRING, &options->ExitPolicy) ||
+    config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
+    config_compare(list, "ORBindAddress",  CONFIG_TYPE_STRING, &options->ORBindAddress) ||
 
     /* int options */
     config_compare(list, "MaxConn",         CONFIG_TYPE_INT, &options->MaxConn) ||
-    config_compare(list, "APPort",          CONFIG_TYPE_INT, &options->APPort) ||
+    config_compare(list, "SocksPort",       CONFIG_TYPE_INT, &options->SocksPort) ||
     config_compare(list, "ORPort",          CONFIG_TYPE_INT, &options->ORPort) ||
     config_compare(list, "DirPort",         CONFIG_TYPE_INT, &options->DirPort) ||
     config_compare(list, "DirFetchPostPeriod",CONFIG_TYPE_INT, &options->DirFetchPostPeriod) ||
@@ -195,20 +198,27 @@
 
 }
 
-/* return 0 if success, <0 if failure. */
-int getconfig(int argc, char **argv, or_options_t *options) {
-  struct config_line *cl;
-  FILE *cf;
-  char *fname;
-  int i;
-  int result = 0;
+void free_options(or_options_t *options) {
+  tor_free(options->LogLevel);
+  tor_free(options->LogFile);
+  tor_free(options->DebugLogFile);
+  tor_free(options->DataDirectory);
+  tor_free(options->RouterFile);
+  tor_free(options->Nickname);
+  tor_free(options->Address);
+  tor_free(options->PidFile);
+  tor_free(options->ExitPolicy);
+}
 
+void init_options(or_options_t *options) {
 /* give reasonable values for each option. Defaults to zero. */
   memset(options,0,sizeof(or_options_t));
-  options->LogLevel = "info";
-  options->ExitPolicy = "reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*";
+  options->LogLevel = tor_strdup("info");
+  options->ExitPolicy = tor_strdup("reject 127.0.0.1:*,reject 18.244.0.188:25,accept *:*");
+  options->SocksBindAddress = tor_strdup("127.0.0.1");
+  options->ORBindAddress = tor_strdup("0.0.0.0");
   options->loglevel = LOG_INFO;
-  options->PidFile = "tor.pid";
+  options->PidFile = tor_strdup("tor.pid");
   options->DataDirectory = NULL;
   options->CoinWeight = 0.1;
   options->MaxConn = 900;
@@ -218,6 +228,17 @@
   options->NewCircuitPeriod = 60; /* once a minute */
   options->TotalBandwidth = 800000; /* at most 800kB/s total sustained incoming */
   options->NumCpus = 1;
+}
+
+/* return 0 if success, <0 if failure. */
+int getconfig(int argc, char **argv, or_options_t *options) {
+  struct config_line *cl;
+  FILE *cf;
+  char *fname;
+  int i;
+  int result = 0;
+
+  init_options(options); 
 
   if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
     print_usage();
@@ -295,8 +316,8 @@
     result = -1;
   }
 
-  if(options->APPort < 0) {
-    log(LOG_WARN,"APPort option can't be negative.");
+  if(options->SocksPort < 0) {
+    log(LOG_WARN,"SocksPort option can't be negative.");
     result = -1;
   }
 
@@ -305,7 +326,7 @@
     result = -1;
   }
 
-  if(options->APPort > 1 &&
+  if(options->SocksPort > 1 &&
      (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0)) {
     log(LOG_WARN,"CoinWeight option must be >=0.0 and <1.0.");
     result = -1;

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- connection.c	21 Oct 2003 08:37:07 -0000	1.123
+++ connection.c	21 Oct 2003 09:48:17 -0000	1.124
@@ -100,8 +100,7 @@
     buf_free(conn->inbuf);
     buf_free(conn->outbuf);
   }
-  if(conn->address)
-    free(conn->address);
+  tor_free(conn->address);
 
   if(connection_speaks_cells(conn)) {
     directory_set_dirty();
@@ -115,8 +114,7 @@
     crypto_free_pk_env(conn->link_pkey);
   if (conn->identity_pkey)
     crypto_free_pk_env(conn->identity_pkey);
-  if (conn->nickname) 
-    free(conn->nickname);
+  tor_free(conn->nickname);
 
   if(conn->s >= 0) {
     log_fn(LOG_INFO,"closing fd %d.",conn->s);

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- connection_or.c	19 Oct 2003 00:47:03 -0000	1.70
+++ connection_or.c	21 Oct 2003 09:48:17 -0000	1.71
@@ -85,8 +85,7 @@
   conn->link_pkey = crypto_pk_dup_key(router->link_pkey);
   conn->identity_pkey = crypto_pk_dup_key(router->identity_pkey);
   conn->nickname = tor_strdup(router->nickname);
-  if(conn->address)
-    free(conn->address);
+  tor_free(conn->address);
   conn->address = tor_strdup(router->address);
 }
 

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dirserv.c	18 Oct 2003 03:23:26 -0000	1.12
+++ dirserv.c	21 Oct 2003 09:48:17 -0000	1.13
@@ -165,10 +165,8 @@
 
 static void free_descriptor_entry(descriptor_entry_t *desc)
 {
-  if (desc->descriptor)
-    free(desc->descriptor);
-  if (desc->nickname)
-    free(desc->nickname);
+  tor_free(desc->descriptor);
+  tor_free(desc->nickname);
   free(desc);
 }
 
@@ -218,7 +216,7 @@
     log(LOG_WARN, "Couldn't parse descriptor");
     goto err;
   }
-  free(desc_tmp); desc_tmp = NULL;
+  tor_free(desc_tmp);
   /* Okay.  Now check whether the fingerprint is recognized. */
   if (!dirserv_router_fingerprint_is_known(ri)) {
     log(LOG_WARN, "Identity is unrecognized for descriptor");
@@ -238,7 +236,7 @@
       /* We already have a newer descriptor */
       log_fn(LOG_INFO,"We already have a newer desc for nickname %s. Not adding.",ri->nickname);
       /* This isn't really an error; return. */
-      if (desc_tmp) free(desc_tmp);
+      tor_free(desc_tmp);
       if (ri) routerinfo_free(ri);
       *desc = end;
       return 0;
@@ -263,8 +261,7 @@
   routerinfo_free(ri);
   return 0;
  err:
-  if (desc_tmp)
-    free(desc_tmp);
+  tor_free(desc_tmp);
   if (ri)
     routerinfo_free(ri);
   
@@ -417,8 +414,7 @@
       free(new_directory);
       return 0;
     }
-    if (the_directory)
-      free(the_directory);
+    tor_free(the_directory);
     the_directory = new_directory;
     the_directory_len = strlen(the_directory);
     log_fn(LOG_INFO,"New directory (size %d):\n%s",the_directory_len,

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- main.c	20 Oct 2003 01:19:54 -0000	1.138
+++ main.c	21 Oct 2003 09:48:17 -0000	1.139
@@ -337,7 +337,7 @@
   /* 2. Every NewCircuitPeriod seconds, we expire old circuits and make a 
    *    new one as needed.
    */
-  if(options.APPort && time_to_new_circuit < now) {
+  if(options.SocksPort && time_to_new_circuit < now) {
     circuit_expire_unused_circuits();
     circuit_launch_new(-1); /* tell it to forget about previous failures */
     circ = circuit_get_newest_open();
@@ -595,7 +595,7 @@
    * and start the listeners.
    */
   retry_all_connections((uint16_t) options.ORPort,
-                        (uint16_t) options.APPort,
+                        (uint16_t) options.SocksPort,
                         (uint16_t) options.DirPort);
 
   for(;;) {

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- onion.c	10 Oct 2003 01:48:32 -0000	1.74
+++ onion.c	21 Oct 2003 09:48:17 -0000	1.75
@@ -222,7 +222,7 @@
   for(i=0;i<*routelen;i++) {
 //    log_fn(LOG_DEBUG,"Choosing hop %u.",i);
     if (CRYPTO_PSEUDO_RAND_INT(choice)) {
-      free((void *)route);
+      free(route);
       return NULL;
     }
 
@@ -432,7 +432,7 @@
 
   return 0;
  err:
-  if (pubkey) free(pubkey);
+  tor_free(pubkey);
   if (dh) crypto_dh_free(dh);
   if (cipher) crypto_free_cipher_env(cipher);
   return -1;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- or.h	21 Oct 2003 08:37:07 -0000	1.169
+++ or.h	21 Oct 2003 09:48:17 -0000	1.170
@@ -335,7 +335,7 @@
  
   uint32_t addr; /* all host order */
   uint16_t or_port;
-  uint16_t ap_port;
+  uint16_t socks_port;
   uint16_t dir_port;
 
   time_t published_on;
@@ -426,9 +426,11 @@
    char *Address;
    char *PidFile;
    char *ExitPolicy;
+   char *SocksBindAddress;
+   char *ORBindAddress;
    double CoinWeight;
    int ORPort;
-   int APPort;
+   int SocksPort;
    int DirPort;
    int MaxConn;
    int OnionRouter;

Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- routers.c	20 Oct 2003 20:19:59 -0000	1.84
+++ routers.c	21 Oct 2003 09:48:17 -0000	1.85
@@ -144,10 +144,8 @@
   if (!router)
     return;
 
-  if (router->address)
-    free(router->address);
-  if (router->nickname)
-    free(router->nickname);
+  tor_free(router->address);
+  tor_free(router->nickname);
   if (router->onion_pkey)
     crypto_free_pk_env(router->onion_pkey);
   if (router->link_pkey)
@@ -157,9 +155,9 @@
   while (router->exit_policy) {
     e = router->exit_policy;
     router->exit_policy = e->next;
-    if (e->string) free(e->string);
-    if (e->address) free(e->address);
-    if (e->port) free(e->port);
+    tor_free(e->string);
+    tor_free(e->address);
+    tor_free(e->port);
     free(e);
   }
   free(router);
@@ -170,10 +168,8 @@
   int i;
   for (i = 0; i < dir->n_routers; ++i)
     routerinfo_free(dir->routers[i]);
-  if (dir->routers)
-    free(dir->routers);
-  if(dir->software_versions)
-    free(dir->software_versions);
+  tor_free(dir->routers);
+  tor_free(dir->software_versions);
   free(dir);
 }
 
@@ -825,8 +821,8 @@
     goto err;
   }
   
-  /* Router->ap_port */
-  router->ap_port = atoi(ARGS[3]);
+  /* Router->socks_port */
+  router->socks_port = atoi(ARGS[3]);
   
   /* Router->dir_port */
   router->dir_port = atoi(ARGS[4]);
@@ -838,8 +834,8 @@
     goto err;
   }
   
-  log_fn(LOG_DEBUG,"or_port %d, ap_port %d, dir_port %d, bandwidth %d.",
-    router->or_port, router->ap_port, router->dir_port, router->bandwidth);
+  log_fn(LOG_DEBUG,"or_port %d, socks_port %d, dir_port %d, bandwidth %d.",
+    router->or_port, router->socks_port, router->dir_port, router->bandwidth);
 
   /* XXX Later, require platform before published. */
   NEXT_TOKEN();
@@ -1039,12 +1035,9 @@
 policy_read_failed:
   assert(newe->string);
   log_fn(LOG_WARN,"Couldn't parse line '%s'. Dropping", newe->string);
-  if(newe->string)
-    free(newe->string);
-  if(newe->address)
-    free(newe->address);
-  if(newe->port)
-    free(newe->port);
+  tor_free(newe->string);
+  tor_free(newe->address);
+  tor_free(newe->port);
   free(newe);
   return -1;
 }
@@ -1121,7 +1114,7 @@
   ri->nickname = tor_strdup(options.Nickname);
   /* No need to set addr. */
   ri->or_port = options.ORPort;
-  ri->ap_port = options.APPort;
+  ri->socks_port = options.SocksPort;
   ri->dir_port = options.DirPort;
   ri->published_on = time(NULL);
   ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
@@ -1202,7 +1195,7 @@
     router->nickname,             
     router->address,
     router->or_port,
-    router->ap_port,
+    router->socks_port,
     router->dir_port,
     router->bandwidth,
     platform,

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- test.c	21 Oct 2003 08:37:07 -0000	1.44
+++ test.c	21 Oct 2003 09:48:17 -0000	1.45
@@ -517,7 +517,7 @@
   r1.addr = 0xc0a80001u; /* 192.168.0.1 */
   r1.published_on = 0;
   r1.or_port = 9000;
-  r1.ap_port = 9002;
+  r1.socks_port = 9002;
   r1.dir_port = 9003;
   r1.onion_pkey = pk1;
   r1.identity_pkey = pk2;
@@ -539,7 +539,7 @@
   r2.addr = 0x0a030201u; /* 10.3.2.1 */
   r2.published_on = 5;
   r2.or_port = 9005;
-  r2.ap_port = 0;
+  r2.socks_port = 0;
   r2.dir_port = 0;
   r2.onion_pkey = pk2;
   r2.identity_pkey = pk1;
@@ -580,7 +580,7 @@
   test_assert(rp1);
   test_streq(rp1->address, r1.address);
   test_eq(rp1->or_port, r1.or_port);
-  test_eq(rp1->ap_port, r1.ap_port);
+  test_eq(rp1->socks_port, r1.socks_port);
   test_eq(rp1->dir_port, r1.dir_port);
   test_eq(rp1->bandwidth, r1.bandwidth);
   test_assert(crypto_pk_cmp_keys(rp1->onion_pkey, pk1) == 0);
@@ -603,7 +603,7 @@
   test_assert(rp2);
   test_streq(rp2->address, r2.address);
   test_eq(rp2->or_port, r2.or_port);
-  test_eq(rp2->ap_port, r2.ap_port);
+  test_eq(rp2->socks_port, r2.socks_port);
   test_eq(rp2->dir_port, r2.dir_port);
   test_eq(rp2->bandwidth, r2.bandwidth);
   test_assert(crypto_pk_cmp_keys(rp2->onion_pkey, pk2) == 0);
@@ -636,14 +636,14 @@
   test_eq(2, dir2->n_routers);
 #endif
  
-  if (pk1_str) free(pk1_str);
-  if (pk2_str) free(pk2_str);
+  tor_free(pk1_str);
+  tor_free(pk2_str);
   if (pk1) crypto_free_pk_env(pk1);
   if (pk2) crypto_free_pk_env(pk2);
   if (rp1) routerinfo_free(rp1);
   if (rp2) routerinfo_free(rp2);
-  if (dir1) free(dir1); /* And more !*/
-  if (dir1) free(dir2); /* And more !*/
+  tor_free(dir1); /* And more !*/
+  tor_free(dir2); /* And more !*/
 
   /* make sure compare_recommended_versions() works */
   test_eq(0, compare_recommended_versions("abc", "abc"));



More information about the tor-commits mailing list