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

swarm/src/behaviour: Add KeepAlive Behaviour

Open mxinden opened this issue 3 years ago • 3 comments

Description

When getting started with rust-libp2p, it is confusing that connections over time through the KeepAlive mechanism.

See e.g. https://github.com/libp2p/rust-libp2p/issues/2768 https://github.com/libp2p/rust-libp2p/pull/2679

Today, users can import the Ping NetworkBehaviour and set with_keep_alive.

https://github.com/libp2p/rust-libp2p/blob/ce963dfcaa0a99e4b9bef27cdfe29e48946d823a/protocols/ping/src/handler.rs#L103-L116

I think there is value in a simple KeepAlive NetworkBehaviour implementation, keeping the connection alive, without the need to import Ping. The ConnectionHandler of the KeepAlive NetworkBehaviour could be exposed as well, thus allowing it to be used without its parent NetworkBehaviour.

Are you planning to do it yourself in a pull request?

No

mxinden avatar Jul 26 '22 06:07 mxinden

It seems like it's possible to keep a connection open using DummyBehaviour::with_keep_alive but I don't know if it's good enough.

K0UR05H avatar Jul 30 '22 00:07 K0UR05H

To be honest I haven't been aware of DummyBehaviour::with_keep_alive. Thanks @k0ur0x.

I am closing here for now. I would still consider a pure KeepAlive NetworkBehaviour useful. That said, I doubt it is worth the additional work.

mxinden avatar Aug 02 '22 04:08 mxinden

I am reopening this because:

  • the orthogonality of the static keep alive mechanism with the remaining ping functionality is highlighted once again in https://github.com/libp2p/rust-libp2p/pull/2852
  • I find DummyBehaviour to be a rather strange component too and thus I think it isn't a particularly good solution to the problem discussed here. Also see https://github.com/libp2p/rust-libp2p/pull/2859.

thomaseizinger avatar Sep 04 '22 09:09 thomaseizinger