swarm: Split off "keep alive" functionality from DummyConnectionHandler#2859
swarm: Split off "keep alive" functionality from DummyConnectionHandler#2859
DummyConnectionHandler#2859Conversation
() is the default associated type when creating implementations of traits with IDEs like IntelliJ Rust or rust-analyzer. Providing a `ConnectionHandler` implementation for those should make it easier for users to get started.
NetworkBehaviour and ConnectionHandler for ()NetworkBehaviour and ConnectionHandler for ()
I have to give this more thought. I agree that it makes it harder to discover. Also I don't find the fact that
I think this is a good idea. |
I'll progress in this direction then! |
NetworkBehaviour and ConnectionHandler for ()DummyConnectionHandler
|
This is ready for another review @mxinden ! |
mxinden
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up. Small suggestions on the naming of the two NetworkBehaviour implementations.
|
Can you update the pull request description? |
Updated. Also added new questions. |
It is better for these to be grouped together rather than by what interface they are implementing.
I ended up introducing top-level |
|
Changelog and PR description are up to date. This is ready to be merged from my end. |
|
@thomaseizinger can you take a look at the clippy failure? |
Ah yes, I expected that one to happen eventually. I originally got the warning because #2932 wasn't yet fixed! |
…2p into unit-connection-handler
mxinden
left a comment
There was a problem hiding this comment.
Ready to merge from my end otherwise.
swarm/src/dummy.rs
Outdated
| use std::task::{Context, Poll}; | ||
| use void::Void; | ||
|
|
||
| /// Implementation of [`NetworkBehaviour`] that doesn't do anything other than keep all connections alive. |
There was a problem hiding this comment.
It does not keep connections alive, right?
There was a problem hiding this comment.
Absolutely correct. Thanks for spotting the typo!
Description
Previously, the
DummyConnectionHandleroffered a "keep alive" functionality, i.e. it allowed users to set the value of what is returned fromConnectionHandler::keep_alive. This handler is primarily used in tests orNetworkBehaviours that don't open any connections (like mDNS). In all of these cases, it is statically known whether we want to keep connections alive. As such, this functionality is better represented by a staticKeepAliveConnectionHandlerthat always returnsKeepAlive::Yesand aDummyConnectionHandlerthat always returnsKeepAlive::No.To follow the naming conventions described in #2217, we introduce a top-level
keep_aliveanddummybehaviour inlibp2p-swarmthat contains both theNetworkBehaviourandConnectionHandlerimplementation for either case.Links to any relevant issues
FromFnConnectionHandler#2852: To actually replace "Ping"'sConnectionHandlerwith aFromFnConnectionHandler, we need to decouple the "Keep Alive" functionality from the Ping protocol. If this PR is accepted, I'd send a follow-up to remove the keep-alive functionality from ping in favor of using theKeepAliveBehaviour.Open Questions
Implementations on()are not as easy to discover. Should we retainDummyBehaviourandDummyConnectionHandlerbut strip the keep-alive logic from them?Should we rename theKeepAlivetoKeepAlivePolicy(or something else) to avoid ambiguity withbehaviour::KeepAlive?Should we strip the keep alive functionality fromlibp2p-pingas part of this PR or in a follow-up?Change checklist
- [ ] I have added tests that prove my fix is effective or that my feature works