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: return E_DIAL_REFUSED instead of E_DIAL_ERROR of when skipping dial #1482

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion p2p/host/autonat/autonat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func sayPrivateStreamHandler(t *testing.T) network.StreamHandler {
w := protoio.NewDelimitedWriter(s)
res := pb.Message{
Type: pb.Message_DIAL_RESPONSE.Enum(),
DialResponse: newDialResponseError(pb.Message_E_DIAL_ERROR, "no dialable addresses"),
DialResponse: newDialResponseError(pb.Message_E_DIAL_ERROR, "dial failed"),
}
w.WriteMsg(&res)
}
Expand Down
6 changes: 4 additions & 2 deletions p2p/host/autonat/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (as *autoNATService) handleDial(p peer.ID, obsaddr ma.Multiaddr, mpi *pb.Me
// need to know their public IP address, and it needs to be different from our public IP
// address.
if as.config.dialPolicy.skipDial(obsaddr) {
return newDialResponseError(pb.Message_E_DIAL_ERROR, "refusing to dial peer with blocked observed address")
// Note: versions < v0.20.0 return Message_E_DIAL_ERROR here, thus we can not rely on this error code.
return newDialResponseError(pb.Message_E_DIAL_REFUSED, "refusing to dial peer with blocked observed address")
}

// Determine the peer's IP address.
Expand Down Expand Up @@ -187,7 +188,8 @@ func (as *autoNATService) handleDial(p peer.ID, obsaddr ma.Multiaddr, mpi *pb.Me
}

if len(addrs) == 0 {
return newDialResponseError(pb.Message_E_DIAL_ERROR, "no dialable addresses")
// Note: versions < v0.20.0 return Message_E_DIAL_ERROR here, thus we can not rely on this error code.
return newDialResponseError(pb.Message_E_DIAL_REFUSED, "no dialable addresses")
}

return as.doDial(peer.AddrInfo{ID: p, Addrs: addrs})
Expand Down
4 changes: 2 additions & 2 deletions p2p/host/autonat/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func makeAutoNATClient(t *testing.T) (host.Host, Client) {
}

// Note: these tests assume that the host has only private network addresses!
func TestAutoNATServiceDialError(t *testing.T) {
func TestAutoNATServiceDialRefused(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -64,7 +64,7 @@ func TestAutoNATServiceDialError(t *testing.T) {
t.Fatal("Dial back succeeded unexpectedly!")
}

if !IsDialError(err) {
if !IsDialRefused(err) {
t.Fatal(err)
}
}
Expand Down