int for_directory,
dirinfo_type_t dirtype,
int *n_options_out);
+static guard_selection_t * guard_selection_new(void);
static int num_bridges_usable(void);
/* Default number of entry guards in the case where the NumEntryGuards
#define MIN_N_GUARDS 1
#define MAX_N_GUARDS 10
+/** Allocate a new guard_selection_t */
+
+static guard_selection_t *
+guard_selection_new(void)
+{
+ guard_selection_t *gs;
+
+ gs = tor_malloc_zero(sizeof(*gs));
+ gs->chosen_entry_guards = smartlist_new();
+
+ return gs;
+}
+
/** Get current default guard_selection_t, creating it if necessary */
guard_selection_t *
get_guard_selection_info(void)
}
if (!curr_guard_context) {
- curr_guard_context = tor_malloc_zero(sizeof(*curr_guard_context));
+ curr_guard_context = guard_selection_new();
smartlist_add(guard_contexts, curr_guard_context);
}
get_entry_guards_for_guard_selection(guard_selection_t *gs)
{
tor_assert(gs != NULL);
-
- if (!(gs->chosen_entry_guards)) {
- gs->chosen_entry_guards = smartlist_new();
- }
+ tor_assert(gs->chosen_entry_guards != NULL);
return gs->chosen_entry_guards;
}
entry_guard_t *entry;
tor_assert(gs != NULL);
+ tor_assert(gs->chosen_entry_guards != NULL);
if (chosen) {
node = chosen;
if (!for_discovery)
entry->made_contact = 1;
- if (gs->chosen_entry_guards == NULL) {
- gs->chosen_entry_guards = smartlist_new();
- }
-
if (prepend)
smartlist_insert(gs->chosen_entry_guards, 0, entry);
else
const int num_needed = decide_num_guards(options, for_directory);
tor_assert(gs != NULL);
- if (gs->chosen_entry_guards == NULL) {
- gs->chosen_entry_guards = smartlist_new();
- }
+ tor_assert(gs->chosen_entry_guards != NULL);
while (num_live_entry_guards_for_guard_selection(gs, for_directory)
< num_needed) {
int retval = 0;
tor_assert(gs != NULL);
+ tor_assert(gs->chosen_entry_guards != NULL);
if (n_options_out)
*n_options_out = 0;
- if (!(gs->chosen_entry_guards))
- gs->chosen_entry_guards = smartlist_new();
-
if (gs->should_add_entry_nodes)
entry_guards_set_from_config(gs, options);
config_line_t **next, *line;
guard_selection_t *gs = get_guard_selection_info();
+ tor_assert(gs != NULL);
+ tor_assert(gs->chosen_entry_guards != NULL);
+
if (!gs->dirty)
return;
config_free_lines(state->EntryGuards);
next = &state->EntryGuards;
*next = NULL;
- if (!(gs->chosen_entry_guards))
- gs->chosen_entry_guards = smartlist_new();
SMARTLIST_FOREACH_BEGIN(gs->chosen_entry_guards, entry_guard_t *, e) {
char dbuf[HEX_DIGEST_LEN+1];
if (!e->made_contact)
{
guard_selection_t *gs = get_guard_selection_info();
+ tor_assert(gs != NULL);
+ tor_assert(gs->chosen_entry_guards != NULL);
+
(void) conn;
(void) errmsg;
smartlist_t *sl = smartlist_new();
char tbuf[ISO_TIME_LEN+1];
char nbuf[MAX_VERBOSE_NICKNAME_LEN+1];
- if (!(gs->chosen_entry_guards))
- gs->chosen_entry_guards = smartlist_new();
+
SMARTLIST_FOREACH_BEGIN(gs->chosen_entry_guards, entry_guard_t *, e) {
const char *status = NULL;
time_t when = 0;
int need_bridges = options->UseBridges != 0;
guard_selection_t *gs = get_guard_selection_info();
- if (!(gs->chosen_entry_guards))
- gs->chosen_entry_guards = smartlist_new();
+ tor_assert(gs != NULL);
+ tor_assert(gs->chosen_entry_guards != NULL);
+
SMARTLIST_FOREACH_BEGIN(gs->chosen_entry_guards, entry_guard_t *, e) {
node = node_get_by_id(e->identity);
if (node && node_has_descriptor(node) &&