Point to point Request-Response Behavior with libp2p

554 views Asked by At

Using libp2p, is there a way to write a network behavior that doesn’t hit the entire swarm, but goes directly to a peer and only that peer?

More generally, is there a way within libp2p to communicate exclusively (request/response) to particular peer that you are currently connected to?

2

There are 2 answers

0
Jackob T. Daw On

For everybody who finds this answer post 2022, the preferred solution would be the request-response network behavior.

An example of how to use this library can be found in the library's tests: https://github.com/libp2p/rust-libp2p/blob/master/protocols/request-response/tests/ping.rs

0
gkee On

One idea is to use gossipsub and subscribe to a specific topic between peers. You can create a custom behaviour that implements gossipsub and request/response. Here is an example of how to implement multiple behaviours in Rust.

I'm trying to do something similar but need multiple peers to subscribe to a topic.

Here is a list of all implementors for the NetworkBehaviour in Rust. At the time of writing, it looks like your options are:

  • Floodsub
  • Identify
  • Mdns
  • Ping
  • Relay
  • DummyBehaviour
  • Throttled
  • Gossipsub
  • Toggle
  • RequestResponse
  • Kademlia