Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions protocols/request-response/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,36 @@ where
request_id
}

/// Like [`Behaviour::send_request`], but using a specific protocol for negotiation.
Copy link
Contributor

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?

Copy link
Author

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.

///
/// 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]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check against outbound_protocol on the behaviour first? protocols outside of outbound_protocol may be negotiated successfully, but I don't think it is a correct behaviour.

Copy link
Author

Choose a reason for hiding this comment

The 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
Expand Down