mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Move published_on from routerstatus_t to vote_routerstatus_t.
Nothing breaks here, since all non-voting users of routerstatus_t.published_on have been adjusted or removed in previous commits. We have to expand the API of routerstatus_format_entry() a bit, though, so that it can always get a published time as argument, since it can't get it from the routerstatus any more. This should have no effect on voter behavior.
This commit is contained in:
parent
a7fb5563bc
commit
1d2c918dfd
12 changed files with 52 additions and 56 deletions
|
@ -390,7 +390,8 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
|
||||||
rsf = routerstatus_format_entry(&vrs->status,
|
rsf = routerstatus_format_entry(&vrs->status,
|
||||||
vrs->version, vrs->protocols,
|
vrs->version, vrs->protocols,
|
||||||
NS_V3_VOTE,
|
NS_V3_VOTE,
|
||||||
vrs);
|
vrs,
|
||||||
|
-1);
|
||||||
if (rsf)
|
if (rsf)
|
||||||
smartlist_add(chunks, rsf);
|
smartlist_add(chunks, rsf);
|
||||||
|
|
||||||
|
@ -618,8 +619,8 @@ compare_vote_rs(const vote_routerstatus_t *a, const vote_routerstatus_t *b)
|
||||||
* the descriptor digests matched, so somebody is making SHA1 collisions.
|
* the descriptor digests matched, so somebody is making SHA1 collisions.
|
||||||
*/
|
*/
|
||||||
#define CMP_FIELD(utype, itype, field) do { \
|
#define CMP_FIELD(utype, itype, field) do { \
|
||||||
utype aval = (utype) (itype) a->status.field; \
|
utype aval = (utype) (itype) a->field; \
|
||||||
utype bval = (utype) (itype) b->status.field; \
|
utype bval = (utype) (itype) b->field; \
|
||||||
utype u = bval - aval; \
|
utype u = bval - aval; \
|
||||||
itype r2 = (itype) u; \
|
itype r2 = (itype) u; \
|
||||||
if (r2 < 0) { \
|
if (r2 < 0) { \
|
||||||
|
@ -638,8 +639,8 @@ compare_vote_rs(const vote_routerstatus_t *a, const vote_routerstatus_t *b)
|
||||||
CMP_EXACT))) {
|
CMP_EXACT))) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
CMP_FIELD(unsigned, int, ipv4_orport);
|
CMP_FIELD(unsigned, int, status.ipv4_orport);
|
||||||
CMP_FIELD(unsigned, int, ipv4_dirport);
|
CMP_FIELD(unsigned, int, status.ipv4_dirport);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -692,10 +693,10 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
|
||||||
} else {
|
} else {
|
||||||
if (cur && (cur_n > most_n ||
|
if (cur && (cur_n > most_n ||
|
||||||
(cur_n == most_n &&
|
(cur_n == most_n &&
|
||||||
cur->status.published_on > most_published))) {
|
cur->published_on > most_published))) {
|
||||||
most = cur;
|
most = cur;
|
||||||
most_n = cur_n;
|
most_n = cur_n;
|
||||||
most_published = cur->status.published_on;
|
most_published = cur->published_on;
|
||||||
}
|
}
|
||||||
cur_n = 1;
|
cur_n = 1;
|
||||||
cur = rs;
|
cur = rs;
|
||||||
|
@ -703,7 +704,7 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
|
||||||
} SMARTLIST_FOREACH_END(rs);
|
} SMARTLIST_FOREACH_END(rs);
|
||||||
|
|
||||||
if (cur_n > most_n ||
|
if (cur_n > most_n ||
|
||||||
(cur && cur_n == most_n && cur->status.published_on > most_published)) {
|
(cur && cur_n == most_n && cur->published_on > most_published)) {
|
||||||
most = cur;
|
most = cur;
|
||||||
// most_n = cur_n; // unused after this point.
|
// most_n = cur_n; // unused after this point.
|
||||||
// most_published = cur->status.published_on; // unused after this point.
|
// most_published = cur->status.published_on; // unused after this point.
|
||||||
|
@ -2047,7 +2048,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
|
||||||
memcpy(rs_out.descriptor_digest, rs->status.descriptor_digest,
|
memcpy(rs_out.descriptor_digest, rs->status.descriptor_digest,
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
tor_addr_copy(&rs_out.ipv4_addr, &rs->status.ipv4_addr);
|
tor_addr_copy(&rs_out.ipv4_addr, &rs->status.ipv4_addr);
|
||||||
rs_out.published_on = rs->status.published_on;
|
time_t published_on = rs->published_on;
|
||||||
rs_out.ipv4_dirport = rs->status.ipv4_dirport;
|
rs_out.ipv4_dirport = rs->status.ipv4_dirport;
|
||||||
rs_out.ipv4_orport = rs->status.ipv4_orport;
|
rs_out.ipv4_orport = rs->status.ipv4_orport;
|
||||||
tor_addr_copy(&rs_out.ipv6_addr, &alt_orport.addr);
|
tor_addr_copy(&rs_out.ipv6_addr, &alt_orport.addr);
|
||||||
|
@ -2276,7 +2277,7 @@ networkstatus_compute_consensus(smartlist_t *votes,
|
||||||
/* Okay!! Now we can write the descriptor... */
|
/* Okay!! Now we can write the descriptor... */
|
||||||
/* First line goes into "buf". */
|
/* First line goes into "buf". */
|
||||||
buf = routerstatus_format_entry(&rs_out, NULL, NULL,
|
buf = routerstatus_format_entry(&rs_out, NULL, NULL,
|
||||||
rs_format, NULL);
|
rs_format, NULL, published_on);
|
||||||
if (buf)
|
if (buf)
|
||||||
smartlist_add(chunks, buf);
|
smartlist_add(chunks, buf);
|
||||||
}
|
}
|
||||||
|
@ -4745,6 +4746,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
|
||||||
dirauth_set_routerstatus_from_routerinfo(rs, node, ri, now,
|
dirauth_set_routerstatus_from_routerinfo(rs, node, ri, now,
|
||||||
list_bad_exits,
|
list_bad_exits,
|
||||||
list_middle_only);
|
list_middle_only);
|
||||||
|
vrs->published_on = ri->cache_info.published_on;
|
||||||
|
|
||||||
if (ri->cache_info.signing_key_cert) {
|
if (ri->cache_info.signing_key_cert) {
|
||||||
memcpy(vrs->ed25519_id,
|
memcpy(vrs->ed25519_id,
|
||||||
|
|
|
@ -371,14 +371,17 @@ routerstatus_parse_entry_from_string(memarea_t *area,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t published_on;
|
||||||
if (tor_snprintf(timebuf, sizeof(timebuf), "%s %s",
|
if (tor_snprintf(timebuf, sizeof(timebuf), "%s %s",
|
||||||
tok->args[3+offset], tok->args[4+offset]) < 0 ||
|
tok->args[3+offset], tok->args[4+offset]) < 0 ||
|
||||||
parse_iso_time(timebuf, &rs->published_on)<0) {
|
parse_iso_time(timebuf, &published_on)<0) {
|
||||||
log_warn(LD_DIR, "Error parsing time '%s %s' [%d %d]",
|
log_warn(LD_DIR, "Error parsing time '%s %s' [%d %d]",
|
||||||
tok->args[3+offset], tok->args[4+offset],
|
tok->args[3+offset], tok->args[4+offset],
|
||||||
offset, (int)flav);
|
offset, (int)flav);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
if (vote_rs)
|
||||||
|
vote_rs->published_on = published_on;
|
||||||
|
|
||||||
if (tor_inet_aton(tok->args[5+offset], &in) == 0) {
|
if (tor_inet_aton(tok->args[5+offset], &in) == 0) {
|
||||||
log_warn(LD_DIR, "Error parsing router address in network-status %s",
|
log_warn(LD_DIR, "Error parsing router address in network-status %s",
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
/** Helper: write the router-status information in <b>rs</b> into a newly
|
/** Helper: write the router-status information in <b>rs</b> into a newly
|
||||||
* allocated character buffer. Use the same format as in network-status
|
* allocated character buffer. Use the same format as in network-status
|
||||||
* documents. If <b>version</b> is non-NULL, add a "v" line for the platform.
|
* documents. If <b>version</b> is non-NULL, add a "v" line for the platform.
|
||||||
|
* If <b>declared_publish_time</b> is nonnegative, we declare it as the
|
||||||
|
* publication time. Otherwise we look for a publication time in <b>vrs</b>,
|
||||||
|
* and fall back to a default (not useful) publication time.
|
||||||
*
|
*
|
||||||
* Return 0 on success, -1 on failure.
|
* Return 0 on success, -1 on failure.
|
||||||
*
|
*
|
||||||
|
@ -38,12 +41,14 @@
|
||||||
* NS_V3_VOTE - Output a complete V3 NS vote. If <b>vrs</b> is present,
|
* NS_V3_VOTE - Output a complete V3 NS vote. If <b>vrs</b> is present,
|
||||||
* it contains additional information for the vote.
|
* it contains additional information for the vote.
|
||||||
* NS_CONTROL_PORT - Output a NS document for the control port.
|
* NS_CONTROL_PORT - Output a NS document for the control port.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
routerstatus_format_entry(const routerstatus_t *rs, const char *version,
|
routerstatus_format_entry(const routerstatus_t *rs, const char *version,
|
||||||
const char *protocols,
|
const char *protocols,
|
||||||
routerstatus_format_type_t format,
|
routerstatus_format_type_t format,
|
||||||
const vote_routerstatus_t *vrs)
|
const vote_routerstatus_t *vrs,
|
||||||
|
time_t declared_publish_time)
|
||||||
{
|
{
|
||||||
char *summary;
|
char *summary;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
@ -53,11 +58,18 @@ routerstatus_format_entry(const routerstatus_t *rs, const char *version,
|
||||||
char digest64[BASE64_DIGEST_LEN+1];
|
char digest64[BASE64_DIGEST_LEN+1];
|
||||||
smartlist_t *chunks = smartlist_new();
|
smartlist_t *chunks = smartlist_new();
|
||||||
|
|
||||||
|
if (declared_publish_time != -1) {
|
||||||
|
format_iso_time(published, declared_publish_time);
|
||||||
|
} else if (vrs) {
|
||||||
|
format_iso_time(published, vrs->published_on);
|
||||||
|
} else {
|
||||||
|
strlcpy(published, "2038-01-01 00:00:00", sizeof(published));
|
||||||
|
}
|
||||||
|
|
||||||
const char *ip_str = fmt_addr(&rs->ipv4_addr);
|
const char *ip_str = fmt_addr(&rs->ipv4_addr);
|
||||||
if (ip_str[0] == '\0')
|
if (ip_str[0] == '\0')
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
format_iso_time(published, rs->published_on);
|
|
||||||
digest_to_base64(identity64, rs->identity_digest);
|
digest_to_base64(identity64, rs->identity_digest);
|
||||||
digest_to_base64(digest64, rs->descriptor_digest);
|
digest_to_base64(digest64, rs->descriptor_digest);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ char *routerstatus_format_entry(
|
||||||
const char *version,
|
const char *version,
|
||||||
const char *protocols,
|
const char *protocols,
|
||||||
routerstatus_format_type_t format,
|
routerstatus_format_type_t format,
|
||||||
const vote_routerstatus_t *vrs);
|
const vote_routerstatus_t *vrs,
|
||||||
|
time_t declared_publish_time);
|
||||||
|
|
||||||
#endif /* !defined(TOR_FMT_ROUTERSTATUS_H) */
|
#endif /* !defined(TOR_FMT_ROUTERSTATUS_H) */
|
||||||
|
|
|
@ -2364,7 +2364,7 @@ char *
|
||||||
networkstatus_getinfo_helper_single(const routerstatus_t *rs)
|
networkstatus_getinfo_helper_single(const routerstatus_t *rs)
|
||||||
{
|
{
|
||||||
return routerstatus_format_entry(rs, NULL, NULL, NS_CONTROL_PORT,
|
return routerstatus_format_entry(rs, NULL, NULL, NS_CONTROL_PORT,
|
||||||
NULL);
|
NULL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2396,7 +2396,6 @@ set_routerstatus_from_routerinfo(routerstatus_t *rs,
|
||||||
rs->is_hs_dir = node->is_hs_dir;
|
rs->is_hs_dir = node->is_hs_dir;
|
||||||
rs->is_named = rs->is_unnamed = 0;
|
rs->is_named = rs->is_unnamed = 0;
|
||||||
|
|
||||||
rs->published_on = ri->cache_info.published_on;
|
|
||||||
memcpy(rs->identity_digest, node->identity, DIGEST_LEN);
|
memcpy(rs->identity_digest, node->identity, DIGEST_LEN);
|
||||||
memcpy(rs->descriptor_digest, ri->cache_info.signed_descriptor_digest,
|
memcpy(rs->descriptor_digest, ri->cache_info.signed_descriptor_digest,
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
|
|
|
@ -21,7 +21,6 @@ struct routerstatus_t {
|
||||||
* routerstatus_has_visibly_changed and the printing function
|
* routerstatus_has_visibly_changed and the printing function
|
||||||
* routerstatus_format_entry in NS_CONTROL_PORT mode.
|
* routerstatus_format_entry in NS_CONTROL_PORT mode.
|
||||||
*/
|
*/
|
||||||
time_t published_on; /**< When was this router published? */
|
|
||||||
char nickname[MAX_NICKNAME_LEN+1]; /**< The nickname this router says it
|
char nickname[MAX_NICKNAME_LEN+1]; /**< The nickname this router says it
|
||||||
* has. */
|
* has. */
|
||||||
char identity_digest[DIGEST_LEN]; /**< Digest of the router's identity
|
char identity_digest[DIGEST_LEN]; /**< Digest of the router's identity
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
struct vote_routerstatus_t {
|
struct vote_routerstatus_t {
|
||||||
routerstatus_t status; /**< Underlying 'status' object for this router.
|
routerstatus_t status; /**< Underlying 'status' object for this router.
|
||||||
* Flags are redundant. */
|
* Flags are redundant. */
|
||||||
|
time_t published_on; /**< When was this router published? */
|
||||||
/** How many known-flags are allowed in a vote? This is the width of
|
/** How many known-flags are allowed in a vote? This is the width of
|
||||||
* the flags field of vote_routerstatus_t */
|
* the flags field of vote_routerstatus_t */
|
||||||
#define MAX_KNOWN_FLAGS_IN_VOTE 64
|
#define MAX_KNOWN_FLAGS_IN_VOTE 64
|
||||||
|
|
|
@ -2971,7 +2971,7 @@ test_vrs_for_v3ns(vote_routerstatus_t *vrs, int voter, time_t now)
|
||||||
(voter == 1)) {
|
(voter == 1)) {
|
||||||
/* Check the first routerstatus. */
|
/* Check the first routerstatus. */
|
||||||
tt_str_op(vrs->version,OP_EQ, "0.1.2.14");
|
tt_str_op(vrs->version,OP_EQ, "0.1.2.14");
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1500);
|
tt_int_op(vrs->published_on,OP_EQ, now-1500);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router2");
|
tt_str_op(rs->nickname,OP_EQ, "router2");
|
||||||
tt_mem_op(rs->identity_digest,OP_EQ,
|
tt_mem_op(rs->identity_digest,OP_EQ,
|
||||||
"\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3"
|
"\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3"
|
||||||
|
@ -2996,7 +2996,7 @@ test_vrs_for_v3ns(vote_routerstatus_t *vrs, int voter, time_t now)
|
||||||
if (voter == 1) {
|
if (voter == 1) {
|
||||||
/* Check the second routerstatus. */
|
/* Check the second routerstatus. */
|
||||||
tt_str_op(vrs->version,OP_EQ, "0.2.0.5");
|
tt_str_op(vrs->version,OP_EQ, "0.2.0.5");
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1000);
|
tt_int_op(vrs->published_on,OP_EQ, now-1000);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router1");
|
tt_str_op(rs->nickname,OP_EQ, "router1");
|
||||||
}
|
}
|
||||||
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
||||||
|
@ -3057,6 +3057,7 @@ test_consensus_for_v3ns(networkstatus_t *con, time_t now)
|
||||||
static void
|
static void
|
||||||
test_routerstatus_for_v3ns(routerstatus_t *rs, time_t now)
|
test_routerstatus_for_v3ns(routerstatus_t *rs, time_t now)
|
||||||
{
|
{
|
||||||
|
(void)now;
|
||||||
tor_addr_t addr_ipv6;
|
tor_addr_t addr_ipv6;
|
||||||
|
|
||||||
tt_assert(rs);
|
tt_assert(rs);
|
||||||
|
@ -3093,7 +3094,6 @@ test_routerstatus_for_v3ns(routerstatus_t *rs, time_t now)
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router1");
|
tt_str_op(rs->nickname,OP_EQ, "router1");
|
||||||
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1000);
|
|
||||||
tt_assert(tor_addr_eq_ipv4h(&rs->ipv4_addr, 0x99009901));
|
tt_assert(tor_addr_eq_ipv4h(&rs->ipv4_addr, 0x99009901));
|
||||||
tt_int_op(rs->ipv4_orport,OP_EQ, 443);
|
tt_int_op(rs->ipv4_orport,OP_EQ, 443);
|
||||||
tt_int_op(rs->ipv4_dirport,OP_EQ, 0);
|
tt_int_op(rs->ipv4_dirport,OP_EQ, 0);
|
||||||
|
@ -3968,7 +3968,7 @@ gen_routerstatus_for_umbw(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.2.14");
|
vrs->version = tor_strdup("0.1.2.14");
|
||||||
rs->published_on = now-1500;
|
vrs->published_on = now-1500;
|
||||||
strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, 3, DIGEST_LEN);
|
memset(rs->identity_digest, 3, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, 78, DIGEST_LEN);
|
memset(rs->descriptor_digest, 78, DIGEST_LEN);
|
||||||
|
@ -3993,7 +3993,7 @@ gen_routerstatus_for_umbw(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.2.0.5");
|
vrs->version = tor_strdup("0.2.0.5");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, 5, DIGEST_LEN);
|
memset(rs->identity_digest, 5, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, 77, DIGEST_LEN);
|
memset(rs->descriptor_digest, 77, DIGEST_LEN);
|
||||||
|
@ -4020,7 +4020,7 @@ gen_routerstatus_for_umbw(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.0.3");
|
vrs->version = tor_strdup("0.1.0.3");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router3", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router3", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, 0x33, DIGEST_LEN);
|
memset(rs->identity_digest, 0x33, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, 79, DIGEST_LEN);
|
memset(rs->descriptor_digest, 79, DIGEST_LEN);
|
||||||
|
@ -4046,7 +4046,7 @@ gen_routerstatus_for_umbw(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.6.3");
|
vrs->version = tor_strdup("0.1.6.3");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router4", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router4", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, 0x34, DIGEST_LEN);
|
memset(rs->identity_digest, 0x34, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, 47, DIGEST_LEN);
|
memset(rs->descriptor_digest, 47, DIGEST_LEN);
|
||||||
|
@ -4146,7 +4146,7 @@ test_vrs_for_umbw(vote_routerstatus_t *vrs, int voter, time_t now)
|
||||||
* cutoff.
|
* cutoff.
|
||||||
*/
|
*/
|
||||||
tt_str_op(vrs->version,OP_EQ, "0.1.2.14");
|
tt_str_op(vrs->version,OP_EQ, "0.1.2.14");
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1500);
|
tt_int_op(vrs->published_on,OP_EQ, now-1500);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router2");
|
tt_str_op(rs->nickname,OP_EQ, "router2");
|
||||||
tt_mem_op(rs->identity_digest,OP_EQ,
|
tt_mem_op(rs->identity_digest,OP_EQ,
|
||||||
"\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3"
|
"\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3"
|
||||||
|
@ -4170,7 +4170,7 @@ test_vrs_for_umbw(vote_routerstatus_t *vrs, int voter, time_t now)
|
||||||
* cutoff.
|
* cutoff.
|
||||||
*/
|
*/
|
||||||
tt_str_op(vrs->version,OP_EQ, "0.2.0.5");
|
tt_str_op(vrs->version,OP_EQ, "0.2.0.5");
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1000);
|
tt_int_op(vrs->published_on,OP_EQ, now-1000);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router1");
|
tt_str_op(rs->nickname,OP_EQ, "router1");
|
||||||
tt_mem_op(rs->identity_digest,OP_EQ,
|
tt_mem_op(rs->identity_digest,OP_EQ,
|
||||||
"\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5"
|
"\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5"
|
||||||
|
@ -4245,6 +4245,7 @@ test_consensus_for_umbw(networkstatus_t *con, time_t now)
|
||||||
static void
|
static void
|
||||||
test_routerstatus_for_umbw(routerstatus_t *rs, time_t now)
|
test_routerstatus_for_umbw(routerstatus_t *rs, time_t now)
|
||||||
{
|
{
|
||||||
|
(void)now;
|
||||||
tor_addr_t addr_ipv6;
|
tor_addr_t addr_ipv6;
|
||||||
uint32_t max_unmeasured_bw_kb = (alternate_clip_bw > 0) ?
|
uint32_t max_unmeasured_bw_kb = (alternate_clip_bw > 0) ?
|
||||||
alternate_clip_bw : DEFAULT_MAX_UNMEASURED_BW_KB;
|
alternate_clip_bw : DEFAULT_MAX_UNMEASURED_BW_KB;
|
||||||
|
@ -4285,7 +4286,6 @@ test_routerstatus_for_umbw(routerstatus_t *rs, time_t now)
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
tt_str_op(rs->nickname,OP_EQ, "router1");
|
tt_str_op(rs->nickname,OP_EQ, "router1");
|
||||||
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
tt_mem_op(rs->descriptor_digest,OP_EQ, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
|
||||||
tt_int_op(rs->published_on,OP_EQ, now-1000);
|
|
||||||
tt_assert(tor_addr_eq_ipv4h(&rs->ipv4_addr, 0x99009901));
|
tt_assert(tor_addr_eq_ipv4h(&rs->ipv4_addr, 0x99009901));
|
||||||
tt_int_op(rs->ipv4_orport,OP_EQ, 443);
|
tt_int_op(rs->ipv4_orport,OP_EQ, 443);
|
||||||
tt_int_op(rs->ipv4_dirport,OP_EQ, 0);
|
tt_int_op(rs->ipv4_dirport,OP_EQ, 0);
|
||||||
|
@ -4385,7 +4385,6 @@ test_dir_fmt_control_ns(void *arg)
|
||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
memset(&rs, 0, sizeof(rs));
|
memset(&rs, 0, sizeof(rs));
|
||||||
rs.published_on = 1364925198;
|
|
||||||
strlcpy(rs.nickname, "TetsuoMilk", sizeof(rs.nickname));
|
strlcpy(rs.nickname, "TetsuoMilk", sizeof(rs.nickname));
|
||||||
memcpy(rs.identity_digest, "Stately, plump Buck ", DIGEST_LEN);
|
memcpy(rs.identity_digest, "Stately, plump Buck ", DIGEST_LEN);
|
||||||
memcpy(rs.descriptor_digest, "Mulligan came up fro", DIGEST_LEN);
|
memcpy(rs.descriptor_digest, "Mulligan came up fro", DIGEST_LEN);
|
||||||
|
@ -4403,7 +4402,7 @@ test_dir_fmt_control_ns(void *arg)
|
||||||
tt_assert(s);
|
tt_assert(s);
|
||||||
tt_str_op(s, OP_EQ,
|
tt_str_op(s, OP_EQ,
|
||||||
"r TetsuoMilk U3RhdGVseSwgcGx1bXAgQnVjayA "
|
"r TetsuoMilk U3RhdGVseSwgcGx1bXAgQnVjayA "
|
||||||
"TXVsbGlnYW4gY2FtZSB1cCBmcm8 2013-04-02 17:53:18 "
|
"TXVsbGlnYW4gY2FtZSB1cCBmcm8 2038-01-01 00:00:00 "
|
||||||
"32.48.64.80 9001 9002\n"
|
"32.48.64.80 9001 9002\n"
|
||||||
"s Exit Fast Running V2Dir\n"
|
"s Exit Fast Running V2Dir\n"
|
||||||
"w Bandwidth=1000\n");
|
"w Bandwidth=1000\n");
|
||||||
|
|
|
@ -93,7 +93,7 @@ dir_common_gen_routerstatus_for_v3ns(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.2.14");
|
vrs->version = tor_strdup("0.1.2.14");
|
||||||
rs->published_on = now-1500;
|
vrs->published_on = now-1500;
|
||||||
strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_1, DIGEST_LEN);
|
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_1, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_1, DIGEST_LEN);
|
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_1, DIGEST_LEN);
|
||||||
|
@ -111,7 +111,7 @@ dir_common_gen_routerstatus_for_v3ns(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.2.0.5");
|
vrs->version = tor_strdup("0.2.0.5");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_2, DIGEST_LEN);
|
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_2, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_2, DIGEST_LEN);
|
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_2, DIGEST_LEN);
|
||||||
|
@ -130,7 +130,7 @@ dir_common_gen_routerstatus_for_v3ns(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.0.3");
|
vrs->version = tor_strdup("0.1.0.3");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router3", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router3", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_3, DIGEST_LEN);
|
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_3, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_3, DIGEST_LEN);
|
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_3, DIGEST_LEN);
|
||||||
|
@ -147,7 +147,7 @@ dir_common_gen_routerstatus_for_v3ns(int idx, time_t now)
|
||||||
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
|
||||||
rs = &vrs->status;
|
rs = &vrs->status;
|
||||||
vrs->version = tor_strdup("0.1.6.3");
|
vrs->version = tor_strdup("0.1.6.3");
|
||||||
rs->published_on = now-1000;
|
vrs->published_on = now-1000;
|
||||||
strlcpy(rs->nickname, "router4", sizeof(rs->nickname));
|
strlcpy(rs->nickname, "router4", sizeof(rs->nickname));
|
||||||
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_4, DIGEST_LEN);
|
memset(rs->identity_digest, TEST_DIR_ROUTER_ID_4, DIGEST_LEN);
|
||||||
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_4, DIGEST_LEN);
|
memset(rs->descriptor_digest, TEST_DIR_ROUTER_DD_4, DIGEST_LEN);
|
||||||
|
|
|
@ -1273,7 +1273,6 @@ test_nodelist_routerstatus_has_visibly_changed(void *arg)
|
||||||
memcpy(rs_orig.descriptor_digest, "abcdefghijklmnopqrst", 20);
|
memcpy(rs_orig.descriptor_digest, "abcdefghijklmnopqrst", 20);
|
||||||
tor_addr_from_ipv4h(&rs_orig.ipv4_addr, 0x7f000001);
|
tor_addr_from_ipv4h(&rs_orig.ipv4_addr, 0x7f000001);
|
||||||
rs_orig.ipv4_orport = 3;
|
rs_orig.ipv4_orport = 3;
|
||||||
rs_orig.published_on = time(NULL);
|
|
||||||
rs_orig.has_bandwidth = 1;
|
rs_orig.has_bandwidth = 1;
|
||||||
rs_orig.bandwidth_kb = 20;
|
rs_orig.bandwidth_kb = 20;
|
||||||
|
|
||||||
|
@ -1284,9 +1283,9 @@ test_nodelist_routerstatus_has_visibly_changed(void *arg)
|
||||||
tor_free(fmt); \
|
tor_free(fmt); \
|
||||||
fmt_orig = routerstatus_format_entry(&rs_orig, NULL, NULL, \
|
fmt_orig = routerstatus_format_entry(&rs_orig, NULL, NULL, \
|
||||||
NS_CONTROL_PORT, \
|
NS_CONTROL_PORT, \
|
||||||
NULL); \
|
NULL, -1); \
|
||||||
fmt = routerstatus_format_entry(&rs, NULL, NULL, NS_CONTROL_PORT, \
|
fmt = routerstatus_format_entry(&rs, NULL, NULL, NS_CONTROL_PORT, \
|
||||||
NULL); \
|
NULL, -1); \
|
||||||
tt_assert(fmt_orig); \
|
tt_assert(fmt_orig); \
|
||||||
tt_assert(fmt); \
|
tt_assert(fmt); \
|
||||||
STMT_END
|
STMT_END
|
||||||
|
@ -1322,9 +1321,6 @@ test_nodelist_routerstatus_has_visibly_changed(void *arg)
|
||||||
strlcpy(rs.nickname, "fr1end1y", sizeof(rs.nickname));
|
strlcpy(rs.nickname, "fr1end1y", sizeof(rs.nickname));
|
||||||
ASSERT_CHANGED();
|
ASSERT_CHANGED();
|
||||||
|
|
||||||
rs.published_on += 3600;
|
|
||||||
ASSERT_CHANGED();
|
|
||||||
|
|
||||||
rs.ipv4_orport = 55;
|
rs.ipv4_orport = 55;
|
||||||
ASSERT_CHANGED();
|
ASSERT_CHANGED();
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,6 @@ test_router_mark_if_too_old(void *arg)
|
||||||
mock_ns = &ns;
|
mock_ns = &ns;
|
||||||
mock_ns->valid_after = now-3600;
|
mock_ns->valid_after = now-3600;
|
||||||
mock_rs = &rs;
|
mock_rs = &rs;
|
||||||
mock_rs->published_on = now - 10;
|
|
||||||
|
|
||||||
// no reason to mark this time.
|
// no reason to mark this time.
|
||||||
desc_clean_since = now-10;
|
desc_clean_since = now-10;
|
||||||
|
@ -302,25 +301,14 @@ test_router_mark_if_too_old(void *arg)
|
||||||
tt_i64_op(desc_clean_since, OP_EQ, 0);
|
tt_i64_op(desc_clean_since, OP_EQ, 0);
|
||||||
tt_str_op(desc_dirty_reason, OP_EQ, "time for new descriptor");
|
tt_str_op(desc_dirty_reason, OP_EQ, "time for new descriptor");
|
||||||
|
|
||||||
// Version in consensus published a long time ago? We won't mark it
|
|
||||||
// if it's been clean for only a short time.
|
|
||||||
desc_clean_since = now - 10;
|
desc_clean_since = now - 10;
|
||||||
desc_dirty_reason = NULL;
|
desc_dirty_reason = NULL;
|
||||||
mock_rs->published_on = now - 3600 * 96;
|
|
||||||
mark_my_descriptor_dirty_if_too_old(now);
|
mark_my_descriptor_dirty_if_too_old(now);
|
||||||
tt_i64_op(desc_clean_since, OP_EQ, now - 10);
|
tt_i64_op(desc_clean_since, OP_EQ, now - 10);
|
||||||
|
|
||||||
// ... but if it's been clean a while, we mark.
|
// Version in consensus marked as stale? We'll mark it.
|
||||||
desc_clean_since = now - 2 * 3600;
|
|
||||||
mark_my_descriptor_dirty_if_too_old(now);
|
|
||||||
tt_i64_op(desc_clean_since, OP_EQ, 0);
|
|
||||||
tt_str_op(desc_dirty_reason, OP_EQ,
|
|
||||||
"version listed in consensus is quite old");
|
|
||||||
|
|
||||||
// same deal if we're marked stale.
|
|
||||||
desc_clean_since = now - 2 * 3600;
|
desc_clean_since = now - 2 * 3600;
|
||||||
desc_dirty_reason = NULL;
|
desc_dirty_reason = NULL;
|
||||||
mock_rs->published_on = now - 10;
|
|
||||||
mock_rs->is_staledesc = 1;
|
mock_rs->is_staledesc = 1;
|
||||||
mark_my_descriptor_dirty_if_too_old(now);
|
mark_my_descriptor_dirty_if_too_old(now);
|
||||||
tt_i64_op(desc_clean_since, OP_EQ, 0);
|
tt_i64_op(desc_clean_since, OP_EQ, 0);
|
||||||
|
|
|
@ -40,7 +40,6 @@ setup_cfg(flag_vote_test_cfg_t *c)
|
||||||
memset(c->ri.cache_info.signed_descriptor_digest, 0xee, DIGEST_LEN);
|
memset(c->ri.cache_info.signed_descriptor_digest, 0xee, DIGEST_LEN);
|
||||||
|
|
||||||
c->ri.cache_info.published_on = c->now - 100;
|
c->ri.cache_info.published_on = c->now - 100;
|
||||||
c->expected.published_on = c->now - 100;
|
|
||||||
|
|
||||||
tor_addr_from_ipv4h(&c->ri.ipv4_addr, 0x7f010105);
|
tor_addr_from_ipv4h(&c->ri.ipv4_addr, 0x7f010105);
|
||||||
tor_addr_from_ipv4h(&c->expected.ipv4_addr, 0x7f010105);
|
tor_addr_from_ipv4h(&c->expected.ipv4_addr, 0x7f010105);
|
||||||
|
@ -65,7 +64,6 @@ check_result(flag_vote_test_cfg_t *c)
|
||||||
dirauth_set_routerstatus_from_routerinfo(&rs, &c->node, &c->ri, c->now,
|
dirauth_set_routerstatus_from_routerinfo(&rs, &c->node, &c->ri, c->now,
|
||||||
0, 0);
|
0, 0);
|
||||||
|
|
||||||
tt_i64_op(rs.published_on, OP_EQ, c->expected.published_on);
|
|
||||||
tt_str_op(rs.nickname, OP_EQ, c->expected.nickname);
|
tt_str_op(rs.nickname, OP_EQ, c->expected.nickname);
|
||||||
|
|
||||||
// identity_digest and descriptor_digest are not set here.
|
// identity_digest and descriptor_digest are not set here.
|
||||||
|
@ -144,13 +142,11 @@ test_voting_flags_staledesc(void *arg)
|
||||||
time_t now = cfg->now;
|
time_t now = cfg->now;
|
||||||
|
|
||||||
cfg->ri.cache_info.published_on = now - DESC_IS_STALE_INTERVAL + 10;
|
cfg->ri.cache_info.published_on = now - DESC_IS_STALE_INTERVAL + 10;
|
||||||
cfg->expected.published_on = now - DESC_IS_STALE_INTERVAL + 10;
|
|
||||||
// no change in expectations for is_staledesc
|
// no change in expectations for is_staledesc
|
||||||
if (!check_result(cfg))
|
if (!check_result(cfg))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
cfg->ri.cache_info.published_on = now - DESC_IS_STALE_INTERVAL - 10;
|
cfg->ri.cache_info.published_on = now - DESC_IS_STALE_INTERVAL - 10;
|
||||||
cfg->expected.published_on = now - DESC_IS_STALE_INTERVAL - 10;
|
|
||||||
cfg->expected.is_staledesc = 1;
|
cfg->expected.is_staledesc = 1;
|
||||||
if (!check_result(cfg))
|
if (!check_result(cfg))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
Loading…
Add table
Reference in a new issue