Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Core
Arti
Commits
1a89d5c9
Commit
1a89d5c9
authored
May 9, 2024
by
gabi-250
Browse files
Options
Downloads
Patches
Plain Diff
tor-circmgr: If necessary, extend the circuit to become STUB+.
Closes
#1400
parent
2e19a240
Branches
Branches containing commit
No related tags found
1 merge request
!2145
tor-circmgr: If necessary, extend the circuit to become STUB+.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/tor-circmgr/src/hspool.rs
+42
-8
42 additions, 8 deletions
crates/tor-circmgr/src/hspool.rs
with
42 additions
and
8 deletions
crates/tor-circmgr/src/hspool.rs
+
42
−
8
View file @
1a89d5c9
...
...
@@ -15,10 +15,10 @@ use futures::{task::SpawnExt, StreamExt, TryFutureExt};
use
once_cell
::
sync
::
OnceCell
;
use
tor_error
::
debug_report
;
use
tor_error
::{
bad_api_usage
,
internal
};
use
tor_linkspec
::{
CircTarget
,
OwnedCircTarget
};
use
tor_linkspec
::{
CircTarget
,
HasRelayIds
as
_
,
OwnedCircTarget
,
RelayIdSet
};
use
tor_netdir
::{
NetDir
,
NetDirProvider
,
Relay
};
use
tor_proto
::
circuit
::{
self
,
CircParameters
,
ClientCirc
};
use
tor_relay_selection
::{
LowLevelRelayPredicate
,
RelayExclusion
};
use
tor_relay_selection
::{
LowLevelRelayPredicate
,
RelayExclusion
,
RelaySelector
,
RelayUsage
};
use
tor_rtcompat
::{
scheduler
::{
TaskHandle
,
TaskSchedule
},
Runtime
,
SleepProviderExt
,
...
...
@@ -438,7 +438,7 @@ impl<R: Runtime> HsCircPool<R> {
};
// Return the circuit we found before, if any.
if
let
Some
(
circuit
)
=
found_usable_circ
{
return
self
.maybe_extend_stub_circuit
(
circuit
,
kind
);
return
self
.maybe_extend_stub_circuit
(
netdir
,
circuit
,
kind
)
.await
;
}
// TODO: There is a possible optimization here. Instead of only waiting
...
...
@@ -456,9 +456,10 @@ impl<R: Runtime> HsCircPool<R> {
}
/// Return a circuit of the specified `kind`, built from `circuit`.
fn
maybe_extend_stub_circuit
(
async
fn
maybe_extend_stub_circuit
(
&
self
,
mut
circuit
:
HsCircStub
,
netdir
:
&
NetDir
,
circuit
:
HsCircStub
,
kind
:
HsCircStubKind
,
)
->
Result
<
HsCircStub
>
{
if
!
self
.vanguards_enabled
()
{
...
...
@@ -467,16 +468,49 @@ impl<R: Runtime> HsCircPool<R> {
match
(
circuit
.kind
,
kind
)
{
(
HsCircStubKind
::
Stub
,
HsCircStubKind
::
Extended
)
=>
{
// TODO HS-VANGUARDS: if full vanguards are enabled and the circuit we got is STUB,
debug!
(
"Wanted STUB+ circuit, but got STUB; extending by 1 hop..."
);
let
params
=
CircParameters
::
default
();
let
usage
=
RelayUsage
::
middle_relay
(
Some
(
&
RelayUsage
::
middle_relay
(
None
)));
let
circ_path
=
circuit
.circ
.path_ref
();
// A STUB circuit is a 3-hop circuit.
debug_assert_eq!
(
circ_path
.hops
()
.len
(),
3
);
// Like in VanguardHsPathBuilder::pick_path, we only want to exclude the L2 and L3
// guards (so we skip over the guard)
let
skip_n
=
1
;
let
mut
exclude_ids
=
RelayIdSet
::
new
();
for
hop
in
circ_path
.iter
()
.skip
(
skip_n
)
.flat_map
(|
hop
|
hop
.as_chan_target
())
{
exclude_ids
.extend
(
hop
.identities
()
.map
(|
id
|
id
.to_owned
()));
}
let
exclusion
=
RelayExclusion
::
exclude_identities
(
exclude_ids
);
let
selector
=
RelaySelector
::
new
(
usage
,
exclusion
);
let
target
=
{
let
mut
rng
=
rand
::
thread_rng
();
let
(
relay
,
info
)
=
selector
.select_relay
(
&
mut
rng
,
netdir
);
relay
.ok_or_else
(||
Error
::
NoRelay
{
path_kind
:
"vanguard STUB+"
,
role
:
"final hop"
,
problem
:
info
.to_string
(),
})
?
};
// If full vanguards are enabled and the circuit we got is STUB,
// we need to extend it by another hop to make it STUB+ before returning it
circuit
.kind
=
kind
;
let
circ
=
self
.extend_circ
(
circuit
,
params
,
target
)
.await
?
;
Ok
(
circuit
)
Ok
(
HsCircStub
{
circ
,
kind
}
)
}
(
HsCircStubKind
::
Extended
,
HsCircStubKind
::
Stub
)
=>
{
Err
(
internal!
(
"wanted a STUB circuit, but got STUB+?!"
)
.into
())
}
_
=>
{
trace!
(
"Wanted {kind} circuit, got {}"
,
circuit
.kind
);
// Nothing to do: the circuit stub we got is of the kind we wanted
Ok
(
circuit
)
}
...
...
...
...
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
sign in
to comment