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(kad): remove deprecated Config::set_connection_idle_timeout #4659

Merged
merged 19 commits into from
Oct 20, 2023

Conversation

leonzchang
Copy link
Contributor

@leonzchang leonzchang commented Oct 16, 2023

Description

Related: #3844.
Related: #4656.

Notes & open questions

some tests need to be fixed, after KeepAlive::Until being removed.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Oct 16, 2023

some tests need to be fixed, after KeepAlive::Until being removed.

To fix these tests, we need to change the following lines of code:

// Peer's first connection.
if other_established == 0 {
// Queue events for sending pending RPCs to the connected peer.
// There can be only one pending RPC for a particular peer and query per definition.
for (peer_id, event) in self.queries.iter_mut().filter_map(|q| {
q.inner
.pending_rpcs
.iter()
.position(|(p, _)| p == &peer_id)
.map(|p| q.inner.pending_rpcs.remove(p))
}) {
self.queued_events.push_back(ToSwarm::NotifyHandler {
peer_id,
event,
handler: NotifyHandler::Any,
});
}
self.connected_peers.insert(peer_id);

What happens here is that after the connection is established, we tell the NetworkBehaviour about it. Without KeepAlive::Until however, the connection shuts down immediately after being established so these events are "too late". To avoid this, we need to "preload" the connection handler in the handle_established_{in,out}bound_connection callbacks. I am doing the same thing for libp2p-request-response in #4029.

This refactoring is backwards compatible so we can do that together with the deprecation of PR for set_connection_idle_timeout.

Let me know if that makes sense or you need more info :)

@thomaseizinger thomaseizinger added this to the v0.53.0 milestone Oct 16, 2023
@leonzchang
Copy link
Contributor Author

leonzchang commented Oct 16, 2023

some tests need to be fixed, after KeepAlive::Until being removed.

Let me know if that makes sense or you need more info :)

I try to add preload_new_handler for Behaviour, but tests seems not going well, could you give me some hints?

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found two things so far, see if those fix the tests :)

protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved
@leonzchang
Copy link
Contributor Author

leonzchang commented Oct 16, 2023

Found two things so far, see if those fix the tests :)

Big Thanks, I found that we have to set idle_timeout when initializing swarm in tests and example.

@mergify
Copy link
Contributor

mergify bot commented Oct 16, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I left some inline comments.

protocols/kad/src/behaviour.rs Show resolved Hide resolved
protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/kad/src/behaviour/test.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Show resolved Hide resolved
examples/ipfs-kad/src/main.rs Outdated Show resolved Hide resolved
examples/ipfs-kad/src/main.rs Outdated Show resolved Hide resolved
protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

mergify bot pushed a commit that referenced this pull request Oct 17, 2023
@mergify

This comment was marked as resolved.

@thomaseizinger thomaseizinger marked this pull request as ready for review October 20, 2023 01:14
@mergify
Copy link
Contributor

mergify bot commented Oct 20, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

@thomaseizinger thomaseizinger marked this pull request as draft October 20, 2023 04:29
@thomaseizinger thomaseizinger marked this pull request as ready for review October 20, 2023 06:30
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thank you!

@thomaseizinger thomaseizinger changed the title feat(kad): remove KeepAlive::Until feat(kad): remove deprecated Config::set_connection_idle_timeout Oct 20, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 20, 2023

This pull request has merge conflicts. Could you please resolve them @leonzchang? 🙏

@mergify mergify bot merged commit 1e3ffeb into libp2p:master Oct 20, 2023
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants