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

[or-cvs] cache .exit address better (i think)



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

Modified Files:
	connection_edge.c or.h relay.c 
Log Message:
cache .exit address better (i think)


Index: connection_edge.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.284
retrieving revision 1.285
diff -u -d -r1.284 -r1.285
--- connection_edge.c	23 Feb 2005 20:35:26 -0000	1.284
+++ connection_edge.c	24 Feb 2005 11:44:08 -0000	1.285
@@ -490,20 +490,35 @@
 /** Record the fact that <b>address</b> resolved to <b>val</b>.
  * We can now use this in subsequent streams via addressmap_rewrite()
  * so we can more correctly choose an exit that will allow <b>address</b>.
+ *
+ * If <b>exitname</b> is defined, then append the addresses with
+ * ".exitname.exit" before registering the mapping.
  */
-void client_dns_set_addressmap(const char *address, uint32_t val)
+void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname)
 {
   struct in_addr in;
-  char *addr;
+  char extendedaddress[MAX_SOCKS_ADDR_LEN+MAX_HEX_NICKNAME_LEN+10];
+  char valbuf[INET_NTOA_BUF_LEN];
+  char extendedval[INET_NTOA_BUF_LEN+MAX_HEX_NICKNAME_LEN+10];
 
   tor_assert(address); tor_assert(val);
 
   if (tor_inet_aton(address, &in))
     return; /* If address was an IP address already, don't add a mapping. */
   in.s_addr = htonl(val);
-  addr = tor_malloc(INET_NTOA_BUF_LEN);
-  tor_inet_ntoa(&in,addr,INET_NTOA_BUF_LEN);
-  addressmap_register(address, addr,
+  tor_inet_ntoa(&in,valbuf,sizeof(valbuf));
+  if (exitname) {
+    tor_snprintf(extendedaddress, sizeof(extendedaddress),
+                 "%s.%s.exit", address, exitname);
+    tor_snprintf(extendedval, sizeof(extendedval),
+                 "%s.%s.exit", valbuf, exitname);
+  } else {
+    tor_snprintf(extendedaddress, sizeof(extendedaddress),
+                 "%s", address);
+    tor_snprintf(extendedval, sizeof(extendedval),
+                 "%s", valbuf);
+  }
+  addressmap_register(extendedaddress, tor_strdup(extendedval),
                       time(NULL) + MAX_DNS_ENTRY_AGE);
 }
 
@@ -754,8 +769,8 @@
   }
 
   string_addr = ap_conn->socks_request->address;
-  payload_len = strlen(string_addr);
-  tor_assert(strlen(string_addr) <= RELAY_PAYLOAD_SIZE);
+  payload_len = strlen(string_addr)+1;
+  tor_assert(payload_len <= RELAY_PAYLOAD_SIZE);
 
   log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id);
 
@@ -840,7 +855,8 @@
   if (answer_type == RESOLVED_TYPE_IPV4) {
     uint32_t a = get_uint32(answer);
     if (a)
-      client_dns_set_addressmap(conn->socks_request->address, ntohl(a));
+      client_dns_set_addressmap(conn->socks_request->address, ntohl(a),
+                                conn->chosen_exit_name);
   }
 
   if (conn->socks_request->socks_version == 4) {

Index: or.h
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.539
retrieving revision 1.540
diff -u -d -r1.539 -r1.540
--- or.h	24 Feb 2005 10:56:55 -0000	1.539
+++ or.h	24 Feb 2005 11:44:08 -0000	1.540
@@ -1289,7 +1289,7 @@
 int addressmap_already_mapped(const char *address);
 void addressmap_register(const char *address, char *new_address, time_t expires);
 int client_dns_incr_failures(const char *address);
-void client_dns_set_addressmap(const char *address, uint32_t val);
+void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
 
 void parse_socks_policy(void);
 void free_socks_policy(void);

Index: relay.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/relay.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- relay.c	24 Feb 2005 10:22:00 -0000	1.40
+++ relay.c	24 Feb 2005 11:44:08 -0000	1.41
@@ -518,7 +518,8 @@
         connection_mark_for_close(conn);
         return 0;
       }
-      client_dns_set_addressmap(conn->socks_request->address, addr);
+      client_dns_set_addressmap(conn->socks_request->address, addr,
+                                conn->chosen_exit_name);
 
       /* check if he *ought* to have allowed it */
       exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
@@ -591,7 +592,8 @@
         connection_mark_for_close(conn);
         return 0;
       }
-      client_dns_set_addressmap(conn->socks_request->address, addr);
+      client_dns_set_addressmap(conn->socks_request->address, addr,
+                                conn->chosen_exit_name);
     }
     circuit_log_path(LOG_INFO,circ);
     connection_ap_handshake_socks_reply(conn, NULL, 0, 1);