mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-04 15:17:02 +00:00
remove RemoteAddr from NodeInfo
This commit is contained in:
@@ -206,8 +206,6 @@ func (p *peer) HandshakeTimeout(ourNodeInfo *NodeInfo, timeout time.Duration) er
|
||||
return errors.Wrap(err, "Error removing deadline")
|
||||
}
|
||||
|
||||
peerNodeInfo.RemoteAddr = p.Addr().String()
|
||||
|
||||
p.nodeInfo = peerNodeInfo
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
func randPeer() *peer {
|
||||
return &peer{
|
||||
nodeInfo: &NodeInfo{
|
||||
RemoteAddr: cmn.Fmt("%v.%v.%v.%v:46656", rand.Int()%256, rand.Int()%256, rand.Int()%256, rand.Int()%256),
|
||||
ListenAddr: cmn.Fmt("%v.%v.%v.%v:46656", rand.Int()%256, rand.Int()%256, rand.Int()%256, rand.Int()%256),
|
||||
PubKey: crypto.GenPrivKeyEd25519().Wrap().PubKey(),
|
||||
},
|
||||
|
||||
+5
-4
@@ -142,10 +142,11 @@ func (p *remotePeer) accept(l net.Listener) {
|
||||
golog.Fatalf("Failed to create a peer: %+v", err)
|
||||
}
|
||||
err = peer.HandshakeTimeout(&NodeInfo{
|
||||
PubKey: p.PrivKey.PubKey(),
|
||||
Moniker: "remote_peer",
|
||||
Network: "testing",
|
||||
Version: "123.123.123",
|
||||
PubKey: p.PrivKey.PubKey(),
|
||||
Moniker: "remote_peer",
|
||||
Network: "testing",
|
||||
Version: "123.123.123",
|
||||
ListenAddr: l.Addr().String(),
|
||||
}, 1*time.Second)
|
||||
if err != nil {
|
||||
golog.Fatalf("Failed to perform handshake: %+v", err)
|
||||
|
||||
+9
-15
@@ -129,17 +129,11 @@ func (r *PEXReactor) RemovePeer(p Peer, reason interface{}) {
|
||||
|
||||
// Receive implements Reactor by handling incoming PEX messages.
|
||||
func (r *PEXReactor) Receive(chID byte, src Peer, msgBytes []byte) {
|
||||
srcAddrStr := src.NodeInfo().RemoteAddr
|
||||
srcAddr, err := NewNetAddressString(srcAddrStr)
|
||||
if err != nil {
|
||||
// this should never happen. TODO: cancel conn
|
||||
r.Logger.Error("Error in Receive: invalid peer address", "addr", srcAddrStr, "err", err)
|
||||
return
|
||||
}
|
||||
srcAddr := src.NodeInfo().NetAddress()
|
||||
|
||||
r.IncrementMsgCountForPeer(srcAddrStr)
|
||||
if r.ReachedMaxMsgCountForPeer(srcAddrStr) {
|
||||
r.Logger.Error("Maximum number of messages reached for peer", "peer", srcAddrStr)
|
||||
r.IncrementMsgCountForPeer(srcAddr.ID)
|
||||
if r.ReachedMaxMsgCountForPeer(srcAddr.ID) {
|
||||
r.Logger.Error("Maximum number of messages reached for peer", "peer", srcAddr)
|
||||
// TODO remove src from peers?
|
||||
return
|
||||
}
|
||||
@@ -192,19 +186,19 @@ func (r *PEXReactor) SetMaxMsgCountByPeer(v uint16) {
|
||||
// ReachedMaxMsgCountForPeer returns true if we received too many
|
||||
// messages from peer with address `addr`.
|
||||
// NOTE: assumes the value in the CMap is non-nil
|
||||
func (r *PEXReactor) ReachedMaxMsgCountForPeer(addr string) bool {
|
||||
return r.msgCountByPeer.Get(addr).(uint16) >= r.maxMsgCountByPeer
|
||||
func (r *PEXReactor) ReachedMaxMsgCountForPeer(peerID ID) bool {
|
||||
return r.msgCountByPeer.Get(string(peerID)).(uint16) >= r.maxMsgCountByPeer
|
||||
}
|
||||
|
||||
// Increment or initialize the msg count for the peer in the CMap
|
||||
func (r *PEXReactor) IncrementMsgCountForPeer(addr string) {
|
||||
func (r *PEXReactor) IncrementMsgCountForPeer(peerID ID) {
|
||||
var count uint16
|
||||
countI := r.msgCountByPeer.Get(addr)
|
||||
countI := r.msgCountByPeer.Get(string(peerID))
|
||||
if countI != nil {
|
||||
count = countI.(uint16)
|
||||
}
|
||||
count++
|
||||
r.msgCountByPeer.Set(addr, count)
|
||||
r.msgCountByPeer.Set(string(peerID), count)
|
||||
}
|
||||
|
||||
// Ensures that sufficient peers are connected. (continuous)
|
||||
|
||||
@@ -184,7 +184,7 @@ func TestPEXReactorAbuseFromPeer(t *testing.T) {
|
||||
r.Receive(PexChannel, peer, msg)
|
||||
}
|
||||
|
||||
assert.True(r.ReachedMaxMsgCountForPeer(peer.NodeInfo().ListenAddr))
|
||||
assert.True(r.ReachedMaxMsgCountForPeer(peer.NodeInfo().ID()))
|
||||
}
|
||||
|
||||
func TestPEXReactorUsesSeedsIfNeeded(t *testing.T) {
|
||||
@@ -243,8 +243,7 @@ func createRandomPeer(outbound bool) *peer {
|
||||
addr, netAddr := createRoutableAddr()
|
||||
p := &peer{
|
||||
nodeInfo: &NodeInfo{
|
||||
ListenAddr: addr,
|
||||
RemoteAddr: netAddr.String(),
|
||||
ListenAddr: netAddr.String(),
|
||||
PubKey: crypto.GenPrivKeyEd25519().Wrap().PubKey(),
|
||||
},
|
||||
outbound: outbound,
|
||||
|
||||
@@ -615,7 +615,6 @@ func makeSwitch(cfg *cfg.P2PConfig, i int, network, version string, initSwitch f
|
||||
Moniker: cmn.Fmt("switch%d", i),
|
||||
Network: network,
|
||||
Version: version,
|
||||
RemoteAddr: cmn.Fmt("%v:%v", network, rand.Intn(64512)+1023),
|
||||
ListenAddr: cmn.Fmt("%v:%v", network, rand.Intn(64512)+1023),
|
||||
})
|
||||
s.SetNodeKey(nodeKey)
|
||||
|
||||
+5
-2
@@ -17,7 +17,6 @@ type NodeInfo struct {
|
||||
PubKey crypto.PubKey `json:"pub_key"` // authenticated pubkey
|
||||
Moniker string `json:"moniker"` // arbitrary moniker
|
||||
Network string `json:"network"` // network/chain ID
|
||||
RemoteAddr string `json:"remote_addr"` // address for the connection
|
||||
ListenAddr string `json:"listen_addr"` // accepting incoming
|
||||
Version string `json:"version"` // major.minor.revision
|
||||
Other []string `json:"other"` // other application specific data
|
||||
@@ -56,6 +55,10 @@ func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (info *NodeInfo) ID() ID {
|
||||
return PubKeyToID(info.PubKey)
|
||||
}
|
||||
|
||||
func (info *NodeInfo) NetAddress() *NetAddress {
|
||||
id := PubKeyToID(info.PubKey)
|
||||
addr := info.ListenAddr
|
||||
@@ -81,7 +84,7 @@ func (info *NodeInfo) ListenPort() int {
|
||||
}
|
||||
|
||||
func (info NodeInfo) String() string {
|
||||
return fmt.Sprintf("NodeInfo{pk: %v, moniker: %v, network: %v [remote %v, listen %v], version: %v (%v)}", info.PubKey, info.Moniker, info.Network, info.RemoteAddr, info.ListenAddr, info.Version, info.Other)
|
||||
return fmt.Sprintf("NodeInfo{pk: %v, moniker: %v, network: %v [listen %v], version: %v (%v)}", info.PubKey, info.Moniker, info.Network, info.ListenAddr, info.Version, info.Other)
|
||||
}
|
||||
|
||||
func splitVersion(version string) (string, string, string, error) {
|
||||
|
||||
Reference in New Issue
Block a user