Browse Source

p2p: some fixes re @odeke-em issues #813,#816,#817

pull/824/head
Ethan Buchman 7 years ago
parent
commit
c931279960
3 changed files with 12 additions and 4 deletions
  1. +4
    -1
      p2p/peer.go
  2. +7
    -2
      p2p/pex_reactor.go
  3. +1
    -1
      p2p/switch.go

+ 4
- 1
p2p/peer.go View File

@ -210,7 +210,7 @@ func (p *peer) PubKey() crypto.PubKeyEd25519 {
if p.config.AuthEnc {
return p.conn.(*SecretConnection).RemotePubKey()
}
if p.NodeInfo == nil {
if p.NodeInfo() == nil {
panic("Attempt to get peer's PubKey before calling Handshake")
}
return p.PubKey()
@ -306,6 +306,9 @@ func (p *peer) Key() string {
// NodeInfo returns a copy of the peer's NodeInfo.
func (p *peer) NodeInfo() *NodeInfo {
if p.nodeInfo == nil {
return nil
}
n := *p.nodeInfo // copy
return &n
}


+ 7
- 2
p2p/pex_reactor.go View File

@ -103,7 +103,7 @@ func (r *PEXReactor) AddPeer(p Peer) {
} else { // For inbound connections, the peer is its own source
addr, err := NewNetAddressString(p.NodeInfo().ListenAddr)
if err != nil {
// this should never happen
// peer gave us a bad ListenAddr. TODO: punish
r.Logger.Error("Error in AddPeer: invalid peer address", "addr", p.NodeInfo().ListenAddr, "err", err)
return
}
@ -120,7 +120,12 @@ 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, _ := NewNetAddressString(srcAddrStr)
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
}
r.IncrementMsgCountForPeer(srcAddrStr)
if r.ReachedMaxMsgCountForPeer(srcAddrStr) {


+ 1
- 1
p2p/switch.go View File

@ -24,7 +24,7 @@ type Reactor interface {
GetChannels() []*ChannelDescriptor
AddPeer(peer Peer)
RemovePeer(peer Peer, reason interface{})
Receive(chID byte, peer Peer, msgBytes []byte)
Receive(chID byte, peer Peer, msgBytes []byte) // CONTRACT: msgBytes are not nil
}
//--------------------------------------


Loading…
Cancel
Save