mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47: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) {
|
||||
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 {
|
||||
if addr == "" {
|
||||
// Ignore empty entries
|
||||
@ -116,20 +124,17 @@ func parseBootStrapAddrs(addrs []string) (discv5Nodes []string, kadDHTNodes []st
|
||||
}
|
||||
_, err := enode.Parse(enode.ValidSchemes, addr)
|
||||
if err == nil {
|
||||
discv5Nodes = append(discv5Nodes, addr)
|
||||
enodeString = append(enodeString, addr)
|
||||
continue
|
||||
}
|
||||
_, err = multiAddrFromString(addr)
|
||||
if err == nil {
|
||||
kadDHTNodes = append(kadDHTNodes, addr)
|
||||
multiAddrString = append(multiAddrString, addr)
|
||||
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 {
|
||||
log.Warn("No bootstrap addresses supplied")
|
||||
}
|
||||
return discv5Nodes, kadDHTNodes
|
||||
return enodeString, multiAddrString
|
||||
}
|
||||
|
||||
func convertToMultiAddr(nodes []*enode.Node) []ma.Multiaddr {
|
||||
@ -168,15 +173,27 @@ func convertToSingleMultiAddr(node *enode.Node) (ma.Multiaddr, error) {
|
||||
return multiAddr, nil
|
||||
}
|
||||
|
||||
func manyMultiAddrsFromString(addrs []string) ([]ma.Multiaddr, error) {
|
||||
func peersFromStringAddrs(addrs []string) ([]ma.Multiaddr, error) {
|
||||
var allAddrs []ma.Multiaddr
|
||||
for _, stringAddr := range addrs {
|
||||
enodeString, multiAddrString := parseGenericAddrs(addrs)
|
||||
for _, stringAddr := range multiAddrString {
|
||||
addr, err := multiAddrFromString(stringAddr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Could not get multiaddr from string")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ func (s *Service) Start() {
|
||||
s.started = true
|
||||
|
||||
if len(s.cfg.StaticPeers) > 0 {
|
||||
addrs, err := manyMultiAddrsFromString(s.cfg.StaticPeers)
|
||||
addrs, err := peersFromStringAddrs(s.cfg.StaticPeers)
|
||||
if err != nil {
|
||||
log.Errorf("Could not connect to static peer: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user