-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: allow selecting outbound protocols in request_response behaviour
#6262
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -470,6 +470,36 @@ where | |
| request_id | ||
| } | ||
|
|
||
| /// Like [`Behaviour::send_request`], but using a specific protocol for negotiation. | ||
| /// | ||
| /// This allows explicitly selecting which protocol to use instead of offering all | ||
| /// configured outbound protocols. | ||
| pub fn send_request_with_protocol( | ||
| &mut self, | ||
| peer: &PeerId, | ||
| request: TCodec::Request, | ||
| protocol: TCodec::Protocol, | ||
| ) -> OutboundRequestId { | ||
| let request_id = self.next_outbound_request_id(); | ||
| let request = OutboundMessage { | ||
| request_id, | ||
| request, | ||
| protocols: SmallVec::from_iter([protocol]), | ||
|
Contributor
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. Maybe we should check against
Author
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 agree. Allowing that will probably just lead to confusion |
||
| }; | ||
|
|
||
| if let Some(request) = self.try_send_request(peer, request) { | ||
| self.pending_events.push_back(ToSwarm::Dial { | ||
| opts: DialOpts::peer_id(*peer).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.
What if a user want to send a request of a specific protocol, and a specific address, given that we also have
send_request_with_addresses?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.
That request isn't supported by this interface.
I was thinking about adding a new function receiving an options argument (similar interface as
DialOpts). That'd replace this function and simplify/deprecate the addresses one.