From cd6cc3b1e5db2c5e23e133c2201c23b063fc4895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Tue, 27 Jan 2026 19:37:02 -0300 Subject: [PATCH] feat: add send_request_with_protocol for selecting outbound protocols --- protocols/request-response/src/lib.rs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 1ac781b5744..f5037c0b83b 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -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]), + }; + + 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