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

refactor(swarm)!: deprecate PollParameters where possible #3153

Merged
merged 15 commits into from
Dec 14, 2022

Conversation

thomaseizinger
Copy link
Contributor

Description

This patch deprecates 3 out of 4 functions on PollParameters:

  • local_peer_id
  • listened_addresses
  • external_addresses

The addresses can be obtained by inspecting the FromSwarm event. To make this easier, we introduce two utility structs in libp2p-swarm:

  • ExternalAddresses
  • ListenAddresses

A node's PeerId is always known to the caller, thus we can require them to pass it in.

Related: #3124.

Notes

I am opening this PR to get an initial concept ACK.

It is still missing changelog entries and we might want to consider waiting for the introduction of FromSwarm to be merged before merging this. That would allow us to then extend FromSwarm::NewExternalAddress with the AddressScore that is tracked in the Swarm which makes ExternaAddresses actually feature-equal with the current PollParameters::external_addresses.

Links to any relevant issues

Open Questions

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

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Two comments. Otherwise this looks great to me.

protocols/kad/src/behaviour.rs Outdated Show resolved Hide resolved

/// Utility struct for tracking the external addresses of a [`Swarm`](crate::Swarm).
#[derive(Debug, Default, Clone)]
pub struct ExternalAddresses {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub struct ExternalAddresses {
pub struct ExternalAddressTracker {

Not a strong opinion, though this would imply that one has to actively interact / pass-events with/to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not convinced that this is a better name. Can you elaborate what you don't like about the current one? :)

Copy link
Member

Choose a reason for hiding this comment

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

The name ExternalAddresses does not imply to me as a user, that I need to pass the FromSwarm events into it. That said, I think ExternalAddresses is just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would argue that this is only something a user needs to learn once and quite obvious from the implementation.

Most of the time, this name should convey that it holds the external addresses and only every so often, you need to understand how it works so I optimised for the common bit :)

@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2022

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

@mergify
Copy link
Contributor

mergify bot commented Dec 12, 2022

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

@thomaseizinger thomaseizinger changed the title refactor(swarm): Deprecate PollParameters where possible refactor(swarm): deprecate PollParameters where possible Dec 13, 2022
@thomaseizinger thomaseizinger changed the title refactor(swarm): deprecate PollParameters where possible refactor(swarm)!: deprecate PollParameters where possible Dec 13, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 13, 2022

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

@mergify
Copy link
Contributor

mergify bot commented Dec 13, 2022

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

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Solid work. Thanks!


/// Utility struct for tracking the external addresses of a [`Swarm`](crate::Swarm).
#[derive(Debug, Default, Clone)]
pub struct ExternalAddresses {
Copy link
Member

Choose a reason for hiding this comment

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

The name ExternalAddresses does not imply to me as a user, that I need to pass the FromSwarm events into it. That said, I think ExternalAddresses is just fine.

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

LGTM

@mergify mergify bot merged commit be3ec6c into master Dec 14, 2022
jxs pushed a commit to jxs/rust-libp2p that referenced this pull request Dec 14, 2022
)

This patch deprecates 3 out of 4 functions on `PollParameters`:

- `local_peer_id`
- `listened_addresses`
- `external_addresses`

The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`:

- `ExternalAddresses`
- `ListenAddresses`

A node's `PeerId` is always known to the caller, thus we can require them to pass it in.

Related: libp2p#3124.
@thomaseizinger thomaseizinger deleted the 3124-deprecate-poll-parameters branch February 24, 2023 14:48
umgefahren pushed a commit to umgefahren/rust-libp2p that referenced this pull request Mar 8, 2024
)

This patch deprecates 3 out of 4 functions on `PollParameters`:

- `local_peer_id`
- `listened_addresses`
- `external_addresses`

The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`:

- `ExternalAddresses`
- `ListenAddresses`

A node's `PeerId` is always known to the caller, thus we can require them to pass it in.

Related: libp2p#3124.
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.

3 participants