Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
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
The Tor Project
Core
Arti
Commits
3b32e635
Commit
3b32e635
authored
2 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
GuardMgr: Tests for note_external_{success,failure}.
parent
3ba9b470
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!447
Guards: Separate "directory cache status" from "circuit status"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/tor-guardmgr/src/lib.rs
+57
-0
57 additions, 0 deletions
crates/tor-guardmgr/src/lib.rs
with
57 additions
and
0 deletions
crates/tor-guardmgr/src/lib.rs
+
57
−
0
View file @
3b32e635
...
...
@@ -1316,4 +1316,61 @@ mod test {
assert_eq!
(
guard
.id
()
.as_ref
()
.rsa
.as_bytes
()[
0
]
%
4
,
0
);
});
}
#[test]
fn
external_status
()
{
use
tor_linkspec
::
ChanTarget
;
test_with_all_runtimes!
(|
rt
|
async
move
{
let
(
guardmgr
,
_statemgr
,
netdir
)
=
init
(
rt
);
let
data_usage
=
GuardUsage
::
default
();
let
dir_usage
=
GuardUsageBuilder
::
new
()
.kind
(
GuardUsageKind
::
OneHopDirectory
)
.build
()
.unwrap
();
guardmgr
.update_network
(
&
netdir
);
{
// Override this parameter, so that we can get deterministic results below.
let
mut
inner
=
guardmgr
.inner
.lock
()
.unwrap
();
inner
.params.dir_parallelism
=
1
;
}
let
(
guard
,
mon
,
_usable
)
=
guardmgr
.select_guard
(
data_usage
.clone
(),
Some
(
&
netdir
))
.unwrap
();
mon
.succeeded
();
// Record that this guard gave us a bad directory object.
guardmgr
.note_external_failure
(
guard
.ed_identity
(),
guard
.rsa_identity
(),
ExternalActivity
::
DirCache
,
);
// We ask for another guard, for data usage. We should get the same
// one as last time, since the director failure doesn't mean this
// guard is useless as a primary guard.
let
(
g2
,
mon
,
_usable
)
=
guardmgr
.select_guard
(
data_usage
,
Some
(
&
netdir
))
.unwrap
();
assert_eq!
(
g2
.ed_identity
(),
guard
.ed_identity
());
mon
.succeeded
();
// But if we ask for a guard for directory usage, we should get a
// different one, since the last guard we gave out failed.
let
(
g3
,
mon
,
_usable
)
=
guardmgr
.select_guard
(
dir_usage
.clone
(),
Some
(
&
netdir
))
.unwrap
();
assert_ne!
(
g3
.ed_identity
(),
guard
.ed_identity
());
mon
.succeeded
();
// Now record a success for for directory usage.
guardmgr
.note_external_success
(
guard
.ed_identity
(),
guard
.rsa_identity
(),
ExternalActivity
::
DirCache
,
);
// Now that the guard is working as a cache, asking for it should get us the same guard.
let
(
g4
,
_mon
,
_usable
)
=
guardmgr
.select_guard
(
dir_usage
,
Some
(
&
netdir
))
.unwrap
();
assert_eq!
(
g4
.ed_identity
(),
guard
.ed_identity
());
});
}
}
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