mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
add multi-options (#5012)
This commit is contained in:
parent
5961aaf588
commit
f3dc113dba
@ -109,6 +109,14 @@ func startDHTDiscovery(host core.Host, bootstrapAddr string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []string) {
|
func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []string) {
|
||||||
|
discv5Nodes, kadDHTNodes = parseGenericAddrs(addrs)
|
||||||
|
if len(discv5Nodes) == 0 && len(kadDHTNodes) == 0 {
|
||||||
|
log.Warn("No bootstrap addresses supplied")
|
||||||
|
}
|
||||||
|
return discv5Nodes, kadDHTNodes
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGenericAddrs(addrs []string) (enodeString []string, multiAddrString []string) {
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
// Ignore empty entries
|
// Ignore empty entries
|
||||||
@ -116,20 +124,17 @@ func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []st
|
|||||||
}
|
}
|
||||||
_, err := enode.Parse(enode.ValidSchemes, addr)
|
_, err := enode.Parse(enode.ValidSchemes, addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
discv5Nodes = append(discv5Nodes, addr)
|
enodeString = append(enodeString, addr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, err = multiAddrFromString(addr)
|
_, err = multiAddrFromString(addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
kadDHTNodes = append(kadDHTNodes, addr)
|
multiAddrString = append(multiAddrString, addr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Errorf("Invalid bootstrap address of %s provided", addr)
|
log.Errorf("Invalid address of %s provided", addr)
|
||||||
}
|
}
|
||||||
if len(discv5Nodes) == 0 && len(kadDHTNodes) == 0 {
|
return enodeString, multiAddrString
|
||||||
log.Warn("No bootstrap addresses supplied")
|
|
||||||
}
|
|
||||||
return discv5Nodes, kadDHTNodes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertToMultiAddr(nodes []*enode.Node) []ma.Multiaddr {
|
func convertToMultiAddr(nodes []*enode.Node) []ma.Multiaddr {
|
||||||
@ -168,15 +173,27 @@ func convertToSingleMultiAddr(node *enode.Node) (ma.Multiaddr, error) {
|
|||||||
return multiAddr, nil
|
return multiAddr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func manyMultiAddrsFromString(addrs []string) ([]ma.Multiaddr, error) {
|
func peersFromStringAddrs(addrs []string) ([]ma.Multiaddr, error) {
|
||||||
var allAddrs []ma.Multiaddr
|
var allAddrs []ma.Multiaddr
|
||||||
for _, stringAddr := range addrs {
|
enodeString, multiAddrString := parseGenericAddrs(addrs)
|
||||||
|
for _, stringAddr := range multiAddrString {
|
||||||
addr, err := multiAddrFromString(stringAddr)
|
addr, err := multiAddrFromString(stringAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "Could not get multiaddr from string")
|
return nil, errors.Wrapf(err, "Could not get multiaddr from string")
|
||||||
}
|
}
|
||||||
allAddrs = append(allAddrs, addr)
|
allAddrs = append(allAddrs, addr)
|
||||||
}
|
}
|
||||||
|
for _, stringAddr := range enodeString {
|
||||||
|
enodeAddr, err := enode.Parse(enode.ValidSchemes, stringAddr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "Could not get enode from string")
|
||||||
|
}
|
||||||
|
addr, err := convertToSingleMultiAddr(enodeAddr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "Could not get multiaddr")
|
||||||
|
}
|
||||||
|
allAddrs = append(allAddrs, addr)
|
||||||
|
}
|
||||||
return allAddrs, nil
|
return allAddrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ func (s *Service) Start() {
|
|||||||
s.started = true
|
s.started = true
|
||||||
|
|
||||||
if len(s.cfg.StaticPeers) > 0 {
|
if len(s.cfg.StaticPeers) > 0 {
|
||||||
addrs, err := manyMultiAddrsFromString(s.cfg.StaticPeers)
|
addrs, err := peersFromStringAddrs(s.cfg.StaticPeers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Could not connect to static peer: %v", err)
|
log.Errorf("Could not connect to static peer: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user