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(tcp): reducing branching in Transport::create_socket #4328

Merged
merged 6 commits into from
Aug 18, 2023

Conversation

jxs
Copy link
Member

@jxs jxs commented Aug 14, 2023

and add test for listening on ipv4 and ipv6 separately.

Description

Following #4289 (comment), hereby is the PR to also improve the create_socket using for_addr. We also add a test for listening on IPv4 and IPv6 separately.

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

and add test for listening on ipv4 and ipv6 separately.
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 the follow-up.

transports/tcp/src/lib.rs Outdated Show resolved Hide resolved
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.

I suggest having the operating system choose any free port. In case someone has e.g. a go-ipfs node running on 4001 their unit tests would still succeed.

transports/tcp/src/lib.rs Outdated Show resolved Hide resolved
transports/tcp/src/lib.rs Outdated Show resolved Hide resolved
transports/tcp/src/lib.rs Outdated Show resolved Hide resolved
@jxs
Copy link
Member Author

jxs commented Aug 15, 2023

I suggest having the operating system choose any free port. In case someone has e.g. a go-ipfs node running on 4001 their unit tests would still succeed.

but that defeats the purpose of the test no? I.e. being certain that ipv4 and ipv6 run in the same port. I can try something else nonetheless.

@mxinden
Copy link
Member

mxinden commented Aug 15, 2023

Ah, yes, sorry. My bad. How about a more random port than 4001, or even better first assign a random port for v4 by the OS and then use the same port for v6?

@thomaseizinger thomaseizinger changed the title chore: improve Tcp Transport::create_socket refactor(tcp): reducing branching in Transport::create_socket Aug 15, 2023
@thomaseizinger
Copy link
Contributor

You can use a TcpListener to first bind a random port, retrieve the port, drop the listener and then bind to it again :)

@jxs
Copy link
Member Author

jxs commented Aug 16, 2023

You can use a TcpListener to first bind a random port, retrieve the port, drop the listener and then bind to it again :)

yup exactly 😁. Meanwhile also updated the Quic test, if wanted I can move it instead do a new PR aha

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. Fine to merge in one pull request.

@thomaseizinger
Copy link
Contributor

@mxinden Why is the cargo-deny job suddenly required? It only runs on changes to Cargo.toml files which is not the case in all PRs. I can't see it here: https://github.com/libp2p/github-mgmt/blame/master/github/libp2p.yml#L7074-L7126

@mxinden
Copy link
Member

mxinden commented Aug 18, 2023

@mergify refresh

@mergify
Copy link
Contributor

mergify bot commented Aug 18, 2023

refresh

✅ Pull request refreshed

@mxinden
Copy link
Member

mxinden commented Aug 18, 2023

@mxinden Why is the cargo-deny job suddenly required? It only runs on changes to Cargo.toml files which is not the case in all PRs. I can't see it here: https://github.com/libp2p/github-mgmt/blame/master/github/libp2p.yml#L7074-L7126

My bad. I changed it through the UI without thinking it all the way through. Thanks for catching. Sorry for the debugging time wasted on this.

What do you think of running it on all changes, simply succeeding right away on non-Cargo.toml changes @thomaseizinger? I would like to get to a place where one does not have to manually check for non-required failures.

@mergify mergify bot merged commit bf7fe68 into libp2p:master Aug 18, 2023
@thomaseizinger
Copy link
Contributor

What do you think of running it on all changes, simply succeeding right away on non-Cargo.toml changes @thomaseizinger? I would like to get to a place where one does not have to manually check for non-required failures.

I think we can simply add it to the CI workflow. I don't see why it shouldn't run on all code changes. It is slightly wasteful in terms of resource usage but I don't think it weighs in very heavily for the gained simplicity in the setup.

mxinden added a commit to mxinden/rust-libp2p that referenced this pull request Aug 20, 2023
Allows us to make `cargo-deny` job required.

See original discussion libp2p#4328 (comment).
@mxinden
Copy link
Member

mxinden commented Aug 20, 2023

Sounds good. Let me know what you think of #4352.

mergify bot pushed a commit that referenced this pull request Aug 21, 2023
Allows us to make `cargo-deny` job required.

See original discussion #4328 (comment).

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