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): express dial logic linearly #3253

Merged
merged 3 commits into from
Dec 22, 2022
Merged

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Dec 16, 2022

Description

Previously, the logic within Swarm::dial involved fairly convoluted match expressions. This patch refactors this function to use new utility functions introduced on DialOpts to handle one concern at a time.

This has the advantage that we are covering slightly more cases now. Because we are parsing the PeerId only once at the top, checks like banning will now also act on dials that specify the PeerId as part of the /p2p protocol.

Notes

I am touching this function as part of #3099 and found it hard to integrate the new callbacks into it.

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

@thomaseizinger
Copy link
Contributor Author

With this refactoring, we are not executing certain checks more thoroughly. For example, we make all addresses to be dialed unique and filter out the ones we listen on. Previously, those was only true for the addresses coming from WithPeerIdWithAddresses. Was that on purpose @mxinden? (I think you introduced this builder).

I think the current version is more correct so I pushed a hack that fixes the test. Alternatively, we could also change the test (and perhaps remove the other code that checks for self dials?).

@mxinden mxinden linked an issue Dec 22, 2022 that may be closed by this pull request
@mxinden
Copy link
Member

mxinden commented Dec 22, 2022

For example, we make all addresses to be dialed unique and filter out the ones we listen on. Previously, those was only true for the addresses coming from WithPeerIdWithAddresses. Was that on purpose @mxinden? (I think you introduced this builder).

No longer dialing duplicate addresses would fix #3209.

Not doing it everywhere but in WithPeerIdWithAddresses only was not a deliberate choice. I am in favor of doing it everywhere. Thanks.

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.

All in all a nice clean-up. Thanks @thomaseizinger. Happy my ugly deeply nested method is gone.

@mergify mergify bot merged commit d5f4acc into master Dec 22, 2022
@thomaseizinger
Copy link
Contributor Author

For example, we make all addresses to be dialed unique and filter out the ones we listen on. Previously, those was only true for the addresses coming from WithPeerIdWithAddresses. Was that on purpose @mxinden? (I think you introduced this builder).

No longer dialing duplicate addresses would fix #3209.

I don't think this patch fixed #3209 because we are doing the deduplication before we ensure the address has a /p2p ending.

Let's re-open #3209 for now and confirm with a test that it is actually fixed.

@thomaseizinger thomaseizinger deleted the 2824-simplify-dial-opts branch February 24, 2023 14:48
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.

Concurrent dials to the same peer with duplicated multiaddrs
2 participants