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

fix: don't prefer local ports from other addresses when dialing #1673

Merged
merged 2 commits into from
Aug 19, 2022

Conversation

Stebalien
Copy link
Member

This address may already be in-use (on that other address) somewhere else.

Thanks to @schomatis for figuring this out.

fixes #1611

p2p/net/reuseport/dialer.go Show resolved Hide resolved
p2p/net/reuseport/dialer.go Show resolved Hide resolved
@@ -177,20 +176,13 @@ func testPrefer(t *testing.T, listen, prefer, avoid ma.Multiaddr) {
}
defer listenerB1.Close()

dialOne(t, &trB, listenerA, listenerB1.Addr().(*net.TCPAddr).Port)
Copy link
Member Author

Choose a reason for hiding this comment

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

We now only prefer source ports if the dialing addresses match.

Comment on lines -12 to -15
type dialer interface {
Dial(network, addr string) (net.Conn, error)
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We now have one dialer, so there's no need to abstract over them.

@schomatis
Copy link

CI error is likely #1421 (working on it in #1659 but need more input).

@marten-seemann marten-seemann self-requested a review August 12, 2022 16:47
Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

I remember having spent quite some time digging through this code a while back (and forgotten most about it), so I'm mainly asking for more documentation here.

p2p/net/reuseport/dialer.go Show resolved Hide resolved
p2p/net/reuseport/dialer.go Show resolved Hide resolved

// DialContext dials a target addr.
// Dialing preference is
// * If there is a listener on the local interface the OS expects to use to route towards addr, use that.
Copy link
Contributor

Choose a reason for hiding this comment

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

I have problems parsing this sentence.

// DialContext dials a target addr.
// Dialing preference is
// * If there is a listener on the local interface the OS expects to use to route towards addr, use that.
// * If there is a listener on a loopback address, addr is loopback, use that.
Copy link
Contributor

Choose a reason for hiding this comment

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

This one as well, do you mean?

Suggested change
// * If there is a listener on a loopback address, addr is loopback, use that.
// * If there is a listener on a loopback address and addr is loopback, use that.

p2p/net/reuseport/dialer.go Show resolved Hide resolved
This address may already be in-use (on that other address) somewhere
else.

Thanks to @schomatis for figuring this out.

fixes #1611
@Stebalien
Copy link
Member Author

@marten-seemann done.

Copy link
Contributor

@marten-seemann marten-seemann 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 excellent documentation, @Stebalien!

@marten-seemann marten-seemann merged commit bbd2836 into master Aug 19, 2022
nisdas added a commit to nisdas/go-libp2p that referenced this pull request Nov 1, 2022
MarcoPolo pushed a commit that referenced this pull request Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flaky TestGlobalPreferenceV4 on Ubuntu
3 participants