diff --git a/p2p/host/relay/autorelay_test.go b/p2p/host/relay/autorelay_test.go index ce50ea8c..4d57d780 100644 --- a/p2p/host/relay/autorelay_test.go +++ b/p2p/host/relay/autorelay_test.go @@ -26,9 +26,10 @@ import ( // test specific parameters func init() { - autonat.AutoNATIdentifyDelay = 100 * time.Millisecond + autonat.AutoNATIdentifyDelay = 500 * time.Millisecond autonat.AutoNATBootDelay = 1 * time.Second relay.BootDelay = 1 * time.Second + relay.AdvertiseBootDelay = 1 * time.Millisecond manet.Private4 = []*net.IPNet{} } diff --git a/p2p/host/relay/relay.go b/p2p/host/relay/relay.go index 69b67370..3f282a13 100644 --- a/p2p/host/relay/relay.go +++ b/p2p/host/relay/relay.go @@ -2,6 +2,7 @@ package relay import ( "context" + "time" basic "github.com/libp2p/go-libp2p/p2p/host/basic" @@ -10,6 +11,10 @@ import ( ma "github.com/multiformats/go-multiaddr" ) +var ( + AdvertiseBootDelay = 5 * time.Second +) + // RelayHost is a Host that provides Relay services. type RelayHost struct { *basic.BasicHost @@ -25,7 +30,10 @@ func NewRelayHost(ctx context.Context, bhost *basic.BasicHost, advertise discove advertise: advertise, } bhost.AddrsFactory = h.hostAddrs - discovery.Advertise(ctx, advertise, RelayRendezvous) + go func() { + time.Sleep(AdvertiseBootDelay) + discovery.Advertise(ctx, advertise, RelayRendezvous) + }() return h }