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

autonatv2: implement autonatv2 spec #2469

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Aug 10, 2023

closes: #2422

Will add metrics for this in a separate PR.

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.

Partial review. I might be missing something, but where is the logic which address to check next? Or is that left for the implementation of the address pipeline?

p2p/host/basic/basic_host.go Outdated Show resolved Hide resolved
p2p/host/eventbus/basic.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
return nil, err
}
}
sub, err := h.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged))
Copy link
Contributor

Choose a reason for hiding this comment

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

EvtLocalReachabilityChanged is emitted by AutoNAT v1. Why are we subscribing to that event here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is for the transition period where we have v1 and v2 running in parallel? If so, can you add comments explaining the transition plan?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this logic from AutoNATv1. Do we need to disable the server in case the node is private?
We can provide this service over a relay connection too since private nodes can dial out and check reachability. Even with amplification attack prevention this only takes 100kb.

Copy link
Member Author

Choose a reason for hiding this comment

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

added a comment explaining the transition period.

Comment on lines 112 to 220
func (an *AutoNAT) validPeer() peer.ID {
peers := an.host.Peerstore().Peers()
idx := 0
for _, p := range an.host.Peerstore().Peers() {
if proto, err := an.host.Peerstore().SupportsProtocols(p, DialProtocol); len(proto) == 0 || err != nil {
continue
}
peers[idx] = p
idx++
}
if idx == 0 {
return ""
}
peers = peers[:idx]
rand.Shuffle(len(peers), func(i, j int) { peers[i], peers[j] = peers[j], peers[i] })
return peers[0]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we instead just keep our own map of peers that support DialProtocol? We would need to subscribe to the peer connected / disconnected event (or the identify completed event?), and check the supported protocols there.

This would allow us to not loop over all peers every single time we need one valid peer.

Copy link
Member Author

@sukunrt sukunrt Aug 14, 2023

Choose a reason for hiding this comment

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

I like this suggestion. I have incorporated it.

Should we process the connected peers on initialisation or just let the map build up and ignore the initially missed peers? This is only an issue if users separately attach AutoNATv2 to their hosts by calling the constructor explicitly.

p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
Comment on lines 206 to 258
s.SetDeadline(as.now().Add(1 * time.Second))
b := make([]byte, 1)
s.Read(b)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this for?

Copy link
Member Author

@sukunrt sukunrt Aug 14, 2023

Choose a reason for hiding this comment

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

Updated comment

Is there any clean way to close a stream with an ACK?
The problem here is, if we just do

stream.Write(msg)
stream.Close()
...
host.Network().ClosePeer(pid)

The last line will Reset the stream and discard the message.
We do want to remove the peer from the dialer host once the request is complete.

p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
@sukunrt
Copy link
Member Author

sukunrt commented Aug 13, 2023

Partial review. I might be missing something, but where is the logic which address to check next? Or is that left for the implementation of the address pipeline?

Yes, that part will go in the address pipeline.

@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 2 times, most recently from e09ef04 to c55e2af Compare August 14, 2023 17:07
@sukunrt sukunrt marked this pull request as ready for review August 21, 2023 17:12
@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 5 times, most recently from 6149b00 to 83babed Compare August 27, 2023 10:10
@p-shahi p-shahi mentioned this pull request Aug 31, 2023
25 tasks
@p-shahi p-shahi removed the request for review from marten-seemann February 22, 2024 16:45
@sukunrt sukunrt marked this pull request as draft April 23, 2024 15:57
@sukunrt sukunrt marked this pull request as ready for review April 26, 2024 06:32
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.

Implement AutoNATv2
2 participants