Change AddAddressByIP to return an error.
This commit is contained in:
parent
f7ce37f8c1
commit
3a45ec1058
1 changed files with 5 additions and 8 deletions
|
@ -662,29 +662,26 @@ func (a *AddrManager) AddAddress(addr *btcwire.NetAddress,
|
||||||
|
|
||||||
// AddAddressByIP adds an address where we are given an ip:port and not a
|
// AddAddressByIP adds an address where we are given an ip:port and not a
|
||||||
// btcwire.NetAddress.
|
// btcwire.NetAddress.
|
||||||
func (a *AddrManager) AddAddressByIP(addrIP string) {
|
func (a *AddrManager) AddAddressByIP(addrIP string) error {
|
||||||
// Split IP and port
|
// Split IP and port
|
||||||
addr, portStr, err := net.SplitHostPort(addrIP)
|
addr, portStr, err := net.SplitHostPort(addrIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("AddADddressByIP given bullshit adddress (%s): %v",
|
return err
|
||||||
err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Put it in btcwire.Netaddress
|
// Put it in btcwire.Netaddress
|
||||||
var na btcwire.NetAddress
|
var na btcwire.NetAddress
|
||||||
na.Timestamp = time.Now()
|
na.Timestamp = time.Now()
|
||||||
na.IP = net.ParseIP(addr)
|
na.IP = net.ParseIP(addr)
|
||||||
if na.IP == nil {
|
if na.IP == nil {
|
||||||
log.Error("Invalid ip address:", addr)
|
return fmt.Errorf("invalid ip address %s", addr)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
port, err := strconv.ParseUint(portStr, 10, 0)
|
port, err := strconv.ParseUint(portStr, 10, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Invalid port: ", portStr, err)
|
return fmt.Errorf("invalid port %s: %v", portStr, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
na.Port = uint16(port)
|
na.Port = uint16(port)
|
||||||
a.AddAddress(&na, &na) // XXX use correct src address
|
a.AddAddress(&na, &na) // XXX use correct src address
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeedMoreAddresses returns whether or not the address manager needs more
|
// NeedMoreAddresses returns whether or not the address manager needs more
|
||||||
|
|
Loading…
Reference in a new issue