-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(transport): Implement dial_with_new_port to prevent port reuse #3910
Changes from all commits
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 |
---|---|---|
|
@@ -396,6 +396,33 @@ where | |
request_id | ||
} | ||
|
||
/// TODO: Document | ||
pub fn send_request_with_new_port( | ||
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. This doesn't really work unfortunately. I think to effectively utilize this API in AutoNAT, we will have to rewrite it to not use The flow would something like:
This is quite specific to AutoNAT and I am not sure we should extend Another thing that bothers me is that we expose functions such as 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.
Agreed. 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. Note that even with rewriting it, the issue of "don't run other protocols over that connection" is not solved although I am not entirely convinced it is actually a problem. |
||
&mut self, | ||
peer: &PeerId, | ||
request: TCodec::Request, | ||
) -> RequestId { | ||
let request_id = self.next_request_id(); | ||
let request = RequestProtocol { | ||
request_id, | ||
codec: self.codec.clone(), | ||
protocols: self.outbound_protocols.clone(), | ||
request, | ||
}; | ||
|
||
if let Some(request) = self.try_send_request(peer, request) { | ||
self.pending_events.push_back(ToSwarm::Dial { | ||
opts: DialOpts::peer_id(*peer).use_new_port().build(), | ||
}); | ||
self.pending_outbound_requests | ||
.entry(*peer) | ||
.or_default() | ||
.push(request); | ||
} | ||
|
||
request_id | ||
} | ||
|
||
/// Initiates sending a response to an inbound request. | ||
/// | ||
/// If the [`ResponseChannel`] is already closed due to a timeout or the | ||
|
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.
Not a fan of this API at all but I also don't have a better idea in the short-term. Long-term, I'd like to get rid of the
Dial
associated type (see #3436).