mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-29 06:37:17 +00:00
0559d01261
* Preliminary support for relay nodes * lint * Add comment, remove TODO * work on relay address factory * dial relay node, if available * forgot new files * fix service registry breakage * added logging * Added a peer count with prometheus * always start mDNS * fix lint
37 lines
858 B
Go
37 lines
858 B
Go
package p2p
|
|
|
|
import (
|
|
"github.com/libp2p/go-libp2p/config"
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
// relayAddrsOnly returns an AddrFactory which will only return Multiaddr via
|
|
// specified relay string.
|
|
func relayAddrsOnly(relay string) config.AddrsFactory {
|
|
return func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
|
if relay == "" {
|
|
return addrs
|
|
}
|
|
|
|
var relayAddrs []ma.Multiaddr
|
|
|
|
for _, a := range addrs {
|
|
if a.String() == "/p2p-circuit" {
|
|
continue
|
|
}
|
|
relayAddr, err := ma.NewMultiaddr(relay + "/p2p-circuit" + a.String())
|
|
if err != nil {
|
|
log.Errorf("Failed to create multiaddress for relay node: %v", err)
|
|
} else {
|
|
relayAddrs = append(relayAddrs, relayAddr)
|
|
}
|
|
}
|
|
|
|
if len(relayAddrs) == 0 {
|
|
log.Warn("Addresses via relay node are zero. Using non-relay addresses")
|
|
return addrs
|
|
}
|
|
return relayAddrs
|
|
}
|
|
}
|