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

feat(dcutr): keep connection alive while we are using it #3960

Merged
merged 19 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions protocols/dcutr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
See [PR 3715].
- Remove deprecated items. See [PR 3700].

- Keep connection alive while we are using it. See [PR 3960].

[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3700]: https://github.com/libp2p/rust-libp2p/pull/3700
[PR 3960]: https://github.com/libp2p/rust-libp2p/pull/3960

## 0.9.1

Expand Down
20 changes: 10 additions & 10 deletions protocols/dcutr/src/handler/relayed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::protocol;
use either::Either;
use futures::future;
use futures::future::{BoxFuture, FutureExt};
use instant::Instant;
use libp2p_core::multiaddr::Multiaddr;
use libp2p_core::upgrade::DeniedUpgrade;
use libp2p_core::ConnectedPoint;
Expand All @@ -38,7 +37,6 @@ use libp2p_swarm::{
use std::collections::VecDeque;
use std::fmt;
use std::task::{Context, Poll};
use std::time::Duration;

pub enum Command {
Connect {
Expand Down Expand Up @@ -142,7 +140,6 @@ pub struct Handler {
/// Inbound connect, accepted by the behaviour, pending completion.
inbound_connect:
Option<BoxFuture<'static, Result<Vec<Multiaddr>, protocol::inbound::UpgradeError>>>,
keep_alive: KeepAlive,
}

impl Handler {
Expand All @@ -152,7 +149,6 @@ impl Handler {
pending_error: Default::default(),
queued_events: Default::default(),
inbound_connect: Default::default(),
keep_alive: KeepAlive::Until(Instant::now() + Duration::from_secs(30)),
}
}

Expand Down Expand Up @@ -226,8 +222,6 @@ impl Handler {
<Self as ConnectionHandler>::OutboundProtocol,
>,
) {
self.keep_alive = KeepAlive::No;

match error {
StreamUpgradeError::Timeout => {
self.queued_events
Expand Down Expand Up @@ -310,14 +304,20 @@ impl ConnectionHandler for Handler {
);
}
}
Command::UpgradeFinishedDontKeepAlive => {
self.keep_alive = KeepAlive::No;
}
Command::UpgradeFinishedDontKeepAlive => {}
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
}
}

fn connection_keep_alive(&self) -> KeepAlive {
self.keep_alive
if !self.queued_events.is_empty() {
return KeepAlive::Yes;
}

if self.inbound_connect.is_some() {
return KeepAlive::Yes;
}

KeepAlive::No
}

fn poll(
Expand Down