[or-cvs] Get address map resetting implemented.

Nick Mathewson nickm at seul.org
Fri Mar 11 21:39:42 UTC 2005


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

Modified Files:
	config.c connection_edge.c main.c or.h 
Log Message:
Get address map resetting implemented.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.319
retrieving revision 1.320
diff -u -d -r1.319 -r1.320
--- config.c	27 Feb 2005 09:47:00 -0000	1.319
+++ config.c	11 Mar 2005 21:39:39 -0000	1.320
@@ -1823,6 +1823,7 @@
   struct config_line_t *opt;
   char *from, *to;
 
+  addressmap_clear_configured();
   elts = smartlist_create();
   for (opt = options->AddressMap; opt; opt = opt->next) {
     smartlist_split_string(elts, opt->value, NULL,

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.293
retrieving revision 1.294
diff -u -d -r1.293 -r1.294
--- connection_edge.c	3 Mar 2005 06:37:54 -0000	1.293
+++ connection_edge.c	11 Mar 2005 21:39:39 -0000	1.294
@@ -435,29 +435,26 @@
   addressmap_ent_free(ent);
 }
 
-/** A helper function for addressmap_clean() below. If ent is too old,
- * then remove it from the tree and return NULL, else return ent.
- */
-static void *
-_addressmap_remove_if_expired(const char *addr,
-                              addressmap_entry_t *ent,
-                              time_t *nowp) {
-  if (ent->expires > 1 && ent->expires < *nowp) {
-    log(LOG_INFO, "Addressmap: expiring remap (%s to %s)",
-           addr, ent->new_address);
-    addressmap_ent_remove(addr,ent);
-    return NULL;
-  } else {
-    return ent;
-  }
+/** Remove all entries from the addressmap that were set via the
+ * configuration file or the command line. */
+void
+addressmap_clear_configured(void)
+{
+  addressmap_get_mappings(NULL, 0, 0);
+}
+
+/** Remove all entries from the addressmap that are set to expire, ever. */
+void
+addressmap_clear_transient(void)
+{
+  addressmap_get_mappings(NULL, 2, TIME_MAX);
 }
 
 /** Clean out entries from the addressmap cache that were
  * added long enough ago that they are no longer valid.
  */
 void addressmap_clean(time_t now) {
-  strmap_foreach(addressmap,
-                 (strmap_foreach_fn)_addressmap_remove_if_expired, &now);
+  addressmap_get_mappings(NULL, 2, now);
 }
 
 /** Free all the elements in the addressmap, and free the addressmap
@@ -708,7 +705,11 @@
   return 0;
 }
 
-/* DOCDOC */
+/* Iterate over all address mapings which have exipry times between
+ * min_expires and max_expires, inclusive.  If sl is provided, add an
+ * "old-addr new-addr" string to sl for each mapping.  If sl is NULL,
+ * remove the mappings.
+ */
 void
 addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
 {
@@ -717,17 +718,23 @@
    void *_val;
    addressmap_entry_t *val;
 
-   tor_assert(sl);
-
    for (iter = strmap_iter_init(addressmap); !strmap_iter_done(iter);
         iter = strmap_iter_next(addressmap,iter)) {
      strmap_iter_get(iter, &key, &_val);
      val = _val;
      if (val->expires >= min_expires && val->expires <= max_expires) {
-       size_t len = strlen(key)+strlen(val->new_address)+2;
-       char *line = tor_malloc(len);
-       tor_snprintf(line, len, "%s %s", key, val->new_address);
-       smartlist_add(sl, line);
+       if (sl) {
+         size_t len = strlen(key)+strlen(val->new_address)+2;
+         char *line = tor_malloc(len);
+         tor_snprintf(line, len, "%s %s", key, val->new_address);
+         smartlist_add(sl, line);
+         iter = strmap_iter_next(addressmap,iter);
+       } else {
+         addressmap_ent_remove(key, val);
+         iter = strmap_iter_next_rmv(addressmap,iter);
+       }
+     } else {
+       iter = strmap_iter_next(addressmap,iter);
      }
    }
 }

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.456
retrieving revision 1.457
diff -u -d -r1.456 -r1.457
--- main.c	2 Mar 2005 03:13:05 -0000	1.456
+++ main.c	11 Mar 2005 21:39:39 -0000	1.457
@@ -892,6 +892,7 @@
   if (accounting_is_enabled(options))
     accounting_record_bandwidth_usage(time(NULL));
 
+  addressmap_clear_transient();
   /* first, reload config variables, in case they've changed */
   /* no need to provide argc/v, they've been cached inside init_from_config */
   if (init_from_config(0, NULL) < 0) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.553
retrieving revision 1.554
diff -u -d -r1.553 -r1.554
--- or.h	11 Mar 2005 20:47:23 -0000	1.553
+++ or.h	11 Mar 2005 21:39:39 -0000	1.554
@@ -1312,6 +1312,8 @@
 
 void addressmap_init(void);
 void addressmap_clean(time_t now);
+void addressmap_clear_configured(void);
+void addressmap_clear_transient(void);
 void addressmap_free_all(void);
 void addressmap_rewrite(char *address, size_t maxlen);
 int addressmap_already_mapped(const char *address);



More information about the tor-commits mailing list