From 5abec520c74cf9e8c677b3eb38feda8fe9bad80a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 7 Oct 2020 23:29:20 +0300 Subject: [PATCH] payload: limit the number of possible addresses --- pkg/network/payload/address.go | 6 +++++- pkg/network/server.go | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/network/payload/address.go b/pkg/network/payload/address.go index 6608b2cf6..04e925aed 100644 --- a/pkg/network/payload/address.go +++ b/pkg/network/payload/address.go @@ -10,6 +10,10 @@ import ( "github.com/nspcc-dev/neo-go/pkg/network/capability" ) +// MaxAddrsCount is the maximum number of addresses that could be packed into +// one payload. +const MaxAddrsCount = 200 + // AddressAndTime payload. type AddressAndTime struct { Timestamp uint32 @@ -75,7 +79,7 @@ func NewAddressList(n int) *AddressList { // DecodeBinary implements Serializable interface. func (p *AddressList) DecodeBinary(br *io.BinReader) { - br.ReadArray(&p.Addrs) + br.ReadArray(&p.Addrs, MaxAddrsCount) } // EncodeBinary implements Serializable interface. diff --git a/pkg/network/server.go b/pkg/network/server.go index 467c128f3..e8feac478 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -29,7 +29,6 @@ const ( defaultAttemptConnPeers = 20 defaultMaxPeers = 100 maxBlockBatch = 200 - maxAddrsToSend = 200 minPoolCount = 30 ) @@ -690,8 +689,8 @@ func (s *Server) handleAddrCmd(p Peer, addrs *payload.AddressList) error { // handleGetAddrCmd sends to the peer some good addresses that we know of. func (s *Server) handleGetAddrCmd(p Peer) error { addrs := s.discovery.GoodPeers() - if len(addrs) > maxAddrsToSend { - addrs = addrs[:maxAddrsToSend] + if len(addrs) > payload.MaxAddrsCount { + addrs = addrs[:payload.MaxAddrsCount] } alist := payload.NewAddressList(len(addrs)) ts := time.Now()