Skip to content

Commit fc3ffcc

Browse files
author
Cory Schwartz
committed
advertise util
1 parent 85cf3e9 commit fc3ffcc

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

p2p/host/relay/relay.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
"github.com/libp2p/go-libp2p-core/discovery"
8-
disc "github.com/libp2p/go-libp2p-discovery"
98

109
ma "github.com/multiformats/go-multiaddr"
1110
)
@@ -21,7 +20,31 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) {
2120
go func() {
2221
select {
2322
case <-time.After(AdvertiseBootDelay):
24-
disc.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL))
23+
go func() {
24+
for {
25+
ttl, err := advertise.Advertise(ctx, RelayRendezvous, discovery.TTL(AdvertiseTTL))
26+
if err != nil {
27+
log.Debugf("Error advertising %s: %s", RelayRendezvous, err.Error())
28+
if ctx.Err() != nil {
29+
return
30+
}
31+
32+
select {
33+
case <-time.After(2 * time.Minute):
34+
continue
35+
case <-ctx.Done():
36+
return
37+
}
38+
}
39+
40+
wait := 7 * ttl / 8
41+
select {
42+
case <-time.After(wait):
43+
case <-ctx.Done():
44+
return
45+
}
46+
}
47+
}()
2548
case <-ctx.Done():
2649
}
2750
}()

0 commit comments

Comments
 (0)