swarm/src/behaviour: Add KeepAlive Behaviour
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
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.
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.
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
DummyBehaviourto 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.