diff --git a/p2p/host/relay/autorelay_test.go b/p2p/host/relay/autorelay_test.go index 83b910325c..b9f062de0c 100644 --- a/p2p/host/relay/autorelay_test.go +++ b/p2p/host/relay/autorelay_test.go @@ -3,6 +3,7 @@ package relay_test import ( "context" "net" + "strings" "sync" "testing" "time" @@ -132,7 +133,22 @@ func TestAutoRelay(t *testing.T) { if err != nil { t.Fatal(err) } - _, err = libp2p.New(ctx, libp2p.EnableRelay(circuit.OptHop), libp2p.EnableAutoRelay(), libp2p.Routing(makeRouting)) + // announce dns addrs because filter out private addresses from relays, + // and we consider dns addresses "public". + _, err = libp2p.New(ctx, + libp2p.EnableRelay(circuit.OptHop), + libp2p.EnableAutoRelay(), + libp2p.Routing(makeRouting), + libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr { + for i, addr := range addrs { + saddr := addr.String() + if strings.HasPrefix(saddr, "/ip4/127.0.0.1/") { + addrNoIP := strings.TrimPrefix(saddr, "/ip4/127.0.0.1") + addrs[i] = ma.StringCast("/dns4/localhost" + addrNoIP) + } + } + return addrs + })) if err != nil { t.Fatal(err) } diff --git a/p2p/protocol/identify/id_test.go b/p2p/protocol/identify/id_test.go index a5948c694b..f3bd42930e 100644 --- a/p2p/protocol/identify/id_test.go +++ b/p2p/protocol/identify/id_test.go @@ -788,7 +788,7 @@ func TestLargeIdentifyMessage(t *testing.T) { // add protocol strings to make the message larger // about 2K of protocol strings for i := 0; i < 500; i++ { - r := "rand" + string(i) + r := fmt.Sprintf("rand%d", i) h1.SetStreamHandler(protocol.ID(r), func(network.Stream) {}) h2.SetStreamHandler(protocol.ID(r), func(network.Stream) {}) } @@ -898,7 +898,7 @@ func TestLargePushMessage(t *testing.T) { // add protocol strings to make the message larger // about 2K of protocol strings for i := 0; i < 500; i++ { - r := "rand" + string(i) + r := fmt.Sprintf("rand%d", i) h1.SetStreamHandler(protocol.ID(r), func(network.Stream) {}) h2.SetStreamHandler(protocol.ID(r), func(network.Stream) {}) }