NetAddress.Same checks ID or DialString
This commit is contained in:
parent
f9e4f6eb6b
commit
68237911ba
|
@ -127,12 +127,25 @@ func NewNetAddressIPPort(ip net.IP, port uint16) *NetAddress {
|
|||
return na
|
||||
}
|
||||
|
||||
// Equals reports whether na and other are the same addresses.
|
||||
// Equals reports whether na and other are the same addresses,
|
||||
// including their ID, IP, and Port.
|
||||
func (na *NetAddress) Equals(other interface{}) bool {
|
||||
if o, ok := other.(*NetAddress); ok {
|
||||
return na.String() == o.String()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Same returns true is na has the same non-empty ID or DialString as other.
|
||||
func (na *NetAddress) Same(other interface{}) bool {
|
||||
if o, ok := other.(*NetAddress); ok {
|
||||
if na.DialString() == o.DialString() {
|
||||
return true
|
||||
}
|
||||
if na.ID != "" && na.ID == o.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -318,18 +318,16 @@ func (sw *Switch) IsDialing(id ID) bool {
|
|||
// DialPeersAsync dials a list of peers asynchronously in random order (optionally, making them persistent).
|
||||
func (sw *Switch) DialPeersAsync(addrBook *AddrBook, peers []string, persistent bool) error {
|
||||
netAddrs, errs := NewNetAddressStrings(peers)
|
||||
// TODO: IDs
|
||||
for _, err := range errs {
|
||||
sw.Logger.Error("Error in peer's address", "err", err)
|
||||
}
|
||||
|
||||
if addrBook != nil {
|
||||
// add peers to `addrBook`
|
||||
ourAddrS := sw.nodeInfo.ListenAddr
|
||||
ourAddr, _ := NewNetAddressString(ourAddrS)
|
||||
ourAddr := sw.nodeInfo.NetAddress()
|
||||
for _, netAddr := range netAddrs {
|
||||
// do not add ourselves
|
||||
if netAddr.Equals(ourAddr) {
|
||||
// do not add our address or ID
|
||||
if netAddr.Same(ourAddr) {
|
||||
continue
|
||||
}
|
||||
addrBook.AddAddress(netAddr, ourAddr)
|
||||
|
|
Loading…
Reference in New Issue