mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
9d375969d1
* Use log.WithError static analysis from #11143 and fix all violations * Fix another log violation after pulling from develop * Update beacon-chain/sync/pending_blocks_queue.go Co-authored-by: Potuz <potuz@prysmaticlabs.com> * @potuz feedback * Copy paste fail * fix tests Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
39 lines
939 B
Go
39 lines
939 B
Go
package p2p
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/libp2p/go-libp2p/config"
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
)
|
|
|
|
// withRelayAddrs returns an AddrFactory which will return Multiaddr via
|
|
// specified relay string in addition to existing MultiAddr.
|
|
func withRelayAddrs(relay string) config.AddrsFactory {
|
|
return func(addrs []ma.Multiaddr) []ma.Multiaddr {
|
|
if relay == "" {
|
|
return addrs
|
|
}
|
|
|
|
var relayAddrs []ma.Multiaddr
|
|
|
|
for _, a := range addrs {
|
|
if strings.Contains(a.String(), "/p2p-circuit") {
|
|
continue
|
|
}
|
|
relayAddr, err := ma.NewMultiaddr(relay + "/p2p-circuit" + a.String())
|
|
if err != nil {
|
|
log.WithError(err).Error("Failed to create multiaddress for relay node")
|
|
} else {
|
|
relayAddrs = append(relayAddrs, relayAddr)
|
|
}
|
|
}
|
|
|
|
if len(relayAddrs) == 0 {
|
|
log.Warn("Addresses via relay node are zero - using non-relay addresses")
|
|
return addrs
|
|
}
|
|
return append(addrs, relayAddrs...)
|
|
}
|
|
}
|