forked from cerc-io/plugeth
ethstats: fix reconnection issue, implement primus pings
This commit is contained in:
parent
9e88224eb8
commit
0fef66c739
@ -280,8 +280,10 @@ func (s *Service) loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fullReport.Stop()
|
fullReport.Stop()
|
||||||
// Make sure the connection is closed
|
|
||||||
|
// Close the current connection and establish a new one
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
errTimer.Reset(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,8 +298,23 @@ func (s *Service) readLoop(conn *websocket.Conn) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
// Retrieve the next generic network packet and bail out on error
|
// Retrieve the next generic network packet and bail out on error
|
||||||
|
var blob json.RawMessage
|
||||||
|
if err := conn.ReadJSON(&blob); err != nil {
|
||||||
|
log.Warn("Failed to retrieve stats server message", "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// If the network packet is a system ping, respond to it directly
|
||||||
|
var ping string
|
||||||
|
if err := json.Unmarshal(blob, &ping); err == nil && strings.HasPrefix(ping, "primus::ping::") {
|
||||||
|
if err := conn.WriteJSON(strings.Replace(ping, "ping", "pong", -1)); err != nil {
|
||||||
|
log.Warn("Failed to respond to system ping message", "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Not a system ping, try to decode an actual state message
|
||||||
var msg map[string][]interface{}
|
var msg map[string][]interface{}
|
||||||
if err := conn.ReadJSON(&msg); err != nil {
|
if err := json.Unmarshal(blob, &msg); err != nil {
|
||||||
log.Warn("Failed to decode stats server message", "err", err)
|
log.Warn("Failed to decode stats server message", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user