--- /dev/null
+ o Code simplification and refactoring:
+ - Do not allow the body of any SMARTLIST_FOREACH block to exceed
+ 10 lines. Doing so in the past has led to hard-to-debug code.
+ The new style is to use the SMARTLIST_FOREACH_{BEGIN,END} pair.
smartlist_split_string(domains_list, domains_str, ",", SPLIT_SKIP_SPACE,
-1);
tor_free(domains_str);
- SMARTLIST_FOREACH(domains_list, const char *, domain,
- {
+ SMARTLIST_FOREACH_BEGIN(domains_list, const char *, domain) {
if (!strcmp(domain, "*")) {
domains = ~0u;
} else {
domains |= d;
}
}
- });
+ } SMARTLIST_FOREACH_END(domain);
SMARTLIST_FOREACH(domains_list, char *, d, tor_free(d));
smartlist_free(domains_list);
if (err)
* came back? We should give our earlier entries another try too,
* and close this connection so we don't use it before we've given
* the others a shot. */
- SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e, {
+ SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
if (e == entry)
break;
if (e->made_contact) {
e->can_retry = 1;
}
}
- });
+ } SMARTLIST_FOREACH_END(e);
if (refuse_conn) {
log_info(LD_CIRC,
"Connected to new entry guard '%s' (%s). Marking earlier "
*next = NULL;
if (!entry_guards)
entry_guards = smartlist_new();
- SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e,
- {
+ SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
char dbuf[HEX_DIGEST_LEN+1];
if (!e->made_contact)
continue; /* don't write this one to disk */
next = &(line->next);
}
- });
+ } SMARTLIST_FOREACH_END(e);
if (!get_options()->AvoidDiskWrites)
or_state_mark_dirty(get_or_state(), 0);
entry_guards_dirty = 0;
any_pending_bridge_descriptor_fetches(void)
{
smartlist_t *conns = get_connection_array();
- SMARTLIST_FOREACH(conns, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
if (conn->type == CONN_TYPE_DIR &&
conn->purpose == DIR_PURPOSE_FETCH_SERVERDESC &&
TO_DIR_CONN(conn)->router_purpose == ROUTER_PURPOSE_BRIDGE &&
log_debug(LD_DIR, "found one: %s", conn->address);
return 1;
}
- });
+ } SMARTLIST_FOREACH_END(conn);
return 0;
}
*auth = NO_DIRINFO;
if (!list) /* empty list, answer is none */
return 0;
- SMARTLIST_FOREACH(list, const char *, string, {
+ SMARTLIST_FOREACH_BEGIN(list, const char *, string) {
if (!strcasecmp(string, "v1"))
*auth |= V1_DIRINFO;
else if (!strcmp(string, "1"))
/* no authority */;
else
return -1;
- });
+ } SMARTLIST_FOREACH_END(string);
return 0;
}
options->_AllowInvalid = 0;
if (options->AllowInvalidNodes) {
- SMARTLIST_FOREACH(options->AllowInvalidNodes, const char *, cp, {
+ SMARTLIST_FOREACH_BEGIN(options->AllowInvalidNodes, const char *, cp) {
if (!strcasecmp(cp, "entry"))
options->_AllowInvalid |= ALLOW_INVALID_ENTRY;
else if (!strcasecmp(cp, "exit"))
"Unrecognized value '%s' in AllowInvalidNodes", cp);
return -1;
}
- });
+ } SMARTLIST_FOREACH_END(cp);
}
if (!options->SafeLogging ||
now = time(NULL);
- SMARTLIST_FOREACH(conns, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
/* If we've been holding the connection open, but we haven't written
* for 15 seconds...
*/
conn->hold_open_until_flushed = 0;
}
}
- });
+ } SMARTLIST_FOREACH_END(conn);
}
#if defined(HAVE_SYS_UN_H) || defined(RUNNING_DOXYGEN)
"global_relayed_write_bucket");
/* refill the per-connection buckets */
- SMARTLIST_FOREACH(conns, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
int orbandwidthrate = or_conn->bandwidthrate;
conn->write_blocked_on_bw = 0;
connection_start_writing(conn);
}
- });
+ } SMARTLIST_FOREACH_END(conn);
}
/** Is the <b>bucket</b> for connection <b>conn</b> low enough that we
memset(alloc_by_type, 0, sizeof(alloc_by_type));
memset(n_conns_by_type, 0, sizeof(n_conns_by_type));
- SMARTLIST_FOREACH(conns, connection_t *, c,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, c) {
int tp = c->type;
++n_conns_by_type[tp];
if (c->inbuf) {
used_by_type[tp] += buf_datalen(c->outbuf);
alloc_by_type[tp] += buf_allocation(c->outbuf);
}
- });
+ } SMARTLIST_FOREACH_END(c);
for (i=0; i <= _CONN_TYPE_MAX; ++i) {
total_used += used_by_type[i];
total_alloc += alloc_by_type[i];
{
entry_connection_t *entry_conn;
smartlist_t *conns = get_connection_array();
- SMARTLIST_FOREACH(conns, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
if (conn->marked_for_close ||
conn->type != CONN_TYPE_AP ||
conn->state != AP_CONN_STATE_CIRCUIT_WAIT)
connection_mark_unattached_ap(entry_conn,
END_STREAM_REASON_CANT_ATTACH);
}
- });
+ } SMARTLIST_FOREACH_END(conn);
}
/** Tell any AP streams that are waiting for a one-hop tunnel to
(void) body_len; /* body is NUL-terminated; so we can ignore len. */
smartlist_split_string(questions, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- SMARTLIST_FOREACH(questions, const char *, q,
- {
+ SMARTLIST_FOREACH_BEGIN(questions, const char *, q) {
if (!option_is_recognized(q)) {
smartlist_add(unrecognized, (char*) q);
} else {
answer = next;
}
}
- });
+ } SMARTLIST_FOREACH_END(q);
if ((len = smartlist_len(unrecognized))) {
for (i=0; i < len-1; ++i)
routerlist_t *routerlist = router_get_routerlist();
smartlist_t *sl = smartlist_new();
if (routerlist && routerlist->routers) {
- SMARTLIST_FOREACH(routerlist->routers, const routerinfo_t *, ri,
- {
+ SMARTLIST_FOREACH_BEGIN(routerlist->routers, const routerinfo_t *, ri) {
const char *body = signed_descriptor_get_body(&ri->cache_info);
signed_descriptor_t *ei = extrainfo_get_by_descriptor_digest(
ri->cache_info.extra_info_digest);
smartlist_add(sl,
tor_strndup(body, ri->cache_info.signed_descriptor_len));
}
- });
+ } SMARTLIST_FOREACH_END(ri);
}
*answer = smartlist_join_strings(sl, "", 0, NULL);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c));
smartlist_free(args);
nodes = smartlist_new();
- SMARTLIST_FOREACH(router_nicknames, const char *, n,
- {
+ SMARTLIST_FOREACH_BEGIN(router_nicknames, const char *, n) {
const node_t *node = node_get_by_nickname(n, 1);
if (!node) {
connection_printf_to_buf(conn, "552 No such router \"%s\"\r\n", n);
goto done;
}
smartlist_add(nodes, (void*)node);
- });
+ } SMARTLIST_FOREACH_END(n);
if (!smartlist_len(nodes)) {
connection_write_str_to_buf("512 No router names provided\r\n", conn);
goto done;
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- SMARTLIST_FOREACH(args, char *, option,
- {
+ SMARTLIST_FOREACH_BEGIN(args, char *, option) {
if (!strcasecmpstart(option, "purpose=")) {
option += strlen("purpose=");
purpose = router_purpose_from_string(option);
"512 Unexpected argument \"%s\" to postdescriptor\r\n", option);
goto done;
}
- });
+ } SMARTLIST_FOREACH_END(option);
read_escaped_data(cp, len-(cp-body), &desc);
args = smartlist_new();
smartlist_split_string(args, body, " ",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- SMARTLIST_FOREACH(args, const char *, arg, {
+ SMARTLIST_FOREACH_BEGIN(args, const char *, arg) {
if (!strcasecmp(arg, "VERBOSE_NAMES"))
;
else if (!strcasecmp(arg, "EXTENDED_EVENTS"))
bad = 1;
break;
}
- });
+ } SMARTLIST_FOREACH_END(arg);
if (!bad) {
send_control_done(conn);
{
time_t now = time(NULL);
smartlist_t *conns = get_connection_array();
- SMARTLIST_FOREACH(conns, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(conns, connection_t *, conn) {
if (!conn->marked_for_close &&
conn->type == CONN_TYPE_CPUWORKER &&
conn->state == CPUWORKER_STATE_BUSY_ONION &&
num_cpuworkers--;
connection_mark_for_close(conn);
}
- });
+ } SMARTLIST_FOREACH_END(conn);
}
/** Try to tell a cpuworker to perform the public key operations necessary to
tor_assert(dir_purpose == DIR_PURPOSE_FETCH_STATUS_VOTE ||
dir_purpose == DIR_PURPOSE_FETCH_DETACHED_SIGNATURES);
- SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
- trusted_dir_server_t *, ds,
- {
+ SMARTLIST_FOREACH_BEGIN(router_get_trusted_dir_servers(),
+ trusted_dir_server_t *, ds) {
routerstatus_t *rs;
if (router_digest_is_me(ds->digest))
continue;
rs = &ds->fake_status;
directory_initiate_command_routerstatus(rs, dir_purpose, router_purpose,
0, resource, NULL, 0, 0);
- });
+ } SMARTLIST_FOREACH_END(ds);
}
/** Same as directory_initiate_command_routerstatus(), but accepts
char *authority_id_list;
smartlist_t *authority_digests = smartlist_new();
- SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
- trusted_dir_server_t *, ds,
- {
+ SMARTLIST_FOREACH_BEGIN(router_get_trusted_dir_servers(),
+ trusted_dir_server_t *, ds) {
char *hex;
if (!(ds->type & V3_DIRINFO))
continue;
base16_encode(hex, 2*CONDITIONAL_CONSENSUS_FPR_LEN+1,
ds->v3_identity_digest, CONDITIONAL_CONSENSUS_FPR_LEN);
smartlist_add(authority_digests, hex);
- });
+ } SMARTLIST_FOREACH_END(ds);
smartlist_sort(authority_digests, _compare_strs);
authority_id_list = smartlist_join_strings(authority_digests,
"+", 0, NULL);
{
if (status_code == 503)
return;
- SMARTLIST_FOREACH(failed, const char *, fp,
- {
+ SMARTLIST_FOREACH_BEGIN(failed, const char *, fp) {
char digest[DIGEST_LEN];
trusted_dir_server_t *dir;
if (base16_decode(digest, DIGEST_LEN, fp, strlen(fp))<0) {
if (dir)
download_status_failed(&dir->v2_ns_dl_status, status_code);
- });
+ } SMARTLIST_FOREACH_END(fp);
}
/** Schedule for when servers should download things in general. */
}
return; /* FFFF should implement for other-than-router-purpose someday */
}
- SMARTLIST_FOREACH(failed, const char *, cp,
- {
+ SMARTLIST_FOREACH_BEGIN(failed, const char *, cp) {
download_status_t *dls = NULL;
if (base16_decode(digest, DIGEST_LEN, cp, strlen(cp)) < 0) {
log_warn(LD_BUG, "Malformed fingerprint in list: %s", escaped(cp));
if (!dls || dls->n_download_failures >= MAX_ROUTERDESC_DOWNLOAD_FAILURES)
continue;
download_status_increment_failure(dls, status_code, cp, server, now);
- });
+ } SMARTLIST_FOREACH_END(cp);
/* No need to relaunch descriptor downloads here: we already do it
* every 10 or 60 seconds (FOO_DESCRIPTOR_RETRY_INTERVAL) in main.c. */
last_addr = 0;
addr_count = 0;
- SMARTLIST_FOREACH(routers_by_ip, routerinfo_t *, ri,
- {
+ SMARTLIST_FOREACH_BEGIN(routers_by_ip, routerinfo_t *, ri) {
if (last_addr != ri->addr) {
last_addr = ri->addr;
addr_count = 1;
addr_count > max_with_same_addr_on_authority)
digestmap_set(omit_as_sybil, ri->cache_info.identity_digest, ri);
}
- });
+ } SMARTLIST_FOREACH_END(ri);
smartlist_free(routers_by_ip);
return omit_as_sybil;
omit_as_sybil = get_possible_sybil_list(routers);
- SMARTLIST_FOREACH(routers, routerinfo_t *, ri, {
+ SMARTLIST_FOREACH_BEGIN(routers, routerinfo_t *, ri) {
if (ri->cache_info.published_on >= cutoff) {
routerstatus_t rs;
char *version = version_from_platform(ri->platform);
tor_free(version);
outp += strlen(outp);
}
- });
+ } SMARTLIST_FOREACH_END(ri);
if (tor_snprintf(outp, endp-outp, "directory-signature %s\n",
options->Nickname)<0) {
cached_v2_networkstatus = digestmap_new();
dirserv_get_networkstatus_v2_fingerprints(fingerprints, key);
- SMARTLIST_FOREACH(fingerprints, const char *, fp,
- {
+ SMARTLIST_FOREACH_BEGIN(fingerprints, const char *, fp) {
if (router_digest_is_me(fp) && should_generate_v2_networkstatus())
generate_v2_networkstatus_opinion();
cached = digestmap_get(cached_v2_networkstatus, fp);
log_info(LD_DIRSERV, "Don't know about any network status with "
"fingerprint '%s'", hexbuf);
}
- });
+ } SMARTLIST_FOREACH_END(fp);
SMARTLIST_FOREACH(fingerprints, char *, cp, tor_free(cp));
smartlist_free(fingerprints);
}
key += strlen("/tor/server/fp/");
dir_split_resource_into_fingerprints(key, digests, NULL,
DSR_HEX|DSR_SORT_UNIQ);
- SMARTLIST_FOREACH(digests, const char *, d,
- {
+ SMARTLIST_FOREACH_BEGIN(digests, const char *, d) {
if (router_digest_is_me(d)) {
/* make sure desc_routerinfo exists */
const routerinfo_t *ri = router_get_my_routerinfo();
if (ri && ri->cache_info.published_on > cutoff)
smartlist_add(descs_out, (void*) &(ri->cache_info));
}
- });
+ } SMARTLIST_FOREACH_END(d);
SMARTLIST_FOREACH(digests, char *, d, tor_free(d));
smartlist_free(digests);
} else {
dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff)
{
int found_any = 0;
- SMARTLIST_FOREACH(fps, char *, digest,
- {
+ SMARTLIST_FOREACH_BEGIN(fps, char *, digest) {
cached_dir_t *d = lookup_cached_dir_by_fp(digest);
if (!d)
continue;
tor_free(digest);
SMARTLIST_DEL_CURRENT(fps, digest);
}
- });
+ } SMARTLIST_FOREACH_END(digest);
return found_any;
}
dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src)
{
time_t publish_cutoff = time(NULL)-ROUTER_MAX_AGE_TO_PUBLISH;
- SMARTLIST_FOREACH(fps, const char *, fp, {
+ SMARTLIST_FOREACH_BEGIN(fps, const char *, fp) {
switch (spool_src)
{
case DIR_SPOOL_EXTRA_BY_DIGEST:
return 1;
break;
}
- });
+ } SMARTLIST_FOREACH_END(fp);
return 0;
}
{
char *cur = NULL;
int count = 0;
- SMARTLIST_FOREACH(in, char *, cp,
- {
+ SMARTLIST_FOREACH_BEGIN(in, char *, cp) {
if (cur && !strcmp(cp, cur)) {
++count;
} else {
cur = cp;
count = 1;
}
- });
+ } SMARTLIST_FOREACH_END(cp);
if (count > min)
smartlist_add(out, cur);
}
* date cannot tie, we use the descriptor with the smaller digest.
*/
smartlist_sort(votes, _compare_vote_rs);
- SMARTLIST_FOREACH(votes, vote_routerstatus_t *, rs,
- {
+ SMARTLIST_FOREACH_BEGIN(votes, vote_routerstatus_t *, rs) {
if (cur && !compare_vote_rs(cur, rs)) {
++cur_n;
} else {
cur_n = 1;
cur = rs;
}
- });
+ } SMARTLIST_FOREACH_END(rs);
if (cur_n > most_n ||
(cur && cur_n == most_n && cur->status.published_on > most_published)) {
chosen_named_idx = smartlist_string_pos(flags, "Named");
/* Build the flag index. */
- SMARTLIST_FOREACH(votes, networkstatus_t *, v,
- {
+ SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
flag_map[v_sl_idx] = tor_malloc_zero(
sizeof(int)*smartlist_len(v->known_flags));
- SMARTLIST_FOREACH(v->known_flags, const char *, fl,
- {
+ SMARTLIST_FOREACH_BEGIN(v->known_flags, const char *, fl) {
int p = smartlist_string_pos(flags, fl);
tor_assert(p >= 0);
flag_map[v_sl_idx][fl_sl_idx] = p;
named_flag[v_sl_idx] = fl_sl_idx;
if (!strcmp(fl, "Unnamed"))
unnamed_flag[v_sl_idx] = fl_sl_idx;
- });
+ } SMARTLIST_FOREACH_END(fl);
n_voter_flags[v_sl_idx] = smartlist_len(v->known_flags);
size[v_sl_idx] = smartlist_len(v->routerstatus_list);
- });
+ } SMARTLIST_FOREACH_END(v);
/* Named and Unnamed get treated specially */
if (consensus_method >= 2) {
- SMARTLIST_FOREACH(votes, networkstatus_t *, v,
- {
+ SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
uint64_t nf;
if (named_flag[v_sl_idx]<0)
continue;
nf = U64_LITERAL(1) << named_flag[v_sl_idx];
- SMARTLIST_FOREACH(v->routerstatus_list, vote_routerstatus_t *, rs,
- {
+ SMARTLIST_FOREACH_BEGIN(v->routerstatus_list,
+ vote_routerstatus_t *, rs) {
+
if ((rs->flags & nf) != 0) {
const char *d = strmap_get_lc(name_to_id_map, rs->status.nickname);
if (!d) {
/* It's already a conflict, or it's already this ID. */
}
}
- });
- });
- SMARTLIST_FOREACH(votes, networkstatus_t *, v,
- {
+ } SMARTLIST_FOREACH_END(rs);
+ } SMARTLIST_FOREACH_END(v);
+
+ SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) {
uint64_t uf;
if (unnamed_flag[v_sl_idx]<0)
continue;
uf = U64_LITERAL(1) << unnamed_flag[v_sl_idx];
- SMARTLIST_FOREACH(v->routerstatus_list, vote_routerstatus_t *, rs,
- {
+ SMARTLIST_FOREACH_BEGIN(v->routerstatus_list,
+ vote_routerstatus_t *, rs) {
if ((rs->flags & uf) != 0) {
const char *d = strmap_get_lc(name_to_id_map, rs->status.nickname);
if (d == conflict || d == unknown) {
/* It's mapped to a different name. */
}
}
- });
- });
+ } SMARTLIST_FOREACH_END(rs);
+ } SMARTLIST_FOREACH_END(v);
}
/* Now go through all the votes */
/* Set the flags. */
smartlist_add(chosen_flags, (char*)"s"); /* for the start of the line. */
- SMARTLIST_FOREACH(flags, const char *, fl,
- {
+ SMARTLIST_FOREACH_BEGIN(flags, const char *, fl) {
if (!strcmp(fl, "Named")) {
if (is_named)
smartlist_add(chosen_flags, (char*)fl);
is_bad_exit = 1;
}
}
- });
+ } SMARTLIST_FOREACH_END(fl);
/* Starting with consensus method 4 we do not list servers
* that are not running in a consensus. See Proposal 138 */
* that list previously */
const char *chosen_exitsummary = NULL;
smartlist_clear(exitsummaries);
- SMARTLIST_FOREACH(matching_descs, vote_routerstatus_t *, vsr, {
+ SMARTLIST_FOREACH_BEGIN(matching_descs, vote_routerstatus_t *, vsr) {
/* Check if the vote where this status comes from had the
* proper descriptor */
tor_assert(fast_memeq(rs_out.identity_digest,
exitsummary_disagreement = 1;
}
}
- });
+ } SMARTLIST_FOREACH_END(vsr);
if (exitsummary_disagreement) {
char id[HEX_DIGEST_LEN+1];
smartlist_t *missing_fps = smartlist_new();
char *resource;
- SMARTLIST_FOREACH(router_get_trusted_dir_servers(),
- trusted_dir_server_t *, ds,
- {
+ SMARTLIST_FOREACH_BEGIN(router_get_trusted_dir_servers(),
+ trusted_dir_server_t *, ds) {
if (!(ds->type & V3_DIRINFO))
continue;
if (!dirvote_get_vote(ds->v3_identity_digest,
DIGEST_LEN);
smartlist_add(missing_fps, cp);
}
- });
+ } SMARTLIST_FOREACH_END(ds);
if (!smartlist_len(missing_fps)) {
smartlist_free(missing_fps);
update_consensus_router_descriptor_downloads(time(NULL), 1, vote);
/* Now see whether we already have a vote from this authority. */
- SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v, {
+ SMARTLIST_FOREACH_BEGIN(pending_vote_list, pending_vote_t *, v) {
if (fast_memeq(v->vote->cert->cache_info.identity_digest,
vote->cert->cache_info.identity_digest,
DIGEST_LEN)) {
goto err;
}
}
- });
+ } SMARTLIST_FOREACH_END(v);
pending_vote = tor_malloc_zero(sizeof(pending_vote_t));
pending_vote->vote_body = new_cached_dir(tor_strndup(vote_body,
int n_sigs = 0;
/* we may have gotten signatures for this consensus before we built
* it ourself. Add them now. */
- SMARTLIST_FOREACH(pending_consensus_signature_list, char *, sig,
- {
+ SMARTLIST_FOREACH_BEGIN(pending_consensus_signature_list, char *, sig) {
const char *msg = NULL;
int r = dirvote_add_signatures_to_all_pending_consensuses(sig,
"pending", &msg);
"Could not add queued signature to new consensus: %s",
msg);
tor_free(sig);
- });
+ } SMARTLIST_FOREACH_END(sig);
if (n_sigs)
log_notice(LD_DIR, "Added %d pending signatures while building "
"consensus.", n_sigs);
return NULL;
entries = smartlist_new();
- SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, {
+ SMARTLIST_FOREACH_BEGIN(geoip_countries, geoip_country_t *, c) {
uint32_t tot = 0;
c_hist_t *ent;
tot = (action == GEOIP_CLIENT_NETWORKSTATUS) ?
strlcpy(ent->country, c->countrycode, sizeof(ent->country));
ent->total = round_to_next_multiple_of(tot, granularity);
smartlist_add(entries, ent);
- });
+ } SMARTLIST_FOREACH_END(c);
smartlist_sort(entries, _c_hist_compare);
strings = smartlist_new();
log(severity, LD_GENERAL, "Dumping stats:");
- SMARTLIST_FOREACH(connection_array, connection_t *, conn,
- {
+ SMARTLIST_FOREACH_BEGIN(connection_array, connection_t *, conn) {
int i = conn_sl_idx;
log(severity, LD_GENERAL,
"Conn %d (socket %d) type %d (%s), state %d (%s), created %d secs ago",
}
circuit_dump_by_conn(conn, severity); /* dump info about all the circuits
* using this conn */
- });
+ } SMARTLIST_FOREACH_END(conn);
log(severity, LD_NET,
"Cells processed: "U64_FORMAT" padding\n"
" "U64_FORMAT" create\n"
return 0;
}
tor_free(filename);
- SMARTLIST_FOREACH(entries, const char *, fn, {
+ SMARTLIST_FOREACH_BEGIN(entries, const char *, fn) {
char buf[DIGEST_LEN];
if (maybe_delete) {
filename = get_datadir_fname2("cached-status", fn);
tor_free(s);
}
tor_free(filename);
- });
+ } SMARTLIST_FOREACH_END(fn);
SMARTLIST_FOREACH(entries, char *, fn, tor_free(fn));
smartlist_free(entries);
networkstatus_v2_list_clean(time(NULL));
{
time_t live_until = ns->published_on + V2_NETWORKSTATUS_ROUTER_LIFETIME;
- SMARTLIST_FOREACH(ns->entries, routerstatus_t *, rs,
- {
+ SMARTLIST_FOREACH_BEGIN(ns->entries, routerstatus_t *, rs) {
signed_descriptor_t *sd =
router_get_by_descriptor_digest(rs->descriptor_digest);
if (sd) {
} else {
rs->need_to_mirror = 1;
}
- });
+ } SMARTLIST_FOREACH_END(rs);
}
log_info(LD_DIR, "Setting networkstatus %s %s (published %s)",
named_server_map = strmap_new();
strmap_free(unnamed_server_map, NULL);
unnamed_server_map = strmap_new();
- SMARTLIST_FOREACH(current_consensus->routerstatus_list,
- const routerstatus_t *, rs,
- {
+ SMARTLIST_FOREACH_BEGIN(current_consensus->routerstatus_list,
+ const routerstatus_t *, rs) {
if (rs->is_named) {
strmap_set_lc(named_server_map, rs->nickname,
tor_memdup(rs->identity_digest, DIGEST_LEN));
if (rs->is_unnamed) {
strmap_set_lc(unnamed_server_map, rs->nickname, (void*)1);
}
- });
+ } SMARTLIST_FOREACH_END(rs);
}
/** Given a list <b>routers</b> of routerinfo_t *, update each status field
} SMARTLIST_FOREACH_JOIN_END(rs, router);
/* Now update last_listed_as_valid_until from v2 networkstatuses. */
- SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns, {
+ SMARTLIST_FOREACH_BEGIN(networkstatus_v2_list, networkstatus_v2_t *, ns) {
time_t live_until = ns->published_on + V2_NETWORKSTATUS_ROUTER_LIFETIME;
SMARTLIST_FOREACH_JOIN(ns->entries, const routerstatus_t *, rs,
routers, routerinfo_t *, ri,
ri->cache_info.last_listed_as_valid_until = live_until;
}
} SMARTLIST_FOREACH_JOIN_END(rs, ri);
- });
+ } SMARTLIST_FOREACH_END(ns);
router_dir_info_changed();
}
}
statuses = smartlist_new();
- SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
+ SMARTLIST_FOREACH_BEGIN(rl->routers, routerinfo_t *, ri) {
node_t *node = node_get_mutable_by_id(ri->cache_info.identity_digest);
if (!node)
continue;
/* then generate and write out status lines for each of them */
set_routerstatus_from_routerinfo(&rs, node, ri, now, 0, 0, 0, 0);
smartlist_add(statuses, networkstatus_getinfo_helper_single(&rs));
- });
+ } SMARTLIST_FOREACH_END(ri);
answer = smartlist_join_strings(statuses, "", 0, NULL);
SMARTLIST_FOREACH(statuses, char *, cp, tor_free(cp));
tmp = smartlist_new();
- SMARTLIST_FOREACH(*policy, addr_policy_t *, p,
- {
+ SMARTLIST_FOREACH_BEGIN(*policy, addr_policy_t *, p) {
if (! p->is_private) {
smartlist_add(tmp, p);
continue;
smartlist_add(tmp, addr_policy_get_canonical_entry(&newpolicy));
}
addr_policy_free(p);
- });
+ } SMARTLIST_FOREACH_END(p);
smartlist_free(*policy);
*policy = tmp;
for (; cfg; cfg = cfg->next) {
smartlist_split_string(entries, cfg->value, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
- SMARTLIST_FOREACH(entries, const char *, ent,
- {
+ SMARTLIST_FOREACH_BEGIN(entries, const char *, ent) {
log_debug(LD_CONFIG,"Adding new entry '%s'",ent);
item = router_parse_addr_policy_item_from_string(ent, assume_action);
if (item) {
log_warn(LD_CONFIG,"Malformed policy '%s'.", ent);
r = -1;
}
- });
+ } SMARTLIST_FOREACH_END(ent);
SMARTLIST_FOREACH(entries, char *, ent, tor_free(ent));
smartlist_clear(entries);
}
char subnet_status[256];
memset(subnet_status, 0, sizeof(subnet_status));
- SMARTLIST_FOREACH(policy, addr_policy_t *, p, {
+ SMARTLIST_FOREACH_BEGIN(policy, addr_policy_t *, p) {
if (tor_addr_family(&p->addr) != AF_INET)
continue; /* IPv4 only for now */
if (p->prt_min > port || p->prt_max < port)
subnet_status[i] = 1;
}
}
- });
+ } SMARTLIST_FOREACH_END(p);
return 0;
}
smartlist_sort(signed_descriptors, _compare_signed_descriptors_by_age);
/* Now, add the appropriate members to chunk_list */
- SMARTLIST_FOREACH(signed_descriptors, signed_descriptor_t *, sd,
- {
+ SMARTLIST_FOREACH_BEGIN(signed_descriptors, signed_descriptor_t *, sd) {
sized_chunk_t *c;
const char *body = signed_descriptor_get_body_impl(sd, 1);
if (!body) {
c->len = sd->signed_descriptor_len + sd->annotations_len;
total_expected_len += c->len;
smartlist_add(chunk_list, c);
- });
+ } SMARTLIST_FOREACH_END(sd);
if (write_chunks_to_file(fname_tmp, chunk_list, 1)<0) {
log_warn(LD_FS, "Error writing router store to disk.");
log_info(LD_DIR, "Reconstructing pointers into cache");
offset = 0;
- SMARTLIST_FOREACH(signed_descriptors, signed_descriptor_t *, sd,
- {
+ SMARTLIST_FOREACH_BEGIN(signed_descriptors, signed_descriptor_t *, sd) {
if (sd->do_not_cache)
continue;
sd->saved_location = SAVED_IN_CACHE;
}
offset += sd->signed_descriptor_len + sd->annotations_len;
signed_descriptor_get_body(sd); /* reconstruct and assert */
- });
+ } SMARTLIST_FOREACH_END(sd);
tor_free(fname);
fname = get_datadir_fname_suffix(store->fname_base, ".new");
node->is_running = 1;
});
if (trusted_dir_servers) {
- SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, dir,
- {
+ SMARTLIST_FOREACH_BEGIN(trusted_dir_servers, trusted_dir_server_t *, dir) {
routerstatus_t *rs;
dir->is_running = 1;
download_status_reset(&dir->v2_ns_dl_status);
rs->last_dir_503_at = 0;
control_event_networkstatus_changed_single(rs);
}
- });
+ } SMARTLIST_FOREACH_END(dir);
}
router_dir_info_changed();
}
cutoff = now - OLD_ROUTER_DESC_MAX_AGE;
/* Build a list of all the descriptors that _anybody_ lists. */
if (caches && networkstatus_v2_list) {
- SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
- {
+ SMARTLIST_FOREACH_BEGIN(networkstatus_v2_list, networkstatus_v2_t *, ns) {
/* XXXX The inner loop here gets pretty expensive, and actually shows up
* on some profiles. It may be the reason digestmap_set shows up in
* profiles too. If instead we kept a per-descriptor digest count of
* improvement, possibly 1-4% if it also removes digestmap_set from the
* profile. Not worth it for 0.1.2.x, though. The new directory
* system will obsolete this whole thing in 0.2.0.x. */
- SMARTLIST_FOREACH(ns->entries, routerstatus_t *, rs,
+ SMARTLIST_FOREACH_BEGIN(ns->entries, routerstatus_t *, rs) {
if (rs->published_on >= cutoff)
- digestset_add(retain, rs->descriptor_digest));
- });
+ digestset_add(retain, rs->descriptor_digest);
+ } SMARTLIST_FOREACH_END(rs);
+ } SMARTLIST_FOREACH_END(ns);
}
/* Retain anything listed in the consensus. */
log_info(LD_DIR, "%d elements to add", smartlist_len(extrainfo_list));
- SMARTLIST_FOREACH(extrainfo_list, extrainfo_t *, ei, {
+ SMARTLIST_FOREACH_BEGIN(extrainfo_list, extrainfo_t *, ei) {
was_router_added_t added =
router_add_extrainfo_to_routerlist(ei, &msg, from_cache, !from_cache);
if (WRA_WAS_ADDED(added) && requested_fingerprints) {
* all the extrainfos we want, and we never actually act on them
* inside Tor, this should be harmless. */
}
- });
+ } SMARTLIST_FOREACH_END(ei);
routerlist_assert_ok(routerlist);
router_rebuild_store(0, &router_get_routerlist()->extrainfo_store);
* descriptor from the corresponding authority.
*/
n_download = 0;
- SMARTLIST_FOREACH(networkstatus_v2_list, networkstatus_v2_t *, ns,
- {
+ SMARTLIST_FOREACH_BEGIN(networkstatus_v2_list, networkstatus_v2_t *, ns) {
trusted_dir_server_t *ds;
smartlist_t *dl;
dl = downloadable[ns_sl_idx] = smartlist_new();
if (ds && !ds->is_running)
continue;
- SMARTLIST_FOREACH(ns->entries, routerstatus_t * , rs,
- {
+ SMARTLIST_FOREACH_BEGIN(ns->entries, routerstatus_t * , rs) {
if (!rs->need_to_mirror)
continue;
if (router_get_by_descriptor_digest(rs->descriptor_digest)) {
smartlist_add(dl, rs->descriptor_digest);
++n_download;
}
- });
- });
+ } SMARTLIST_FOREACH_END(rs);
+ } SMARTLIST_FOREACH_END(ns);
/* At random, assign descriptors to authorities such that:
* - if d is a member of some downloadable[x], d is a member of some
log_info(LD_DIR, "%d router descriptors listed in consensus are "
"currently in old_routers; making them current.",
smartlist_len(no_longer_old));
- SMARTLIST_FOREACH(no_longer_old, signed_descriptor_t *, sd, {
+ SMARTLIST_FOREACH_BEGIN(no_longer_old, signed_descriptor_t *, sd) {
const char *msg;
was_router_added_t r;
routerinfo_t *ri = routerlist_reparse_old(rl, sd);
log_warn(LD_DIR, "Couldn't add re-parsed router: %s",
msg?msg:"???");
}
- });
+ } SMARTLIST_FOREACH_END(sd);
routerlist_assert_ok(rl);
}
signed_descriptor_t *sd2;
if (!rl)
return;
- SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
- {
+ SMARTLIST_FOREACH_BEGIN(rl->routers, routerinfo_t *, r) {
r2 = rimap_get(rl->identity_map, r->cache_info.identity_digest);
tor_assert(r == r2);
sd2 = sdmap_get(rl->desc_digest_map,
tor_assert(sd3 == &(r->cache_info));
}
*/
- });
- SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd,
- {
+ } SMARTLIST_FOREACH_END(r);
+ SMARTLIST_FOREACH_BEGIN(rl->old_routers, signed_descriptor_t *, sd) {
r2 = rimap_get(rl->identity_map, sd->identity_digest);
tor_assert(sd != &(r2->cache_info));
sd2 = sdmap_get(rl->desc_digest_map, sd->signed_descriptor_digest);
tor_assert(sd3 == sd);
}
*/
- });
+ } SMARTLIST_FOREACH_END(sd);
RIMAP_FOREACH(rl->identity_map, d, r) {
tor_assert(tor_memeq(r->cache_info.identity_digest, d, DIGEST_LEN));
goto done;
}
- SMARTLIST_FOREACH(version_sl, const char *, cp, {
+ SMARTLIST_FOREACH_BEGIN(version_sl, const char *, cp) {
if (!strcmpstart(cp, "Tor "))
cp += 4;
found_older = 1;
}
}
- });
+ } SMARTLIST_FOREACH_END(cp);
/* We didn't find the listed version. Is it new or old? */
if (found_any_in_series && !found_newer_in_series && found_newer) {
elements = tor_listdir(dir);
if (elements) {
- SMARTLIST_FOREACH(elements, const char *, cp,
- {
+ SMARTLIST_FOREACH_BEGIN(elements, const char *, cp) {
char *tmp = NULL;
tor_asprintf(&tmp, "%s"PATH_SEPARATOR"%s", dir, cp);
if (0 == stat(tmp,&st) && (st.st_mode & S_IFDIR)) {
}
}
tor_free(tmp);
- });
+ } SMARTLIST_FOREACH_END(cp);
SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
smartlist_free(elements);
}
j = 0;
log_info(LD_GENERAL, "Splitting test %d of length %d",
i, tests[i].orig_length);
- SMARTLIST_FOREACH(sl, const char *, line,
- {
+ SMARTLIST_FOREACH_BEGIN(sl, const char *, line) {
/* Check we have not got too many lines */
test_assert(j < MAX_SPLIT_LINE_COUNT);
/* Check that there actually should be a line here */
/* Check that the line is as expected */
test_streq(line, tests[i].split_line[j]);
j++;
- });
+ } SMARTLIST_FOREACH_END(line);
/* Check that we didn't miss some lines */
test_eq_ptr(NULL, tests[i].split_line[j]);
tor_free(orig_line);