summaryrefslogtreecommitdiff
path: root/src/or/entrynodes.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-01-31 12:31:43 -0500
committerNick Mathewson <nickm@torproject.org>2017-01-31 12:31:43 -0500
commit746d959100f0275e3ad4442e89901796f669413e (patch)
treea38157b8df08bef124337e8919699c04428ae336 /src/or/entrynodes.c
parent02da24f8e5b2ce34da941cc25ce9808b447065ac (diff)
downloadtor-746d959100f0275e3ad4442e89901796f669413e.tar.gz
tor-746d959100f0275e3ad4442e89901796f669413e.zip
Don't build circuits till primary guards have descriptors
In addition to not wanting to build circuits until we can see most of the paths in the network, and in addition to not wanting to build circuits until we have a consensus ... we shouldn't build circuits till all of our (in-use) primary guards have descriptors that we can use for them. This is another bug 21242 fix.
Diffstat (limited to 'src/or/entrynodes.c')
-rw-r--r--src/or/entrynodes.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 1cf1ff2c8e..6249e847a9 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -3335,6 +3335,43 @@ guards_retry_optimistic(const or_options_t *options)
return 1;
}
+/**
+ * Return true iff we know enough directory information to construct
+ * circuits through all of the primary guards we'd currently use.
+ */
+int
+guard_selection_have_enough_dir_info_to_build_circuits(guard_selection_t *gs)
+{
+ if (!gs->primary_guards_up_to_date)
+ entry_guards_update_primary(gs);
+
+ const int num_primary = get_n_primary_guards_to_use(GUARD_USAGE_TRAFFIC);
+ int n_missing_descriptors = 0;
+ int n_considered = 0;
+
+ SMARTLIST_FOREACH_BEGIN(gs->primary_entry_guards, entry_guard_t *, guard) {
+ entry_guard_consider_retry(guard);
+ if (guard->is_reachable == GUARD_REACHABLE_NO)
+ continue;
+ n_considered++;
+ if (!guard_has_descriptor(guard))
+ n_missing_descriptors++;
+ if (n_considered >= num_primary)
+ break;
+ } SMARTLIST_FOREACH_END(guard);
+
+ return n_missing_descriptors == 0;
+}
+
+/** As guard_selection_have_enough_dir_info_to_build_circuits, but uses
+ * the default guard selection. */
+int
+entry_guards_have_enough_dir_info_to_build_circuits(void)
+{
+ return guard_selection_have_enough_dir_info_to_build_circuits(
+ get_guard_selection_info());
+}
+
/** Free one guard selection context */
STATIC void
guard_selection_free(guard_selection_t *gs)