network: treat unsolicited addr commands as errors

See neo-project/neo#2097.
This commit is contained in:
Roman Khimov 2020-11-25 13:34:38 +03:00
parent 619b6d4132
commit 2ce3c8b75f
4 changed files with 41 additions and 0 deletions

View file

@ -680,6 +680,9 @@ func (s *Server) handleTxCmd(tx *transaction.Transaction) error {
// handleAddrCmd will process received addresses.
func (s *Server) handleAddrCmd(p Peer, addrs *payload.AddressList) error {
if !p.CanProcessAddr() {
return errors.New("unexpected addr received")
}
for _, a := range addrs.Addrs {
addr, err := a.GetTCPAddress()
if err == nil {
@ -830,6 +833,9 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, []byte) e
if peerOK != nil && !peerOK(peer) {
continue
}
if msg.Command == CMDGetAddr {
peer.AddGetAddrSent()
}
// Who cares about these messages anyway?
_ = send(peer, pkt)
}