Skip to content
Snippets Groups Projects

WIP: Code to store, cache, manage, and generate consensus diffs

Open Nick Mathewson requested to merge consdiffmgr into master
4 unresolved threads

Merge request reports

Approval is optional
Merge blocked: 1 check failed
Merge conflicts must be resolved.

Merge details

  • The source branch is 1392 commits behind the target branch.
  • 28 commits and 1 merge commit will be added to master.
  • Source branch will not be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
57 * If true, we have learned at least one new consensus since the
58 * consensus cache was last up-to-date.
59 */
60 static int cdm_cache_dirty = 0;
61 /**
62 * If true, we have scanned the cache to update our hashtable of diffs.
63 */
64 static int cdm_cache_loaded = 0;
65
66 /**
67 * Possible status values for cdm_diff_t.cdm_diff_status
68 *
69 * @{ */
70 #define CDM_DIFF_PRESENT 1
71 #define CDM_DIFF_IN_PROGRESS 2
72 #define CDM_DIFF_ERROR 3
  • 177 memcpy(search.from_sha3, from_sha3, DIGEST256_LEN);
    178 ent = HT_FIND(cdm_diff_ht, &cdm_diff_ht, &search);
    179 if (ent) {
    180 tor_assert_nonfatal(ent->cdm_diff_status != CDM_DIFF_PRESENT);
    181 return 1;
    182 }
    183 ent = cdm_diff_new(flav, from_sha3, target_sha3);
    184 ent->cdm_diff_status = CDM_DIFF_IN_PROGRESS;
    185 HT_INSERT(cdm_diff_ht, &cdm_diff_ht, ent);
    186 return 0;
    187 }
    188
    189 /**
    190 * Update the status of the diff of type <b>flav</b> between consensuses with
    191 * the two provided SHA3-256 digests, so that its status becomes
    192 * <b>status</b>, and its value becomes the (optional) <b>handle</b>.
  • 383 * Return 0 on success and -1 on failure.
    384 */
    385 int
    386 consdiffmgr_add_consensus(const char *consensus,
    387 const networkstatus_t *as_parsed)
    388 {
    389 if (BUG(consensus == NULL) || BUG(as_parsed == NULL))
    390 return -1; // LCOV_EXCL_LINE
    391 if (BUG(as_parsed->type != NS_TYPE_CONSENSUS))
    392 return -1; // LCOV_EXCL_LINE
    393
    394 const consensus_flavor_t flavor = as_parsed->flavor;
    395 const time_t valid_after = as_parsed->valid_after;
    396
    397 if (valid_after < approx_time() - 3600 * consdiff_cfg.cache_max_age_hours) {
    398 log_info(LD_DIRSERV, "We don't care about this one; it's too old.");
  • 657 consensus_cache_entry_incref(obj);
    658 r = consensus_cache_entry_get_body(obj, &body, &bodylen);
    659 if (r == 0) {
    660 crypto_digest256((char *)sha3_received, (const char *)body, bodylen,
    661 DIGEST_SHA3_256);
    662 }
    663 consensus_cache_entry_decref(obj);
    664 if (r < 0)
    665 continue;
    666
    667 if (fast_memneq(sha3_received, sha3_expected, DIGEST256_LEN)) {
    668 problems = 1;
    669 consensus_cache_entry_mark_for_removal(obj);
    670 continue;
    671 }
    672
  • Nick Mathewson added 1 commit

    added 1 commit

    • 33e5c6b8 - fixup! Add a hashtable to consdiffmgr to keep track of diff status

    Compare with previous version

  • Nick Mathewson added 1 commit

    added 1 commit

    • c7dcd939 - fixup! Add a "Consensus diff manager" module.

    Compare with previous version

  • Nick Mathewson added 1 commit

    added 1 commit

    • 487ba568 - fixup! Add a hashtable to consdiffmgr to keep track of diff status

    Compare with previous version

  • Please register or sign in to reply
    Loading