Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm/src/behaviour: Add KeepAlive Behaviour #2778

Closed
mxinden opened this issue Jul 26, 2022 · 3 comments · Fixed by #2859
Closed

swarm/src/behaviour: Add KeepAlive Behaviour #2778

mxinden opened this issue Jul 26, 2022 · 3 comments · Fixed by #2859
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@mxinden
Copy link
Member

mxinden commented Jul 26, 2022

Description

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

See e.g. #2768 #2679

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

/// Sets whether the ping protocol itself should keep the connection alive,
/// apart from the maximum allowed failures.
///
/// By default, the ping protocol itself allows the connection to be closed
/// at any time, i.e. in the absence of ping failures the connection lifetime
/// is determined by other protocol handlers.
///
/// If the maximum number of allowed ping failures is reached, the
/// connection is always terminated as a result of [`ConnectionHandler::poll`]
/// returning an error, regardless of the keep-alive setting.
pub fn with_keep_alive(mut self, b: bool) -> Self {
self.keep_alive = b;
self
}

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

@K0UR05H
Copy link
Contributor

K0UR05H commented Jul 30, 2022

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.

@mxinden
Copy link
Member Author

mxinden commented Aug 2, 2022

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.

@thomaseizinger
Copy link
Contributor

I am reopening this because:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants