mirror of
https://github.com/status-im/status-go.git
synced 2025-02-11 22:37:41 +00:00
40 lines
880 B
Go
40 lines
880 B
Go
package relay
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/libp2p/go-libp2p-discovery"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
var (
|
|
// this is purposefully long to require some node stability before advertising as a relay
|
|
AdvertiseBootDelay = 15 * time.Minute
|
|
AdvertiseTTL = 30 * time.Minute
|
|
)
|
|
|
|
// Advertise advertises this node as a libp2p relay.
|
|
func Advertise(ctx context.Context, advertise discovery.Advertiser) {
|
|
go func() {
|
|
select {
|
|
case <-time.After(AdvertiseBootDelay):
|
|
discovery.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL))
|
|
case <-ctx.Done():
|
|
}
|
|
}()
|
|
}
|
|
|
|
// Filter filters out all relay addresses.
|
|
func Filter(addrs []ma.Multiaddr) []ma.Multiaddr {
|
|
raddrs := make([]ma.Multiaddr, 0, len(addrs))
|
|
for _, addr := range addrs {
|
|
if isRelayAddr(addr) {
|
|
continue
|
|
}
|
|
raddrs = append(raddrs, addr)
|
|
}
|
|
return raddrs
|
|
}
|