Skip to content

Commit

Permalink
Merge pull request #495 from libp2p/fix/advertise-relay
Browse files Browse the repository at this point in the history
Add delay in initial relay advertisement to allow the dht time to bootstrap
  • Loading branch information
vyzo authored Dec 5, 2018
2 parents a17052f + 5d0a6e2 commit e042905
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion p2p/host/relay/autorelay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down
13 changes: 12 additions & 1 deletion p2p/host/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package relay

import (
"context"
"time"

basic "github.com/libp2p/go-libp2p/p2p/host/basic"

Expand All @@ -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
Expand All @@ -25,7 +30,13 @@ func NewRelayHost(ctx context.Context, bhost *basic.BasicHost, advertise discove
advertise: advertise,
}
bhost.AddrsFactory = h.hostAddrs
discovery.Advertise(ctx, advertise, RelayRendezvous)
go func() {
select {
case <-time.After(AdvertiseBootDelay):
discovery.Advertise(ctx, advertise, RelayRendezvous)
case <-ctx.Done():
}
}()
return h
}

Expand Down

0 comments on commit e042905

Please # to comment.