add delay in initial relay advertisement to allow the dht time to bootstrap

This commit is contained in:
vyzo 2018-11-29 12:24:40 +02:00
parent 14fad346b7
commit 31eb77d446
2 changed files with 11 additions and 2 deletions

View File

@ -26,9 +26,10 @@ import (
// test specific parameters // test specific parameters
func init() { func init() {
autonat.AutoNATIdentifyDelay = 100 * time.Millisecond autonat.AutoNATIdentifyDelay = 500 * time.Millisecond
autonat.AutoNATBootDelay = 1 * time.Second autonat.AutoNATBootDelay = 1 * time.Second
relay.BootDelay = 1 * time.Second relay.BootDelay = 1 * time.Second
relay.AdvertiseBootDelay = 1 * time.Millisecond
manet.Private4 = []*net.IPNet{} manet.Private4 = []*net.IPNet{}
} }

View File

@ -2,6 +2,7 @@ package relay
import ( import (
"context" "context"
"time"
basic "github.com/libp2p/go-libp2p/p2p/host/basic" basic "github.com/libp2p/go-libp2p/p2p/host/basic"
@ -10,6 +11,10 @@ import (
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
) )
var (
AdvertiseBootDelay = 5 * time.Second
)
// RelayHost is a Host that provides Relay services. // RelayHost is a Host that provides Relay services.
type RelayHost struct { type RelayHost struct {
*basic.BasicHost *basic.BasicHost
@ -25,7 +30,10 @@ func NewRelayHost(ctx context.Context, bhost *basic.BasicHost, advertise discove
advertise: advertise, advertise: advertise,
} }
bhost.AddrsFactory = h.hostAddrs bhost.AddrsFactory = h.hostAddrs
discovery.Advertise(ctx, advertise, RelayRendezvous) go func() {
time.Sleep(AdvertiseBootDelay)
discovery.Advertise(ctx, advertise, RelayRendezvous)
}()
return h return h
} }