mirror of
https://github.com/status-im/op-geth.git
synced 2025-01-14 08:44:29 +00:00
p2p: enable devp2p ping
This should prevent connection drops.
This commit is contained in:
parent
1ec6190e86
commit
3dbd32093c
37
p2p/peer.go
37
p2p/peer.go
@ -21,6 +21,7 @@ const (
|
|||||||
baseProtocolMaxMsgSize = 10 * 1024 * 1024
|
baseProtocolMaxMsgSize = 10 * 1024 * 1024
|
||||||
|
|
||||||
disconnectGracePeriod = 2 * time.Second
|
disconnectGracePeriod = 2 * time.Second
|
||||||
|
pingInterval = 15 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -118,19 +119,33 @@ func (p *Peer) run() DiscReason {
|
|||||||
p.startProtocols()
|
p.startProtocols()
|
||||||
go func() { readErr <- p.readLoop() }()
|
go func() { readErr <- p.readLoop() }()
|
||||||
|
|
||||||
|
ping := time.NewTicker(pingInterval)
|
||||||
|
defer ping.Stop()
|
||||||
|
|
||||||
// Wait for an error or disconnect.
|
// Wait for an error or disconnect.
|
||||||
var reason DiscReason
|
var reason DiscReason
|
||||||
select {
|
loop:
|
||||||
case err := <-readErr:
|
for {
|
||||||
// We rely on protocols to abort if there is a write error. It
|
select {
|
||||||
// might be more robust to handle them here as well.
|
case <-ping.C:
|
||||||
p.DebugDetailf("Read error: %v\n", err)
|
go func() {
|
||||||
p.rw.Close()
|
if err := EncodeMsg(p.rw, pingMsg, nil); err != nil {
|
||||||
return DiscNetworkError
|
p.protoErr <- err
|
||||||
|
return
|
||||||
case err := <-p.protoErr:
|
}
|
||||||
reason = discReasonForError(err)
|
}()
|
||||||
case reason = <-p.disc:
|
case err := <-readErr:
|
||||||
|
// We rely on protocols to abort if there is a write error. It
|
||||||
|
// might be more robust to handle them here as well.
|
||||||
|
p.DebugDetailf("Read error: %v\n", err)
|
||||||
|
p.rw.Close()
|
||||||
|
return DiscNetworkError
|
||||||
|
case err := <-p.protoErr:
|
||||||
|
reason = discReasonForError(err)
|
||||||
|
break loop
|
||||||
|
case reason = <-p.disc:
|
||||||
|
break loop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.politeDisconnect(reason)
|
p.politeDisconnect(reason)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user