mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
payload: limit the number of possible addresses
This commit is contained in:
parent
0120a8f239
commit
5abec520c7
2 changed files with 7 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue