mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 11:41:48 +00:00
network: treat unsolicited addr commands as errors
See neo-project/neo#2097.
This commit is contained in:
parent
619b6d4132
commit
2ce3c8b75f
4 changed files with 41 additions and 0 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"go.uber.org/atomic"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -58,6 +59,9 @@ type TCPPeer struct {
|
|||
|
||||
wg sync.WaitGroup
|
||||
|
||||
// track outstanding getaddr requests.
|
||||
getAddrSent atomic.Int32
|
||||
|
||||
// number of sent pings.
|
||||
pingSent int
|
||||
pingTimer *time.Timer
|
||||
|
@ -455,3 +459,16 @@ func (p *TCPPeer) HandlePong(pong *payload.Ping) error {
|
|||
p.lastBlockIndex = pong.LastBlockIndex
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddGetAddrSent increments internal outstanding getaddr requests counter. The
|
||||
// peer can only send then one addr reply per getaddr request.
|
||||
func (p *TCPPeer) AddGetAddrSent() {
|
||||
p.getAddrSent.Inc()
|
||||
}
|
||||
|
||||
// CanProcessAddr decrements internal outstanding getaddr requests counter and
|
||||
// answers whether the addr command from the peer can be safely processed.
|
||||
func (p *TCPPeer) CanProcessAddr() bool {
|
||||
v := p.getAddrSent.Dec()
|
||||
return v >= 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue