Previously, a connection would be shut down immediately as soon as its `ConnectionHandler` reports `KeepAlive::No`. As we have gained experience with libp2p, it turned out that this isn't ideal. For one, tests often need to keep connections alive longer than the configured protocols require. Plus, some usecases require connections to be kept alive in general. Both of these needs are currently served by the `keep_alive::Behaviour`. That one does essentially nothing other than statically returning `KeepAlive::Yes` from its `ConnectionHandler`. It makes much more sense to deprecate `keep_alive::Behaviour` and instead allow users to globally configure an `idle_conncetion_timeout` on the `Swarm`. This timeout comes into effect once a `ConnectionHandler` reports `KeepAlive::No`. To start with, this timeout is 0. Together with https://github.com/libp2p/rust-libp2p/issues/3844, this will allow us to move towards a much more aggressive closing of idle connections, together with a more ergonomic way of opting out of this behaviour. Fixes #4121. Pull-Request: #4161.
Description
The rendezvous protocol example showcases how to implement a rendezvous server and interact with it using different binaries. The rendezvous server facilitates peer registration and discovery, enabling peers to find and communicate with each other in a decentralized manner.
Usage
To run the example, follow these steps:
-
Start the rendezvous server by running the following command:
RUST_LOG=info cargo run --bin rendezvous-example
This command starts the rendezvous server, which will listen for incoming connections and handle peer registrations and discovery.
-
Register a peer by executing the following command:
RUST_LOG=info cargo run --bin rzv-register
This command registers a peer with the rendezvous server, allowing the peer to be discovered by other peers.
-
Try to discover the registered peer from the previous step by running the following command:
RUST_LOG=info cargo run --bin rzv-discover
This command attempts to discover the registered peer using the rendezvous server. If successful, it will print the details of the discovered peer.
-
Additionally, you can try discovering a peer using the identify protocol by executing the following command:
RUST_LOG=info cargo run --bin rzv-identify
This command demonstrates peer discovery using the identify protocol. It will print the peer's identity information if successful.
-
Experiment with different registrations, discoveries, and combinations of protocols to explore the capabilities of the rendezvous protocol and libp2p library.
Conclusion
The rendezvous protocol example provides a practical demonstration of how to implement peer registration and discovery using libp2p. By running the rendezvous server and utilizing the provided binaries, users can register peers and discover them in a decentralized network.
Feel free to explore the code and customize the behavior of the rendezvous server and the binaries to suit your specific use cases.