mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-18 11:15:36 +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"
|
"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.
|
// AddressAndTime payload.
|
||||||
type AddressAndTime struct {
|
type AddressAndTime struct {
|
||||||
Timestamp uint32
|
Timestamp uint32
|
||||||
|
@ -75,7 +79,7 @@ func NewAddressList(n int) *AddressList {
|
||||||
|
|
||||||
// DecodeBinary implements Serializable interface.
|
// DecodeBinary implements Serializable interface.
|
||||||
func (p *AddressList) DecodeBinary(br *io.BinReader) {
|
func (p *AddressList) DecodeBinary(br *io.BinReader) {
|
||||||
br.ReadArray(&p.Addrs)
|
br.ReadArray(&p.Addrs, MaxAddrsCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeBinary implements Serializable interface.
|
// EncodeBinary implements Serializable interface.
|
||||||
|
|
|
@ -29,7 +29,6 @@ const (
|
||||||
defaultAttemptConnPeers = 20
|
defaultAttemptConnPeers = 20
|
||||||
defaultMaxPeers = 100
|
defaultMaxPeers = 100
|
||||||
maxBlockBatch = 200
|
maxBlockBatch = 200
|
||||||
maxAddrsToSend = 200
|
|
||||||
minPoolCount = 30
|
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.
|
// handleGetAddrCmd sends to the peer some good addresses that we know of.
|
||||||
func (s *Server) handleGetAddrCmd(p Peer) error {
|
func (s *Server) handleGetAddrCmd(p Peer) error {
|
||||||
addrs := s.discovery.GoodPeers()
|
addrs := s.discovery.GoodPeers()
|
||||||
if len(addrs) > maxAddrsToSend {
|
if len(addrs) > payload.MaxAddrsCount {
|
||||||
addrs = addrs[:maxAddrsToSend]
|
addrs = addrs[:payload.MaxAddrsCount]
|
||||||
}
|
}
|
||||||
alist := payload.NewAddressList(len(addrs))
|
alist := payload.NewAddressList(len(addrs))
|
||||||
ts := time.Now()
|
ts := time.Now()
|
||||||
|
|
Loading…
Add table
Reference in a new issue