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

[or-cvs] r10967: make progress towards retrying our bridges when they're all (tor/trunk/src/or)



Author: arma
Date: 2007-07-29 00:38:21 -0400 (Sun, 29 Jul 2007)
New Revision: 10967

Modified:
   tor/trunk/src/or/circuitbuild.c
   tor/trunk/src/or/circuituse.c
   tor/trunk/src/or/or.h
Log:
make progress towards retrying our bridges when they're all
down and we get a new socks request


Modified: tor/trunk/src/or/circuitbuild.c
===================================================================
--- tor/trunk/src/or/circuitbuild.c	2007-07-29 04:10:05 UTC (rev 10966)
+++ tor/trunk/src/or/circuitbuild.c	2007-07-29 04:38:21 UTC (rev 10967)
@@ -294,7 +294,7 @@
   return circ;
 }
 
-/** Build a new circuit for <b>purpose</b>. If <b>info</b>
+/** Build a new circuit for <b>purpose</b>. If <b>exit</b>
  * is defined, then use that as your exit router, else choose a suitable
  * exit node.
  *
@@ -2860,17 +2860,19 @@
 int
 any_bridge_descriptors_known(void)
 {
+  tor_assert(get_options()->UseBridges);
   return choose_random_entry(NULL)!=NULL ? 1 : 0;
 }
 
-#if 0
 /** Return 1 if we have at least one descriptor for a bridge and
- * all descriptors we know are down. Else return 0. */
-int
-all_bridges_down(void)
+ * all descriptors we know are down. Else return 0. If <b>act</b> is
+ * 1, then mark the down bridges up; else just observe and report. */
+static int
+bridges_retry_helper(int act)
 {
   routerinfo_t *ri;
   int any_known = 0;
+  int any_running = 0;
   if (!entry_guards)
     entry_guards = smartlist_create();
   SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e,
@@ -2879,13 +2881,32 @@
       if (ri && ri->purpose == ROUTER_PURPOSE_BRIDGE) {
         any_known = 1;
         if (ri->is_running)
-          return 0; /* some bridge is both known and running */
+          any_running = 1; /* some bridge is both known and running */
+        else if (act) { /* mark it for retry */
+          ri->is_running = 1;
+          e->can_retry = 1;
+          e->bad_since = 0;
+        }
       }
     });
-  return any_known;
+  return any_known && !any_running;
 }
-#endif
 
+/** Do we know any descriptors for our bridges, and are they all
+ * down? */
+int
+bridges_should_be_retried(void)
+{
+  return bridges_retry_helper(0);
+}
+
+/** Mark all down known bridges up. */
+void
+bridges_retry_all(void)
+{
+  bridges_retry_helper(1);
+}
+
 /** Release all storage held by the list of entry guards and related
  * memory structs. */
 void

Modified: tor/trunk/src/or/circuituse.c
===================================================================
--- tor/trunk/src/or/circuituse.c	2007-07-29 04:10:05 UTC (rev 10966)
+++ tor/trunk/src/or/circuituse.c	2007-07-29 04:38:21 UTC (rev 10967)
@@ -813,8 +813,9 @@
   return circ;
 }
 
-/** Launch a new circuit with purpose <b>purpose</b> and exit node <b>info</b>
- * (or NULL to select a random exit node).  If <b>need_uptime</b> is true,
+/** Launch a new circuit with purpose <b>purpose</b> and exit node
+ * <b>extend_info</b> (or NULL to select a random exit node).
+ * If <b>need_uptime</b> is true,
  * choose among routers with high uptime.  If <b>need_capacity</b> is true,
  * choose among routers with high bandwidth.  If <b>internal</b> is true, the
  * last hop need not be an exit node. Return the newly allocated circuit on
@@ -942,6 +943,7 @@
   int check_exit_policy;
   int need_uptime, need_internal;
   int want_onehop;
+  or_options_t *options = get_options();
 
   tor_assert(conn);
   tor_assert(circp);
@@ -952,7 +954,7 @@
   want_onehop = conn->socks_request->command == SOCKS_COMMAND_CONNECT_DIR;
 
   need_uptime = (conn->socks_request->command == SOCKS_COMMAND_CONNECT) &&
-                smartlist_string_num_isin(get_options()->LongLivedPorts,
+                smartlist_string_num_isin(options->LongLivedPorts,
                                           conn->socks_request->port);
   need_internal = desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL;
 
@@ -966,10 +968,17 @@
 
   if (!want_onehop && !router_have_minimum_dir_info()) {
     if (!connection_get_by_type(CONN_TYPE_DIR)) {
-      log_notice(LD_APP|LD_DIR,
-                 "Application request when we're believed to be "
-                 "offline. Optimistically trying directory fetches again.");
-      routerlist_retry_directory_downloads(time(NULL));
+      if (options->UseBridges && bridges_should_be_retried()) {
+        log_notice(LD_APP|LD_DIR,
+                   "Application request when we're believed to be "
+                   "offline. Optimistically trying known bridges again.");
+        bridges_retry_all();
+      } else if (!options->UseBridges || any_bridge_descriptors_known()) {
+        log_notice(LD_APP|LD_DIR,
+                   "Application request when we're believed to be "
+                   "offline. Optimistically trying directory fetches again.");
+        routerlist_retry_directory_downloads(time(NULL));
+      }
     }
     /* the stream will be dealt with when router_have_minimum_dir_info becomes
      * 1, or when all directory attempts fail and directory_all_unreachable()

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-07-29 04:10:05 UTC (rev 10966)
+++ tor/trunk/src/or/or.h	2007-07-29 04:38:21 UTC (rev 10967)
@@ -2264,6 +2264,8 @@
 void fetch_bridge_descriptors(time_t now);
 void learned_bridge_descriptor(routerinfo_t *ri);
 int any_bridge_descriptors_known(void);
+int bridges_should_be_retried(void);
+void bridges_retry_all(void);
 
 void entry_guards_free_all(void);