[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Finish implementing GETINFO; make it easy to query address ...



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

Modified Files:
	connection_edge.c control.c or.h 
Log Message:
Finish implementing GETINFO; make it easy to query address maps.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.292
retrieving revision 1.293
diff -u -d -r1.292 -r1.293
--- connection_edge.c	2 Mar 2005 22:29:58 -0000	1.292
+++ connection_edge.c	3 Mar 2005 06:37:54 -0000	1.293
@@ -356,7 +356,11 @@
  * When an addressmap request is made but one is already registered,
  * the new one is replaced only if the currently registered one has
  * no "new_address" (that is, it's in the process of dns resolve),
- * or if the new one is permanent (expires==0).
+ * or if the new one is permanent (expires==0 or 1).
+ *
+ * (We overload the 'expires' field, using "0" for mappings set via
+ * the configuration file, "1" for mappings set from the control
+ * interface, and other values for DNS mappings that can expire.)
  */
 typedef struct {
   char *new_address;
@@ -438,7 +442,7 @@
 _addressmap_remove_if_expired(const char *addr,
                               addressmap_entry_t *ent,
                               time_t *nowp) {
-  if (ent->expires && ent->expires < *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);
@@ -493,7 +497,8 @@
 }
 
 /** Register a request to map <b>address</b> to <b>new_address</b>,
- * which will expire on <b>expires</b> (or 0 if never expires).
+ * which will expire on <b>expires</b> (or 0 if never expires from config
+ * file, 1 if never expires from controller).
  *
  * <b>new_address</b> should be a newly dup'ed string, which we'll use or
  * free as appropriate. We will leave address alone.
@@ -505,7 +510,7 @@
   addressmap_entry_t *ent;
 
   ent = strmap_get(addressmap, address);
-  if (ent && ent->new_address && expires) {
+  if (ent && ent->new_address && expires>1) {
     log_fn(LOG_INFO,"Addressmap ('%s' to '%s') not performed, since it's already mapped to '%s'", address, new_address, ent->new_address);
     tor_free(new_address);
     return;
@@ -688,7 +693,7 @@
   tor_free(*addrp);
   *addrp = addressmap_get_virtual_address(type);
   strmap_set(virtaddress_reversemap, new_address, tor_strdup(*addrp));
-  addressmap_register(*addrp, new_address, 0);
+  addressmap_register(*addrp, new_address, 1);
   return *addrp;
 }
 
@@ -703,6 +708,30 @@
   return 0;
 }
 
+/* DOCDOC */
+void
+addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
+{
+   strmap_iter_t *iter;
+   const char *key;
+   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);
+     }
+   }
+}
+
 /** connection_edge_process_inbuf() found a conn in state
  * socks_wait. See if conn->inbuf has the right bytes to proceed with
  * the socks handshake.

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- control.c	2 Mar 2005 22:29:58 -0000	1.51
+++ control.c	3 Mar 2005 06:37:54 -0000	1.52
@@ -487,7 +487,8 @@
                          SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
   SMARTLIST_FOREACH(lines, const char *, line,
   {
-    smartlist_split_string(elts, body, " ", 0, 2);
+    tor_strlower(line);
+    smartlist_split_string(elts, line, " ", 0, 2);
     if (smartlist_len(elts) == 2) {
       const char *from = smartlist_get(elts,0);
       const char *to = smartlist_get(elts,1);
@@ -510,7 +511,7 @@
           smartlist_add(reply, ans);
         }
       } else {
-        addressmap_register(from, tor_strdup(to), 0);
+        addressmap_register(from, tor_strdup(to), 1);
         smartlist_add(reply, tor_strdup(line));
       }
     } else {
@@ -559,8 +560,27 @@
       *cp++ = ',';
     });
     return answer;
-  } else if (!strcmp(question, "addr-mappings")) {
-    return NULL; /* XXXX */
+  } else if (!strcmpstart(question, "addr-mappings/")) {
+    time_t min_e, max_e;
+    smartlist_t *mappings;
+    char *answer;
+    if (!strcmp(question, "addr-mappings/all")) {
+      min_e = 0; max_e = TIME_MAX;
+    } else if (!strcmp(question, "addr-mappings/cache")) {
+      min_e = 2; max_e = TIME_MAX;
+    } else if (!strcmp(question, "addr-mappings/config")) {
+      min_e = 0; max_e = 0;
+    } else if (!strcmp(question, "addr-mappings/control")) {
+      min_e = 1; max_e = 1;
+    } else {
+      return NULL;
+    }
+    mappings = smartlist_create();
+    addressmap_get_mappings(mappings, min_e, max_e);
+    answer = smartlist_join_strings(mappings, "\n", 1, NULL);
+    SMARTLIST_FOREACH(mappings, char *, cp, tor_free(cp));
+    smartlist_free(mappings);
+    return answer;
   } else {
     /* unrecognized key */
     return NULL;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.551
retrieving revision 1.552
diff -u -d -r1.551 -r1.552
--- or.h	2 Mar 2005 22:29:58 -0000	1.551
+++ or.h	3 Mar 2005 06:37:54 -0000	1.552
@@ -1320,6 +1320,7 @@
 int client_dns_incr_failures(const char *address);
 void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
 char *addressmap_register_virtual_address(int type, char *new_address);
+void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires);
 
 void parse_socks_policy(void);
 void free_socks_policy(void);