Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin J. Thompson
Tor
Commits
9e081a44
Commit
9e081a44
authored
7 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Teach consdiffmgr to remember two digests: one compressed, one not.
parent
0274ea74
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/or/consdiffmgr.c
+31
-16
31 additions, 16 deletions
src/or/consdiffmgr.c
with
31 additions
and
16 deletions
src/or/consdiffmgr.c
+
31
−
16
View file @
9e081a44
...
...
@@ -21,8 +21,6 @@
#include
"networkstatus.h"
#include
"workqueue.h"
/* XXXX support compression */
/**
* Labels to apply to items in the conscache object.
*
...
...
@@ -33,8 +31,10 @@
/* The valid-after time for a consensus (or for the target consensus of a
* diff), encoded as ISO UTC. */
#define LABEL_VALID_AFTER "consensus-valid-after"
/* A hex encoded SHA3 digest of the object a
fter de
compress
ion.
*/
/* A hex encoded SHA3 digest of the object
,
a
s
compress
ed (if any)
*/
#define LABEL_SHA3_DIGEST "sha3-digest"
/* A hex encoded SHA3 digest of the object before compression. */
#define LABEL_SHA3_DIGEST_UNCOMPRESSED "sha3-digest-uncompressed"
/* The flavor of the consensus or consensuses diff */
#define LABEL_FLAVOR "consensus-flavor"
/* Diff only: the SHA3 digest of the source consensus. */
...
...
@@ -43,6 +43,8 @@
#define LABEL_TARGET_SHA3_DIGEST "target-sha3-digest"
/* Diff only: the valid-after date of the source consensus. */
#define LABEL_FROM_VALID_AFTER "from-valid-after"
/* What kind of compression was used? */
#define LABEL_COMPRESSION_TYPE "compression"
/** @} */
#define DOCTYPE_CONSENSUS "consensus"
...
...
@@ -299,10 +301,11 @@ cdm_cache_get(void)
/**
* Helper: given a list of labels, prepend the hex-encoded SHA3 digest
* of the <b>bodylen</b>-byte object at <b>body</b> to those labels,
* with
LABEL_SHA3_DIGEST
as its label.
* with
<b>label</b>
as its label.
*/
static
void
cdm_labels_prepend_sha3
(
config_line_t
**
labels
,
const
char
*
label
,
const
uint8_t
*
body
,
size_t
bodylen
)
{
...
...
@@ -313,7 +316,7 @@ cdm_labels_prepend_sha3(config_line_t **labels,
base16_encode
(
hexdigest
,
sizeof
(
hexdigest
),
(
const
char
*
)
sha3_digest
,
sizeof
(
sha3_digest
));
config_line_prepend
(
labels
,
LABEL_SHA3_DIGEST
,
hexdigest
);
config_line_prepend
(
labels
,
label
,
hexdigest
);
}
/** Helper: if there is a sha3-256 hex-encoded digest in <b>ent</b> with the
...
...
@@ -417,7 +420,10 @@ consdiffmgr_add_consensus(const char *consensus,
format_iso_time_nospace
(
formatted_time
,
valid_after
);
const
char
*
flavname
=
networkstatus_get_flavor_name
(
flavor
);
cdm_labels_prepend_sha3
(
&
labels
,
(
const
uint8_t
*
)
consensus
,
bodylen
);
cdm_labels_prepend_sha3
(
&
labels
,
LABEL_SHA3_DIGEST
,
(
const
uint8_t
*
)
consensus
,
bodylen
);
cdm_labels_prepend_sha3
(
&
labels
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
,
(
const
uint8_t
*
)
consensus
,
bodylen
);
config_line_prepend
(
&
labels
,
LABEL_FLAVOR
,
flavname
);
config_line_prepend
(
&
labels
,
LABEL_VALID_AFTER
,
formatted_time
);
config_line_prepend
(
&
labels
,
LABEL_DOCTYPE
,
DOCTYPE_CONSENSUS
);
...
...
@@ -584,7 +590,8 @@ consdiffmgr_cleanup(void)
if
(
most_recent
==
NULL
)
continue
;
const
char
*
most_recent_sha3
=
consensus_cache_entry_get_value
(
most_recent
,
LABEL_SHA3_DIGEST
);
consensus_cache_entry_get_value
(
most_recent
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
);
if
(
BUG
(
most_recent_sha3
==
NULL
))
continue
;
// LCOV_EXCL_LINE
...
...
@@ -713,7 +720,7 @@ consdiffmgr_rescan_flavor_(consensus_flavor_t flavor)
goto
done
;
//LCOV_EXCL_LINE
uint8_t
most_recent_sha3
[
DIGEST256_LEN
];
if
(
BUG
(
cdm_entry_get_sha3_value
(
most_recent_sha3
,
most_recent
,
LABEL_SHA3_DIGEST
)
<
0
))
LABEL_SHA3_DIGEST
_UNCOMPRESSED
)
<
0
))
goto
done
;
//LCOV_EXCL_LINE
// 2. Find all the relevant diffs _to_ this consensus. These are ones
...
...
@@ -765,7 +772,8 @@ consdiffmgr_rescan_flavor_(consensus_flavor_t flavor)
continue
;
// LCOV_EXCL_LINE
uint8_t
this_sha3
[
DIGEST256_LEN
];
if
(
BUG
(
cdm_entry_get_sha3_value
(
this_sha3
,
c
,
LABEL_SHA3_DIGEST
)
<
0
))
if
(
BUG
(
cdm_entry_get_sha3_value
(
this_sha3
,
c
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
)
<
0
))
continue
;
// LCOV_EXCL_LINE
if
(
cdm_diff_ht_check_and_note_pending
(
flavor
,
this_sha3
,
most_recent_sha3
))
{
...
...
@@ -933,13 +941,15 @@ consensus_diff_worker_threadfn(void *state_, void *work_)
const
char
*
lv_from_valid_after
=
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_VALID_AFTER
);
const
char
*
lv_from_digest
=
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_SHA3_DIGEST
);
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
);
const
char
*
lv_from_flavor
=
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_FLAVOR
);
const
char
*
lv_to_flavor
=
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_FLAVOR
);
const
char
*
lv_to_digest
=
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_SHA3_DIGEST
);
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
);
/* All these values are mandatory on the input */
if
(
BUG
(
!
lv_to_valid_after
)
||
...
...
@@ -978,7 +988,10 @@ consensus_diff_worker_threadfn(void *state_, void *work_)
job
->
body_out
=
(
uint8_t
*
)
consensus_diff
;
job
->
bodylen_out
=
strlen
(
consensus_diff
);
cdm_labels_prepend_sha3
(
&
job
->
labels_out
,
job
->
body_out
,
job
->
bodylen_out
);
cdm_labels_prepend_sha3
(
&
job
->
labels_out
,
LABEL_SHA3_DIGEST
,
job
->
body_out
,
job
->
bodylen_out
);
cdm_labels_prepend_sha3
(
&
job
->
labels_out
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
,
job
->
body_out
,
job
->
bodylen_out
);
config_line_prepend
(
&
job
->
labels_out
,
LABEL_FROM_VALID_AFTER
,
lv_from_valid_after
);
config_line_prepend
(
&
job
->
labels_out
,
LABEL_VALID_AFTER
,
lv_to_valid_after
);
...
...
@@ -1020,9 +1033,11 @@ consensus_diff_worker_replyfn(void *work_)
consensus_diff_worker_job_t
*
job
=
work_
;
const
char
*
lv_from_digest
=
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_SHA3_DIGEST
);
consensus_cache_entry_get_value
(
job
->
diff_from
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
);
const
char
*
lv_to_digest
=
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_SHA3_DIGEST
);
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_SHA3_DIGEST_UNCOMPRESSED
);
const
char
*
lv_flavor
=
consensus_cache_entry_get_value
(
job
->
diff_to
,
LABEL_FLAVOR
);
if
(
BUG
(
lv_from_digest
==
NULL
))
...
...
@@ -1035,10 +1050,10 @@ consensus_diff_worker_replyfn(void *work_)
int
flav
=
-
1
;
int
cache
=
1
;
if
(
BUG
(
cdm_entry_get_sha3_value
(
from_sha3
,
job
->
diff_from
,
LABEL_SHA3_DIGEST
)
<
0
))
LABEL_SHA3_DIGEST
_UNCOMPRESSED
)
<
0
))
cache
=
0
;
if
(
BUG
(
cdm_entry_get_sha3_value
(
to_sha3
,
job
->
diff_to
,
LABEL_SHA3_DIGEST
)
<
0
))
LABEL_SHA3_DIGEST
_UNCOMPRESSED
)
<
0
))
cache
=
0
;
if
(
BUG
(
lv_flavor
==
NULL
))
{
cache
=
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment