[or-cvs] r12617: Do not keep a string representation of every single addr_pol (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Fri Nov 30 20:09:10 UTC 2007


Author: nickm
Date: 2007-11-30 15:09:09 -0500 (Fri, 30 Nov 2007)
New Revision: 12617

Modified:
   tor/trunk/
   tor/trunk/src/or/or.h
   tor/trunk/src/or/policies.c
   tor/trunk/src/or/routerparse.c
   tor/trunk/src/or/test.c
Log:
 r16881 at catbus:  nickm | 2007-11-30 15:07:42 -0500
 Do not keep a string representation of every single addr_policy_t lying around.  This might save a few hundred K.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16881] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-11-30 19:07:11 UTC (rev 12616)
+++ tor/trunk/src/or/or.h	2007-11-30 20:09:09 UTC (rev 12617)
@@ -1119,7 +1119,6 @@
 /** A linked list of policy rules */
 typedef struct addr_policy_t {
   addr_policy_action_t policy_type; /**< What to do when the policy matches.*/
-  char *string; /**< String representation of this rule. */
 
   /* XXXX020 make this ipv6-capable */
   uint32_t addr; /**< Base address to accept or reject. */

Modified: tor/trunk/src/or/policies.c
===================================================================
--- tor/trunk/src/or/policies.c	2007-11-30 19:07:11 UTC (rev 12616)
+++ tor/trunk/src/or/policies.c	2007-11-30 20:09:09 UTC (rev 12617)
@@ -486,8 +486,11 @@
     tmp=ap;
     while (tmp) {
       if (tmp->next && addr_policy_covers(ap, tmp->next)) {
+        char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN];
+        policy_write_item(p1, sizeof(p1), tmp->next);
+        policy_write_item(p2, sizeof(p2), ap);
         log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s.  It is made "
-            "redundant by %s.", tmp->next->string, ap->string);
+            "redundant by %s.", p1, p2);
         victim = tmp->next;
         tmp->next = victim->next;
         victim->next = NULL;
@@ -516,8 +519,11 @@
         }
       } else { /* policy_types are equal. */
         if (addr_policy_covers(tmp, ap)) {
+          char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN];
+          policy_write_item(p1, sizeof(p1), ap);
+          policy_write_item(p2, sizeof(p2), tmp);
           log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s.  It is already "
-              "covered by %s.", ap->string, tmp->string);
+              "covered by %s.", ap, tmp);
           victim = ap;
           ap = ap->next;
 
@@ -694,7 +700,6 @@
   while (p) {
     e = p;
     p = p->next;
-    tor_free(e->string);
     tor_free(e);
   }
 }

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2007-11-30 19:07:11 UTC (rev 12616)
+++ tor/trunk/src/or/routerparse.c	2007-11-30 20:09:09 UTC (rev 12617)
@@ -2480,7 +2480,6 @@
 {
   addr_policy_t *newe;
   char *arg;
-  char buf[POLICY_BUF_LEN];
 
   tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
 
@@ -2500,10 +2499,6 @@
                                 &newe->prt_min, &newe->prt_max))
     goto policy_read_failed;
 
-  if (policy_write_item(buf, sizeof(buf), newe) < 0)
-    goto policy_read_failed;
-
-  newe->string = tor_strdup(buf);
   return newe;
 
 policy_read_failed:
@@ -2540,16 +2535,13 @@
 
   nextp = &result;
   for (net = 0; private_nets[net]; ++net) {
-    size_t len;
+    char buf[POLICY_BUF_LEN];
     *nextp = tor_malloc_zero(sizeof(addr_policy_t));
     (*nextp)->policy_type = (tok->tp == K_REJECT) ? ADDR_POLICY_REJECT
       : ADDR_POLICY_ACCEPT;
-    len = strlen(arg)+strlen(private_nets[net])+16;
-    (*nextp)->string = tor_malloc(len+1);
-    tor_snprintf((*nextp)->string, len, "%s %s%s",
-                 tok->tp == K_REJECT ? "reject" : "accept",
+    tor_snprintf(buf, sizeof(buf), "%s%s",
                  private_nets[net], arg);
-    if (parse_addr_and_port_range((*nextp)->string + 7,
+    if (parse_addr_and_port_range(buf,
                                   &(*nextp)->addr, &(*nextp)->maskbits,
                                   &(*nextp)->prt_min, &(*nextp)->prt_max)) {
       log_warn(LD_BUG, "Couldn't parse an address range we generated!");
@@ -2565,22 +2557,10 @@
 void
 assert_addr_policy_ok(addr_policy_t *t)
 {
-  addr_policy_t *t2;
   while (t) {
     tor_assert(t->policy_type == ADDR_POLICY_REJECT ||
                t->policy_type == ADDR_POLICY_ACCEPT);
     tor_assert(t->prt_min <= t->prt_max);
-    t2 = router_parse_addr_policy_from_string(t->string, -1);
-    tor_assert(t2);
-    tor_assert(t2->policy_type == t->policy_type);
-    tor_assert(t2->addr == t->addr);
-    tor_assert(t2->maskbits == t->maskbits);
-    tor_assert(t2->prt_min == t->prt_min);
-    tor_assert(t2->prt_max == t->prt_max);
-    tor_assert(!strcmp(t2->string, t->string));
-    tor_assert(t2->next == NULL);
-    addr_policy_free(t2);
-
     t = t->next;
   }
 

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2007-11-30 19:07:11 UTC (rev 12616)
+++ tor/trunk/src/or/test.c	2007-11-30 20:09:09 UTC (rev 12617)
@@ -2191,7 +2191,6 @@
   r1.platform = tor_strdup(platform);
 
   ex1.policy_type = ADDR_POLICY_ACCEPT;
-  ex1.string = NULL;
   ex1.addr = 0;
   ex1.maskbits = 0;
   ex1.prt_min = ex1.prt_max = 80;
@@ -2925,7 +2924,6 @@
   test_eq(16, policy->maskbits);
   test_eq(1, policy->prt_min);
   test_eq(65535, policy->prt_max);
-  test_streq("reject 192.168.0.0/16:*", policy->string);
 
   test_assert(ADDR_POLICY_ACCEPTED ==
           compare_addr_to_addr_policy(0x01020304u, 2, policy));
@@ -2957,8 +2955,8 @@
   line.next = NULL;
   test_assert(0 == policies_parse_exit_policy(&line, &policy, 0, NULL));
   test_assert(policy);
-  test_streq(policy->string, "accept *:80");
-  test_streq(policy->next->string, "reject *:*");
+  //test_streq(policy->string, "accept *:80");
+  //test_streq(policy->next->string, "reject *:*");
   test_eq_ptr(policy->next->next, NULL);
 
   addr_policy_free(policy);



More information about the tor-commits mailing list