payload: limit the number of possible addresses

This commit is contained in:
Roman Khimov 2020-10-07 23:29:20 +03:00
parent 0120a8f239
commit 5abec520c7
2 changed files with 7 additions and 4 deletions

View file

@ -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.

View file

@ -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()