mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 03:06:16 +00:00
network/config: redesign ping timeout handling a bit
1) Make timeout a timeout, don't do magic ping counts. 2) Drop additional timer from the main peer's protocol loop, create it dynamically and make it disconnect the peer. 3) Don't expose the ping counter to the outside, handle more logic inside the Peer. Relates to #430.
This commit is contained in:
parent
62092c703d
commit
2c4ace022e
13 changed files with 67 additions and 61 deletions
|
@ -29,7 +29,6 @@ const (
|
|||
maxBlockBatch = 200
|
||||
maxAddrsToSend = 200
|
||||
minPoolCount = 30
|
||||
defaultPingLimit = 4
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -373,12 +372,10 @@ func (s *Server) handlePing(p Peer, ping *payload.Ping) error {
|
|||
|
||||
// handlePing processes pong request.
|
||||
func (s *Server) handlePong(p Peer, pong *payload.Ping) error {
|
||||
pingSent := p.GetPingSent()
|
||||
if pingSent == 0 {
|
||||
return errors.New("pong message wasn't expected")
|
||||
err := p.HandlePong(pong)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.UpdatePingSent(pingSent - 1)
|
||||
p.UpdateLastBlockIndex(pong.LastBlockIndex)
|
||||
if s.chain.HeaderHeight() < pong.LastBlockIndex {
|
||||
return s.requestHeaders(p)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue