-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(dcutr): always check for relayed connection first #3982
Changes from 6 commits
4ed1427
bf1dfce
770e9d0
527371e
3b444eb
5e9e0a3
d1aba5f
b3c0996
5948aee
981735b
bf8d1b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,33 +246,30 @@ impl NetworkBehaviour for Behaviour { | |
local_addr: &Multiaddr, | ||
remote_addr: &Multiaddr, | ||
) -> Result<THandler<Self>, ConnectionDenied> { | ||
match self | ||
.outgoing_direct_connection_attempts | ||
.remove(&(connection_id, peer)) | ||
{ | ||
None => { | ||
let handler = if is_relayed(local_addr) { | ||
Either::Left(handler::relayed::Handler::new(ConnectedPoint::Listener { | ||
local_addr: local_addr.clone(), | ||
send_back_addr: remote_addr.clone(), | ||
})) // TODO: We could make two `handler::relayed::Handler` here, one inbound one outbound. | ||
} else { | ||
Either::Right(Either::Right(dummy::ConnectionHandler)) | ||
}; | ||
|
||
Ok(handler) | ||
} | ||
Some(_) => { | ||
assert!( | ||
!is_relayed(local_addr), | ||
"`Prototype::DirectConnection` is never created for relayed connection." | ||
); | ||
if is_relayed(local_addr) { | ||
return Ok(Either::Left(handler::relayed::Handler::new( | ||
ConnectedPoint::Listener { | ||
local_addr: local_addr.clone(), | ||
send_back_addr: remote_addr.clone(), | ||
}, | ||
))); // TODO: We could make two `handler::relayed::Handler` here, one inbound one outbound. | ||
} | ||
|
||
Ok(Either::Right(Either::Left( | ||
handler::direct::Handler::default(), | ||
))) | ||
} | ||
if let Some(&relayed_connection_id) = self.direct_to_relayed_connections.get(&connection_id) | ||
{ | ||
assert!( | ||
self.outgoing_direct_connection_attempts | ||
.remove(&(relayed_connection_id, peer)) | ||
.is_some(), | ||
"DCUtR state tracking is buggy!" | ||
); | ||
|
||
return Ok(Either::Right(Either::Left( | ||
handler::direct::Handler::default(), | ||
))); | ||
} | ||
|
||
Ok(Either::Right(Either::Right(dummy::ConnectionHandler))) | ||
} | ||
|
||
fn handle_established_outbound_connection( | ||
|
@@ -282,33 +279,32 @@ impl NetworkBehaviour for Behaviour { | |
addr: &Multiaddr, | ||
role_override: Endpoint, | ||
) -> Result<THandler<Self>, ConnectionDenied> { | ||
match self | ||
.outgoing_direct_connection_attempts | ||
.remove(&(connection_id, peer)) | ||
if is_relayed(addr) { | ||
return Ok(Either::Left(handler::relayed::Handler::new( | ||
ConnectedPoint::Dialer { | ||
address: addr.clone(), | ||
role_override, | ||
}, | ||
))); // TODO: We could make two `handler::relayed::Handler` here, one inbound one outbound. | ||
} | ||
|
||
if let Some(&relayed_connection_id) = self.direct_to_relayed_connections.get(&connection_id) | ||
arpankapoor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
None => { | ||
let handler = if is_relayed(addr) { | ||
Either::Left(handler::relayed::Handler::new(ConnectedPoint::Dialer { | ||
address: addr.clone(), | ||
role_override, | ||
})) // TODO: We could make two `handler::relayed::Handler` here, one inbound one outbound. | ||
} else { | ||
Either::Right(Either::Right(dummy::ConnectionHandler)) | ||
}; | ||
|
||
Ok(handler) | ||
} | ||
Some(_) => { | ||
if role_override == Endpoint::Listener { | ||
assert!( | ||
thomaseizinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
!is_relayed(addr), | ||
"`Prototype::DirectConnection` is never created for relayed connection." | ||
self.outgoing_direct_connection_attempts | ||
.remove(&(relayed_connection_id, peer)) | ||
.is_some(), | ||
"DCUtR state tracking is buggy!" | ||
arpankapoor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
|
||
Ok(Either::Right(Either::Left( | ||
handler::direct::Handler::default(), | ||
))) | ||
} | ||
|
||
return Ok(Either::Right(Either::Left( | ||
handler::direct::Handler::default(), | ||
))); | ||
Comment on lines
+296
to
+298
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With recent refactorings in The above improvement is only slightly related to this pull request. In case you want to tackle it @arpankapoor in this pull request, that would be much appreciated. Though I am happy to merge as is and tackle it some other time. Idea raised by @thomaseizinger in a synchronous discussion just now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am in favor of that refactoring but no need to include in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it could be tackled in another PR perhaps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I'll merge this as is then :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracked here #4013. Also unresolving here for easier discovery in the future. |
||
} | ||
|
||
Ok(Either::Right(Either::Right(dummy::ConnectionHandler))) | ||
} | ||
|
||
fn on_connection_handler_event( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can ever be hit actually. In hole-punching, we cannot for sure tell which inbound connection was the one that the remote achieved through hole punching.
Plus, all this state tracking here uses
ConnectionId
s that are created as part of dialing, i.e. outbound connections.So unless I am missing something, this function can be reduced to always return a
dummy::ConnectionHandler
for non-relayed connections.@mxinden Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I agree with your assessment. I'll make this change after @mxinden's comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right @thomaseizinger.
For what it is worth, likely my train of thought that ended up with the code above:
In
NetworkBehaviour::on_connection_handler_event
onOutboundConnectNegotiated
we trigger aDial
withrole_override()
(i.e.as_listener
) and then insert themaybe_direct_connection_id
from theDialOpts
intoself.direct_to_relayed_connections
.rust-libp2p/protocols/dcutr/src/behaviour_impl.rs
Lines 379 to 395 in d4c4078
On success this would be reported to the
Behaviour
viaNetworkBehaviour::handle_established_outbound_connection
and not as assumed here inNetworkBehaviour::handle_established_inbound_connection
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding an
assert
here, thatconnection_id
is not inself.direct_to_relayed_connections
?