rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

Support explicit addresses for dialing purposes `send_request`

Open nazar-pc opened this issue 1 year ago • 6 comments

Right now send_request is dialing peer ID unconditionally. It is destined to fail if none of the behaviors know the address of the peer, as documented in the method itself.

However I am getting addresses in a response to another request and don't really want to persist it in any of the behaviors due to how annoying it is to write and manage them.

The simplest change that would work for me is to add an optional list of addresses to send_request, such that it can still succeed even if behaviors know nothing about this peer.

Not sure if this is the desired approach though. Initially I tried to initiate explicit dial right before calling send_request, but it didn't work because send_request's dial quickly fails and aborts the whole request, so I'll need to do more elaborate workaround, which is unfortunate and unnecessary.

nazar-pc avatar Oct 14 '24 22:10 nazar-pc

Hi Nazar, you are referring to request_response::Behaviour::send_request right? If so,

The simplest change that would work for me is to add an optional list of addresses to send_request, such that it can still succeed even if behaviors know nothing about this peer.

how would this work if request_response saves the peers into connected: HashMap<PeerId, SmallVec<[Connection; 2]>>,

jxs avatar Oct 15 '24 16:10 jxs

Hi Nazar, you are referring to request_response::Behaviour::send_request right?

Yes, what I meant is that for this to include addresses: https://github.com/libp2p/rust-libp2p/blob/d3228adf64cf68f419eeb0b18a5c0b762d29abbe/protocols/request-response/src/lib.rs#L434-L436

Like this:

self.pending_events.push_back(ToSwarm::Dial { 
    opts: DialOpts::peer_id(*peer).addresses(addresses).build(),
});

nazar-pc avatar Oct 15 '24 16:10 nazar-pc

I am curious, where do those multiaddresses come from? And can't you dial them as soon as you get them?

jxs avatar Oct 15 '24 17:10 jxs

Not sure what you mean by that exactly

nazar-pc avatar Oct 15 '24 17:10 nazar-pc

Sorry Nazar, I misread, reformulated the question

jxs avatar Oct 16 '24 14:10 jxs

I have a custom request-response protocol, then as described in https://github.com/libp2p/rust-libp2p/issues/5626 if responder doesn't have the data they respond with addresses of closest peers via local Kademlia query. After this application aggregates results and if needed makes requests to some of the newly discovered peers, which swarm may not be aware of at all.

nazar-pc avatar Oct 18 '24 05:10 nazar-pc