@@ -12,6 +12,7 @@ import (
12
12
recordPb "github.com/libp2p/go-libp2p/core/record/pb"
13
13
blhost "github.com/libp2p/go-libp2p/p2p/host/blank"
14
14
swarmt "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
15
+ ma "github.com/multiformats/go-multiaddr"
15
16
"google.golang.org/protobuf/proto"
16
17
17
18
"github.com/stretchr/testify/assert"
@@ -173,3 +174,34 @@ func TestInvalidSignedPeerRecord(t *testing.T) {
173
174
require .True (t , ok )
174
175
require .Nil (t , cab .GetPeerRecord (h2 .ID ()))
175
176
}
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