[or-cvs] r10609: now we can specify a bridge without specifying its key, and (tor/trunk/src/or)

arma at seul.org arma at seul.org
Fri Jun 15 06:01:04 UTC 2007


Author: arma
Date: 2007-06-15 02:01:04 -0400 (Fri, 15 Jun 2007)
New Revision: 10609

Modified:
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/circuitlist.c
   tor/trunk/src/or/connection_or.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/routerlist.c
Log:
now we can specify a bridge without specifying its key,
and we will still connect to it and use it. getting closer!


Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2007-06-15 04:23:36 UTC (rev 10608)
+++ tor/trunk/src/or/circuitbuild.c	2007-06-15 06:01:04 UTC (rev 10609)
@@ -413,13 +413,23 @@
 
   SMARTLIST_FOREACH(pending_circs, circuit_t *, circ,
     {
-      /* This check is redundant wrt get_all_pending_on_or_conn, but I'm
+      /* These checks are redundant wrt get_all_pending_on_or_conn, but I'm
        * leaving them in in case it's possible for the status of a circuit to
        * change as we're going down the list. */
       if (circ->marked_for_close || circ->n_conn ||
-          circ->state != CIRCUIT_STATE_OR_WAIT ||
-          memcmp(or_conn->identity_digest, circ->n_conn_id_digest, DIGEST_LEN))
+          circ->state != CIRCUIT_STATE_OR_WAIT)
         continue;
+      if (tor_digest_is_zero(circ->n_conn_id_digest)) {
+        /* Look at addr/port. This is an unkeyed connection. */
+        if (circ->n_addr != or_conn->_base.addr ||
+            circ->n_port != or_conn->_base.port)
+          continue;
+      } else {
+        /* We expected a key. See if it's the right one. */
+        if (memcmp(or_conn->identity_digest,
+                   circ->n_conn_id_digest, DIGEST_LEN))
+          continue;
+      }
       if (!status) { /* or_conn failed; close circ */
         log_info(LD_CIRC,"or_conn failed. Closing circ.");
         circuit_mark_for_close(circ, END_CIRC_REASON_OR_CONN_CLOSED);
@@ -2670,6 +2680,7 @@
   smartlist_clear(bridge_list);
 }
 
+#if 0
 /** Return 1 if <b>digest</b> is one of our known bridges. */
 int
 identity_digest_is_a_bridge(const char *digest)
@@ -2681,7 +2692,25 @@
     });
   return 0;
 }
+#endif
 
+/** Return 1 if <b>ri</b> is one of our known bridges (either by
+ * comparing keys if possible, else by comparing addr/port). */
+int
+routerinfo_is_a_bridge(routerinfo_t *ri)
+{
+  SMARTLIST_FOREACH(bridge_list, bridge_info_t *, bridge,
+    {
+      if (tor_digest_is_zero(bridge->identity) &&
+          bridge->addr == ri->addr && bridge->port == ri->or_port)
+        return 1;
+      if (!memcmp(bridge->identity, ri->cache_info.identity_digest,
+                  DIGEST_LEN))
+        return 1;
+    });
+  return 0;
+}
+
 /** Remember a new bridge at <b>addr</b>:<b>port</b>. If <b>digest</b>
  * is set, it tells us the identity key too. */
 void

Modified: tor/trunk/src/or/circuitlist.c
===================================================================
--- tor/trunk/src/or/circuitlist.c	2007-06-15 04:23:36 UTC (rev 10608)
+++ tor/trunk/src/or/circuitlist.c	2007-06-15 06:01:04 UTC (rev 10609)
@@ -218,7 +218,7 @@
   }
 }
 
-/** Append to <b>out</b> the number of circuits in state OR_WAIT, waiting for
+/** Append to <b>out</b> all circuits in state OR_WAIT waiting for
  * the given connection. */
 void
 circuit_get_all_pending_on_or_conn(smartlist_t *out, or_connection_t *or_conn)
@@ -234,11 +234,18 @@
     if (circ->marked_for_close)
       continue;
     tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT);
-    if (!circ->n_conn &&
-        !memcmp(or_conn->identity_digest, circ->n_conn_id_digest,
-                DIGEST_LEN)) {
-      smartlist_add(out, circ);
+    if (tor_digest_is_zero(circ->n_conn_id_digest)) {
+      /* Look at addr/port. This is an unkeyed connection. */
+      if (circ->n_addr != or_conn->_base.addr ||
+          circ->n_port != or_conn->_base.port)
+        continue;
+    } else {
+      /* We expected a key. See if it's the right one. */
+      if (memcmp(or_conn->identity_digest,
+                 circ->n_conn_id_digest, DIGEST_LEN))
+        continue;
     }
+    smartlist_add(out, circ);
   });
 }
 

Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c	2007-06-15 04:23:36 UTC (rev 10608)
+++ tor/trunk/src/or/connection_or.c	2007-06-15 06:01:04 UTC (rev 10609)
@@ -655,6 +655,17 @@
     conn->circ_id_type = CIRC_ID_TYPE_NEITHER;
   }
 
+  if (started_here && tor_digest_is_zero(conn->identity_digest)) {
+    memcpy(conn->identity_digest, digest_rcvd, DIGEST_LEN);
+    conn->nickname = tor_malloc(HEX_DIGEST_LEN+2);
+    conn->nickname[0] = '$';
+    base16_encode(conn->nickname+1, HEX_DIGEST_LEN+1,
+                  conn->identity_digest, DIGEST_LEN);
+    log_info(LD_OR, "Connected to router %s at %s:%d without knowing "
+                    "its key. Hoping for the best.",
+                    conn->nickname, conn->_base.address, conn->_base.port);
+  }
+
   if (started_here) {
     int as_advertised = 1;
     tor_assert(has_cert);

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-06-15 04:23:36 UTC (rev 10608)
+++ tor/trunk/src/or/or.h	2007-06-15 06:01:04 UTC (rev 10609)
@@ -2223,7 +2223,7 @@
 void entry_guards_free_all(void);
 
 void clear_bridge_list(void);
-int identity_digest_is_a_bridge(const char *digest);
+int routerinfo_is_a_bridge(routerinfo_t *ri);
 void bridge_add_from_config(uint32_t addr, uint16_t port, char *digest);
 void fetch_bridge_descriptors(void);
 void learned_bridge_descriptor(routerinfo_t *ri);

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-06-15 04:23:36 UTC (rev 10608)
+++ tor/trunk/src/or/routerlist.c	2007-06-15 06:01:04 UTC (rev 10609)
@@ -2388,7 +2388,7 @@
      * we are receiving in response to a fetch. */
 
     if (!signed_desc_digest_is_recognized(&router->cache_info) &&
-        !identity_digest_is_a_bridge(router->cache_info.identity_digest)) {
+        !routerinfo_is_a_bridge(router)) {
       /* We asked for it, so some networkstatus must have listed it when we
        * did.  Save it if we're a cache in case somebody else asks for it. */
       log_info(LD_DIR,



More information about the tor-commits mailing list