Commit 1d2c918d authored by Nick Mathewson's avatar Nick Mathewson 🥔
Browse files

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.
parent a7fb5563
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -390,7 +390,8 @@ format_networkstatus_vote(crypto_pk_t *private_signing_key,
    rsf = routerstatus_format_entry(&vrs->status,
                                    vrs->version, vrs->protocols,
                                    NS_V3_VOTE,
                                    vrs);
                                    vrs,
                                    -1);
    if (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.
   */
#define CMP_FIELD(utype, itype, field) do {                             \
    utype aval = (utype) (itype) a->status.field;                       \
    utype bval = (utype) (itype) b->status.field;                       \
    utype aval = (utype) (itype) a->field;                              \
    utype bval = (utype) (itype) b->field;                              \
    utype u = bval - aval;                                              \
    itype r2 = (itype) u;                                               \
    if (r2 < 0) {                                                       \
@@ -638,8 +639,8 @@ compare_vote_rs(const vote_routerstatus_t *a, const vote_routerstatus_t *b)
                            CMP_EXACT))) {
    return r;
  }
  CMP_FIELD(unsigned, int, ipv4_orport);
  CMP_FIELD(unsigned, int, ipv4_dirport);
  CMP_FIELD(unsigned, int, status.ipv4_orport);
  CMP_FIELD(unsigned, int, status.ipv4_dirport);

  return 0;
}
@@ -692,10 +693,10 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
    } else {
      if (cur && (cur_n > most_n ||
                  (cur_n == most_n &&
                   cur->status.published_on > most_published))) {
                   cur->published_on > most_published))) {
        most = cur;
        most_n = cur_n;
        most_published = cur->status.published_on;
        most_published = cur->published_on;
      }
      cur_n = 1;
      cur = rs;
@@ -703,7 +704,7 @@ compute_routerstatus_consensus(smartlist_t *votes, int consensus_method,
  } SMARTLIST_FOREACH_END(rs);

  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_n = cur_n; // 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,
             DIGEST_LEN);
      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_orport = rs->status.ipv4_orport;
      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... */
        /*     First line goes into "buf". */
        buf = routerstatus_format_entry(&rs_out, NULL, NULL,
                                        rs_format, NULL);
                                        rs_format, NULL, published_on);
        if (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,
                                               list_bad_exits,
                                               list_middle_only);
      vrs->published_on = ri->cache_info.published_on;

      if (ri->cache_info.signing_key_cert) {
        memcpy(vrs->ed25519_id,
+4 −1
Original line number Diff line number Diff line
@@ -371,14 +371,17 @@ routerstatus_parse_entry_from_string(memarea_t *area,
    }
  }

  time_t published_on;
  if (tor_snprintf(timebuf, sizeof(timebuf), "%s %s",
                   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]",
             tok->args[3+offset], tok->args[4+offset],
             offset, (int)flav);
    goto err;
  }
  if (vote_rs)
    vote_rs->published_on = published_on;

  if (tor_inet_aton(tok->args[5+offset], &in) == 0) {
    log_warn(LD_DIR, "Error parsing router address in network-status %s",
+14 −2
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@
/** Helper: write the router-status information in <b>rs</b> into a newly
 * 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.
 * 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.
 *
@@ -38,12 +41,14 @@
 *   NS_V3_VOTE - Output a complete V3 NS vote. If <b>vrs</b> is present,
 *        it contains additional information for the vote.
 *   NS_CONTROL_PORT - Output a NS document for the control port.
 *
 */
char *
routerstatus_format_entry(const routerstatus_t *rs, const char *version,
                          const char *protocols,
                          routerstatus_format_type_t format,
                          const vote_routerstatus_t *vrs)
                          const vote_routerstatus_t *vrs,
                          time_t declared_publish_time)
{
  char *summary;
  char *result = NULL;
@@ -53,11 +58,18 @@ routerstatus_format_entry(const routerstatus_t *rs, const char *version,
  char digest64[BASE64_DIGEST_LEN+1];
  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);
  if (ip_str[0] == '\0')
    goto err;

  format_iso_time(published, rs->published_on);
  digest_to_base64(identity64, rs->identity_digest);
  digest_to_base64(digest64, rs->descriptor_digest);

+2 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ char *routerstatus_format_entry(
                              const char *version,
                              const char *protocols,
                              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) */
+1 −2
Original line number Diff line number Diff line
@@ -2364,7 +2364,7 @@ char *
networkstatus_getinfo_helper_single(const routerstatus_t *rs)
{
  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_named = rs->is_unnamed = 0;

  rs->published_on = ri->cache_info.published_on;
  memcpy(rs->identity_digest, node->identity, DIGEST_LEN);
  memcpy(rs->descriptor_digest, ri->cache_info.signed_descriptor_digest,
         DIGEST_LEN);
Loading