Fix relay error stats and router relay quality

This commit is contained in:
Jon Staab
2025-04-07 17:28:00 -07:00
parent d0d727edd1
commit a6c916c0e1
4 changed files with 15 additions and 22 deletions
+10 -11
View File
@@ -233,27 +233,26 @@ const onSocketStatus = (status: string, url: string) => {
},
])
}
}
const onSocketError = (error: string, url: string) =>
updateRelayStats([
url,
stats => {
stats.last_error = now()
stats.recent_errors = uniq(stats.recent_errors.concat(now())).slice(-10)
},
])
if (status === SocketStatus.Error) {
updateRelayStats([
url,
stats => {
stats.last_error = now()
stats.recent_errors = uniq(stats.recent_errors.concat(now())).slice(-10)
},
])
}
}
export const trackRelayStats = (socket: Socket) => {
socket.on(SocketEvent.Send, onSocketSend)
socket.on(SocketEvent.Receive, onSocketReceive)
socket.on(SocketEvent.Status, onSocketStatus)
socket.on(SocketEvent.Error, onSocketError)
return () => {
socket.off(SocketEvent.Send, onSocketSend)
socket.off(SocketEvent.Receive, onSocketReceive)
socket.off(SocketEvent.Status, onSocketStatus)
socket.off(SocketEvent.Error, onSocketError)
}
}