Skip to content

Commit

Permalink
Use 'NewPeerInfosFromString' for resolving 'host:port' records by '-p…
Browse files Browse the repository at this point in the history
…eers' CLI parameter.
  • Loading branch information
nickeskov committed Dec 2, 2024
1 parent a2eaf3d commit f03d702
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,21 @@ func spawnPeersByAddresses(ctx context.Context, addressesByComma string, pm *pee
}
addresses := strings.Split(addressesByComma, ",")
for _, addr := range addresses {
tcpAddr := proto.NewTCPAddrFromString(addr)
if tcpAddr.Empty() {
// That means that configuration parameter is invalid
return errors.Errorf("Failed to parse TCPAddr from string %q", tcpAddr.String())
peerInfos, err := proto.NewPeerInfosFromString(addr)
if err != nil {
return errors.Wrapf(err, "failed to resolve TCP addresses from string %q", addr)
}
if pErr := pm.AddAddress(ctx, tcpAddr); pErr != nil {
// That means that we have problems with peers storage
return errors.Wrapf(pErr, "failed to add address %q into known peers storage", tcpAddr.String())
for _, pi := range peerInfos {
tcpAddr := proto.NewTCPAddr(pi.Addr, int(pi.Port))
if tcpAddr.Empty() {
return errors.Errorf("failed to create TCP address from IP %q and port %d",
fmt.Stringer(pi.Addr), pi.Port,
)
}
if pErr := pm.AddAddress(ctx, tcpAddr); pErr != nil {
// That means that we have problems with peers storage
return errors.Wrapf(pErr, "failed to add address %q into known peers storage", tcpAddr.String())
}
}
}
return nil
Expand Down

0 comments on commit f03d702

Please sign in to comment.