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
|
@ -160,7 +160,7 @@ type localPeer struct {
|
|||
handshaked bool
|
||||
t *testing.T
|
||||
messageHandler func(t *testing.T, msg *Message)
|
||||
pingSent int
|
||||
pingSent int
|
||||
}
|
||||
|
||||
func newLocalPeer(t *testing.T) *localPeer {
|
||||
|
@ -206,9 +206,6 @@ func (p *localPeer) Version() *payload.Version {
|
|||
func (p *localPeer) LastBlockIndex() uint32 {
|
||||
return p.lastBlockIndex
|
||||
}
|
||||
func (p *localPeer) UpdateLastBlockIndex(newIndex uint32) {
|
||||
p.lastBlockIndex = newIndex
|
||||
}
|
||||
func (p *localPeer) HandleVersion(v *payload.Version) error {
|
||||
p.version = v
|
||||
return nil
|
||||
|
@ -225,11 +222,14 @@ func (p *localPeer) HandleVersionAck() error {
|
|||
p.handshaked = true
|
||||
return nil
|
||||
}
|
||||
func (p *localPeer) GetPingSent() int {
|
||||
return p.pingSent
|
||||
func (p *localPeer) SendPing() error {
|
||||
p.pingSent++
|
||||
return nil
|
||||
}
|
||||
func (p *localPeer) UpdatePingSent(newValue int) {
|
||||
p.pingSent = newValue
|
||||
func (p *localPeer) HandlePong(pong *payload.Ping) error {
|
||||
p.lastBlockIndex = pong.LastBlockIndex
|
||||
p.pingSent--
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *localPeer) Handshaked() bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue