Browse Source

tolerate unresolvable seeds (Refs #880)

pull/933/head
Anton Kaliaev 7 years ago
parent
commit
c609b18698
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 15 additions and 16 deletions
  1. +9
    -8
      p2p/netaddress.go
  2. +3
    -5
      p2p/netaddress_test.go
  3. +3
    -3
      p2p/switch.go

+ 9
- 8
p2p/netaddress.go View File

@ -5,8 +5,8 @@
package p2p
import (
"errors"
"flag"
"fmt"
"net"
"strconv"
"time"
@ -45,7 +45,6 @@ func NewNetAddress(addr net.Addr) *NetAddress {
// address in the form of "IP:Port". Also resolves the host if host
// is not an IP.
func NewNetAddressString(addr string) (*NetAddress, error) {
host, portStr, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
@ -73,16 +72,18 @@ func NewNetAddressString(addr string) (*NetAddress, error) {
// NewNetAddressStrings returns an array of NetAddress'es build using
// the provided strings.
func NewNetAddressStrings(addrs []string) ([]*NetAddress, error) {
netAddrs := make([]*NetAddress, len(addrs))
for i, addr := range addrs {
func NewNetAddressStrings(addrs []string) ([]*NetAddress, []error) {
netAddrs := make([]*NetAddress, 0)
errs := make([]error, 0)
for _, addr := range addrs {
netAddr, err := NewNetAddressString(addr)
if err != nil {
return nil, errors.New(cmn.Fmt("Error in address %s: %v", addr, err))
errs = append(errs, fmt.Errorf("Error in address %s: %v", addr, err))
} else {
netAddrs = append(netAddrs, netAddr)
}
netAddrs[i] = netAddr
}
return netAddrs, nil
return netAddrs, errs
}
// NewNetAddressIPPort returns a new NetAddress using the provided IP


+ 3
- 5
p2p/netaddress_test.go View File

@ -51,11 +51,9 @@ func TestNewNetAddressString(t *testing.T) {
}
func TestNewNetAddressStrings(t *testing.T) {
assert, require := assert.New(t), require.New(t)
addrs, err := NewNetAddressStrings([]string{"127.0.0.1:8080", "127.0.0.2:8080"})
require.Nil(err)
assert.Equal(2, len(addrs))
addrs, errs := NewNetAddressStrings([]string{"127.0.0.1:8080", "127.0.0.2:8080"})
assert.Len(t, errs, 0)
assert.Equal(t, 2, len(addrs))
}
func TestNewNetAddressIPPort(t *testing.T) {


+ 3
- 3
p2p/switch.go View File

@ -298,9 +298,9 @@ func (sw *Switch) startInitPeer(peer *peer) {
// DialSeeds dials a list of seeds asynchronously in random order.
func (sw *Switch) DialSeeds(addrBook *AddrBook, seeds []string) error {
netAddrs, err := NewNetAddressStrings(seeds)
if err != nil {
return err
netAddrs, errs := NewNetAddressStrings(seeds)
for _, err := range errs {
sw.Logger.Error("Error in seed's address", "err", err)
}
if addrBook != nil {


Loading…
Cancel
Save