Skip to content

Conversation

@arsenron
Copy link
Contributor

@arsenron arsenron commented Aug 8, 2023

Description

Tracked in #4259. Now if a listener supports loopback interfaces, when a remote address is also a loopback address, we reuse an existing listener.

Notes & 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.

Neat! Thank you @arsenron for the work.

Would you mind adding a unit test as well? This should be relatively straight forward. Given two nodes A and B:

  1. Have A listen on 0.0.0.0:0.
  2. Given the wildcard port (:0) store the concrete port chosen by the OS across all interfaces.
  3. Have B listen on 127.0.0.1:0.
  4. Have A dial B.
  5. Expect the source port of A at B to be the port stored in (2), i.e. to be A's listen port.

@mergify
Copy link
Contributor

mergify bot commented Aug 10, 2023

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

@arsenron
Copy link
Contributor Author

Neat! Thank you @arsenron for the work.

Would you mind adding a unit test as well? This should be relatively straight forward. Given two nodes A and B:

1. Have A listen on `0.0.0.0:0`.

2. Given the wildcard port (`:0`) store the concrete port chosen by the OS across all interfaces.

3. Have B listen on `127.0.0.1:0`.

4. Have A dial B.

5. Expect the source port of A at B to be the port stored in (2), i.e. to be A's listen port.

Done.

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.

Wow, that was fast. Thank you! Two suggestions.

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.

Thank you for adjusting the test.

@arsenron
Copy link
Contributor Author

@mxinden Rewrote using a HashSet instead of a bool to make the logic more reliable

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.

Well done @arsenron! Thank you for the help.

@mergify mergify bot merged commit 79aca37 into libp2p:master Aug 11, 2023
@mxinden
Copy link
Member

mxinden commented Aug 11, 2023

Tagged and published.

thomaseizinger pushed a commit that referenced this pull request Aug 20, 2023
Tracked in #4259. Now if a listener supports loopback interfaces, when a remote address is also a loopback address, we reuse an existing listener.

Pull-Request: #4304.
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