advertise util
@@ -5,7 +5,6 @@ import (
"time"
"github.com/libp2p/go-libp2p-core/discovery"
- disc "github.com/libp2p/go-libp2p-discovery"
ma "github.com/multiformats/go-multiaddr"
)
@@ -21,7 +20,31 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) {
go func() {
select {
case <-time.After(AdvertiseBootDelay):
- disc.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL))
+ go func() {
+ for {
+ ttl, err := advertise.Advertise(ctx, RelayRendezvous, discovery.TTL(AdvertiseTTL))
+ if err != nil {
+ log.Debugf("Error advertising %s: %s", RelayRendezvous, err.Error())
+ if ctx.Err() != nil {
+ return
+ }
+
+ select {
+ case <-time.After(2 * time.Minute):
+ continue
+ case <-ctx.Done():
+ return
+ }
+ }
+
+ wait := 7 * ttl / 8
+ select {
+ case <-time.After(wait):
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
case <-ctx.Done():
}
}()
