Browse Source

add a WithDefaultStaticRelays AutoRelay option

pull/1239/head
Marten Seemann 3 years ago
parent
commit
9734b8d822
  1. 6
      options.go
  2. 16
      p2p/host/autorelay/autorelay.go

6
options.go

@ -271,11 +271,7 @@ func StaticRelays(relays []peer.AddrInfo) Option {
func DefaultStaticRelays() Option {
return func(cfg *Config) error {
for _, addr := range autorelay.DefaultRelays {
a, err := ma.NewMultiaddr(addr)
if err != nil {
return err
}
pi, err := peer.AddrInfoFromP2pAddr(a)
pi, err := peer.AddrInfoFromString(addr)
if err != nil {
return err
}

16
p2p/host/autorelay/autorelay.go

@ -53,6 +53,18 @@ var DefaultRelays = []string{
"/ip4/147.75.70.221/udp/4001/quic/p2p/Qme8g49gm3q4Acp7xWBKg3nAa9fxZ1YmyDJdyGgoG6LsXh",
}
var defaultStaticRelays []peer.AddrInfo
func init() {
for _, s := range DefaultRelays {
pi, err := peer.AddrInfoFromString(s)
if err != nil {
panic(fmt.Sprintf("failed to initialize default static relays: %s", err))
}
defaultStaticRelays = append(defaultStaticRelays, *pi)
}
}
type Option func(*AutoRelay) error
func WithStaticRelays(static []peer.AddrInfo) Option {
@ -65,6 +77,10 @@ func WithStaticRelays(static []peer.AddrInfo) Option {
}
}
func WithDefaultStaticRelays() Option {
return WithStaticRelays(defaultStaticRelays)
}
func WithDiscoverer(discover discovery.Discoverer) Option {
return func(r *AutoRelay) error {
r.discover = discover

Loading…
Cancel
Save