Skip to content

Commit 8f46fc8

Browse files
committed
identify: don't filter dns addresses based on remote addr type
1 parent 81d5c0c commit 8f46fc8

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

p2p/protocol/identify/id.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ func filterAddrs(addrs []ma.Multiaddr, remote ma.Multiaddr) []ma.Multiaddr {
996996
return addrs
997997
}
998998
if manet.IsPrivateAddr(remote) {
999-
return ma.FilterAddrs(addrs, func(a ma.Multiaddr) bool { return !manet.IsIPLoopback(a) })
999+
return ma.FilterAddrs(addrs, func(a ma.Multiaddr) bool { return !manet.IsThinWaist(a) || !manet.IsIPLoopback(a) })
10001000
}
1001-
return ma.FilterAddrs(addrs, manet.IsPublicAddr)
1001+
return ma.FilterAddrs(addrs, func(a ma.Multiaddr) bool { return !manet.IsThinWaist(a) || manet.IsPublicAddr(a) })
10021002
}

p2p/protocol/identify/id_glass_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
recordPb "github.com/libp2p/go-libp2p/core/record/pb"
1313
blhost "github.com/libp2p/go-libp2p/p2p/host/blank"
1414
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
15+
ma "github.com/multiformats/go-multiaddr"
1516
"google.golang.org/protobuf/proto"
1617

1718
"github.com/stretchr/testify/assert"
@@ -173,3 +174,34 @@ func TestInvalidSignedPeerRecord(t *testing.T) {
173174
require.True(t, ok)
174175
require.Nil(t, cab.GetPeerRecord(h2.ID()))
175176
}
177+
178+
func TestIncomingAddrFilter(t *testing.T) {
179+
lhAddr := ma.StringCast("/ip4/127.0.0.1/udp/123/quic-v1")
180+
privAddr := ma.StringCast("/ip4/192.168.1.101/tcp/123")
181+
pubAddr := ma.StringCast("/ip6/2::1/udp/123/quic-v1")
182+
dnsAddr := ma.StringCast("/dns/example.com/udp/123/quic-v1")
183+
tests := []struct {
184+
output []ma.Multiaddr
185+
remote ma.Multiaddr
186+
}{
187+
{
188+
output: []ma.Multiaddr{lhAddr, privAddr, pubAddr, dnsAddr},
189+
remote: lhAddr,
190+
},
191+
{
192+
output: []ma.Multiaddr{privAddr, pubAddr, dnsAddr},
193+
remote: privAddr,
194+
},
195+
{
196+
output: []ma.Multiaddr{pubAddr, dnsAddr},
197+
remote: pubAddr,
198+
},
199+
}
200+
for _, tc := range tests {
201+
t.Run(fmt.Sprintf("remote:%s", tc.remote), func(t *testing.T) {
202+
input := []ma.Multiaddr{lhAddr, privAddr, pubAddr, dnsAddr}
203+
got := filterAddrs(input, tc.remote)
204+
require.ElementsMatch(t, tc.output, got)
205+
})
206+
}
207+
}

0 commit comments

Comments
 (0)