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

autonat: fix interaction with autorelay #2967

Merged
merged 10 commits into from
Oct 17, 2024
Merged

autonat: fix interaction with autorelay #2967

merged 10 commits into from
Oct 17, 2024

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Sep 18, 2024

Fixes: #2964

@sukunrt sukunrt force-pushed the sukun/addr-factory branch 5 times, most recently from 3e54651 to f79b989 Compare September 25, 2024 13:07
@MarcoPolo MarcoPolo mentioned this pull request Oct 9, 2024
29 tasks
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

I don't love this service. It's very messy, interacts with the basic host in deep ways, and seems hard to test.

It'll be nice when we drop it in favor of AutoNAT V2.

p2p/host/autonat/autonat_test.go Outdated Show resolved Hide resolved
// We want an update when our public non-relay listen addresses have changed.
// EvtLocalAddressesUpdated is a poor proxy for that. It works when the host is Public,
// but fails when the host is private and used with AutoRelay.
addrChangeTicker := time.NewTicker(1 * time.Minute)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? Nothing about the doc comment in EvtLocalAddressesUpdated mentions this limitation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've changed the comment. But we should figure out what this bug is.

Copy link
Member Author

@sukunrt sukunrt Oct 18, 2024

Choose a reason for hiding this comment

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

There's no bug. The public address is not reachable so we don't advertise it.

Once we obtain relay reservations with AutoRelay, we will only advertise those public circuit v2 addresses and not our unreachable public addresses.

For AutoNAT we need our public, reachable or unreachable, non circuitv2, addresses.

p2p/host/autonat/autonat.go Outdated Show resolved Hide resolved
p2p/host/autonat/autonat.go Outdated Show resolved Hide resolved
p2p/host/autonat/autonat.go Outdated Show resolved Hide resolved
p2p/host/autonat/autonat.go Show resolved Hide resolved

for _, p := range peers {
n := len(peers)
for i, j := rand.Intn(n), 0; j < n; i, j = (i+1)%n, j+1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand the point of starting at a random offset. First, the code is slightly confusing. But, more importantly, you probably want to actually shuffle the list, rather than starting at a random offset. Shuffling correctly is surprisingly subtle.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've changed this.

Copy link
Member Author

@sukunrt sukunrt Oct 18, 2024

Choose a reason for hiding this comment

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

We are only interested in the first element that satisfies our condition, so I think it was fine to not shuffle the whole thing.

Separately, theres rand.Shuffle if you do want to shuffle.

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 start at a random offset to not rely on the peerstore's ordering of peers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL about rand.Shuffle. We should make a PR that updates our usages of shuffling throughout the codebase.

I think we do want to shuffle here, although I don't think I could prove why.

@@ -399,33 +399,30 @@ func (as *AmbientAutoNAT) getPeerToProbe() peer.ID {
return ""
}

candidates := make([]peer.ID, 0, len(peers))
// clean old probes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to decrement pending probes?

Nevermind, this is about our throttling, not about outstanding requests. May help to wordsmith the comment.

* holepunch: pass address function in constructor

* nit

* Remove getPublicAddrs

---------

Co-authored-by: Marco Munizaga <[email protected]>

for _, p := range peers {
n := len(peers)
for i, j := rand.Intn(n), 0; j < n; i, j = (i+1)%n, j+1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've changed this.

// We want an update when our public non-relay listen addresses have changed.
// EvtLocalAddressesUpdated is a poor proxy for that. It works when the host is Public,
// but fails when the host is private and used with AutoRelay.
addrChangeTicker := time.NewTicker(1 * time.Minute)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've changed the comment. But we should figure out what this bug is.

@MarcoPolo MarcoPolo merged commit b9cb861 into master Oct 17, 2024
11 checks passed
@sukunrt
Copy link
Member Author

sukunrt commented Oct 18, 2024

I don't love this service. It's very messy, interacts with the basic host in deep ways, and seems hard to test.

I agree.

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.

Bug: autorelay: enabling autorelay overrides custom AddrFactory
2 participants