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(identify): keep connection alive while we are using it #3876

Merged
merged 23 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2149b03
Move tests to `tests/` directory
thomaseizinger Apr 28, 2023
20a111c
Rewrite first identify tests using `libp2p-swarm-test`
thomaseizinger Apr 28, 2023
dc8dfd8
Rewrite another test
thomaseizinger Apr 28, 2023
ff41147
Rewrite final test
thomaseizinger Apr 28, 2023
336fcf3
Only listen on local interface in `libp2p-swarm-test`
thomaseizinger Apr 28, 2023
562a41f
Assert listen and observed address
thomaseizinger Apr 28, 2023
edea5af
Ensure listen addresses are unique
thomaseizinger Apr 28, 2023
dd3c732
Remove `correct_transfer` test
thomaseizinger Apr 28, 2023
18012d7
Remove unnecessary dependencies
thomaseizinger Apr 28, 2023
2c5c9d3
Delete dead code
thomaseizinger Apr 28, 2023
0182be7
Make tests more resilient
thomaseizinger Apr 28, 2023
d5bcef6
Revert "Only listen on local interface in `libp2p-swarm-test`"
thomaseizinger Apr 28, 2023
f3f5b69
Assert using contains to avoid needing to know other interfaces
thomaseizinger Apr 28, 2023
2f1fcff
Merge branch 'master' into refactor/better-identify-tests
thomaseizinger May 2, 2023
f332d69
Merge branch 'master' into refactor/better-identify-tests
thomaseizinger May 2, 2023
ee68201
Fix flaky test
thomaseizinger May 3, 2023
499667f
Fix more flakiness
thomaseizinger May 3, 2023
4f29de5
Merge branch 'master' into refactor/better-identify-tests
thomaseizinger May 4, 2023
f878e94
Fix more flakiness
thomaseizinger May 4, 2023
3a36bd4
Keep connection alive while we are working on it
thomaseizinger May 4, 2023
e668f51
Merge branch 'master' into feat/identify-keep-connection-alive
thomaseizinger May 8, 2023
aee7383
Add changelog entry
thomaseizinger May 8, 2023
af8b439
Merge branch 'master' into feat/identify-keep-connection-alive
mergify[bot] May 8, 2023
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
4 changes: 4 additions & 0 deletions protocols/identify/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
- Reduce the initial delay before running the identify protocol to 0 and make the option deprecated.
See [PR 3545].

- Fix aborting the answering of an identify request in rare situations.
See [PR 3876].

[PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698
[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715
[PR 3545]: https://github.com/libp2p/rust-libp2p/pull/3545
[PR 3876]: https://github.com/libp2p/rust-libp2p/pull/3876

## 0.42.2

Expand Down
20 changes: 13 additions & 7 deletions protocols/identify/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ pub struct Handler {
/// Future that fires when we need to identify the node again.
trigger_next_identify: Delay,

/// Whether the handler should keep the connection alive.
keep_alive: KeepAlive,

/// The interval of `trigger_next_identify`, i.e. the recurrent delay.
interval: Duration,

Expand Down Expand Up @@ -132,7 +129,6 @@ impl Handler {
reply_streams: VecDeque::new(),
pending_replies: FuturesUnordered::new(),
trigger_next_identify: Delay::new(initial_delay),
keep_alive: KeepAlive::Yes,
interval,
public_key,
protocol_version,
Expand Down Expand Up @@ -190,7 +186,6 @@ impl Handler {
.push(ConnectionHandlerEvent::Custom(Event::Identified(
remote_info,
)));
self.keep_alive = KeepAlive::No;
}
future::Either::Right(()) => self
.events
Expand All @@ -210,7 +205,6 @@ impl Handler {
.push(ConnectionHandlerEvent::Custom(Event::IdentificationError(
err,
)));
self.keep_alive = KeepAlive::No;
self.trigger_next_identify.reset(self.interval);
}
}
Expand Down Expand Up @@ -268,7 +262,19 @@ impl ConnectionHandler for Handler {
}

fn connection_keep_alive(&self) -> KeepAlive {
self.keep_alive
if self.inbound_identify_push.is_some() {
return KeepAlive::Yes;
}

if !self.pending_replies.is_empty() {
return KeepAlive::Yes;
}

if !self.reply_streams.is_empty() {
return KeepAlive::Yes;
}

KeepAlive::No
}

fn poll(
Expand Down