Browse Source

use combination of IP and port, not just IP

pull/1350/head
Anton Kaliaev 6 years ago
parent
commit
5a2fa71b03
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 17 additions and 24 deletions
  1. +0
    -7
      p2p/node_info.go
  2. +17
    -17
      p2p/switch.go

+ 0
- 7
p2p/node_info.go View File

@ -2,7 +2,6 @@ package p2p
import (
"fmt"
"net"
"strings"
crypto "github.com/tendermint/go-crypto"
@ -113,12 +112,6 @@ func (info NodeInfo) ID() ID {
return PubKeyToID(info.PubKey)
}
// IP returns node listen addr's IP.
func (info NodeInfo) IP() net.IP {
hostPort := strings.SplitN(info.ListenAddr, ":", 2)
return net.ParseIP(hostPort[0])
}
// NetAddress returns a NetAddress derived from the NodeInfo -
// it includes the authenticated peer ID and the self-reported
// ListenAddr. Note that the ListenAddr is not authenticated and


+ 17
- 17
p2p/switch.go View File

@ -48,18 +48,18 @@ type AddrBook interface {
type Switch struct {
cmn.BaseService
config *cfg.P2PConfig
peerConfig *PeerConfig
listeners []Listener
reactors map[string]Reactor
chDescs []*conn.ChannelDescriptor
reactorsByCh map[byte]Reactor
peers *PeerSet
dialing *cmn.CMap
nodeInfo NodeInfo // our node info
nodeKey *NodeKey // our node privkey
nodeIP net.IP // our IP
addrBook AddrBook
config *cfg.P2PConfig
peerConfig *PeerConfig
listeners []Listener
reactors map[string]Reactor
chDescs []*conn.ChannelDescriptor
reactorsByCh map[byte]Reactor
peers *PeerSet
dialing *cmn.CMap
nodeInfo NodeInfo // our node info
nodeKey *NodeKey // our node privkey
nodePublicAddr *NetAddress
addrBook AddrBook
filterConnByAddr func(net.Addr) error
filterConnByID func(ID) error
@ -149,7 +149,7 @@ func (sw *Switch) IsListening() bool {
// NOTE: Not goroutine safe.
func (sw *Switch) SetNodeInfo(nodeInfo NodeInfo) {
sw.nodeInfo = nodeInfo
sw.nodeIP = nodeInfo.IP()
sw.nodePublicAddr = nodeInfo.NetAddress()
}
// NodeInfo returns the switch's NodeInfo.
@ -384,7 +384,7 @@ func (sw *Switch) DialPeersAsync(addrBook AddrBook, peers []string, persistent b
// If `persistent == true`, the switch will always try to reconnect to this peer if the connection ever fails.
func (sw *Switch) DialPeerWithAddress(addr *NetAddress, persistent bool) error {
// do not dial ourselves
if addr.IP == sw.nodeIP {
if addr.Same(sw.nodePublicAddr) {
return ErrSwitchConnectToSelf
}
@ -529,9 +529,9 @@ func (sw *Switch) addPeer(pc peerConn) error {
// Avoid self
if sw.nodeKey.ID() == peerID {
// overwrite current IP to avoid dialing ourselves again
// it means original nodeIP was different from public one
sw.nodeIP = peerNodeInfo.IP()
// overwrite current addr to avoid dialing ourselves again
// it means original nodePublicAddr was different from public one
sw.nodePublicAddr = peerNodeInfo.NetAddress()
return ErrSwitchConnectToSelf
}


Loading…
Cancel
Save