prysm-pulse/shared/p2p/addr_factory.go
Preston Van Loon 612bb38077 Cross p2p spans, more spans, synchronous attestations, minor fixes (#2009)
* Fix assignments bug where validators don't retry for assignments on failure

* synch only please

* trying to fix state issues

* trying random stuff

* do not explode

* use ctx

* working build, failing tests

* broadcast local addrs as well as relay addrs

* fixed p2p tests, more tests to fix still

* another test fixed, log warning instead of throw error

* Fix last tests

* godoc

* add test for broadcast in apply fork choiec

* remove unneeded code

* remove tracer adapter, not needed

* remove extra stuff

* remove any

* revert addr_factory

* revert addr_factory

* Revert "revert addr_factory"

This reverts commit e93fb706494a1070158b8db31e67146d6b0648ad.

* Revert "revert addr_factory"

This reverts commit dedaa405559cc818698870c4e4570953367f1e3c.

* revert removal of this code

* unused param
2019-03-17 10:56:05 +08:00

37 lines
906 B
Go

package p2p
import (
"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 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 append(addrs, relayAddrs...)
}
}