mirror of
https://github.com/fosrl/olm.git
synced 2026-10-06 20:59:08 +02:00
Add immediate ping methods for websocket connection liveness checks
This commit is contained in:
+14
@@ -1174,6 +1174,20 @@ func (o *Olm) SetPowerMode(mode string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PokeConnection sends an immediate ping over the control websocket rather
|
||||||
|
// than waiting for the next scheduled ping interval or read-deadline expiry,
|
||||||
|
// so a live connection confirms itself in one round trip and a dead one -
|
||||||
|
// undetectable while the underlying host was asleep, since nothing runs
|
||||||
|
// during real system sleep to notice - starts reconnecting right away. This
|
||||||
|
// is meant to be driven by an actual "device woke up" hook, not a timer, so
|
||||||
|
// recovery stays tied to a real signal rather than a guess about how long
|
||||||
|
// reconnecting might take. No-op if the tunnel isn't running.
|
||||||
|
func (o *Olm) PokeConnection() {
|
||||||
|
if o.websocket != nil {
|
||||||
|
o.websocket.PingNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RebindSocket recreates the UDP socket when network connectivity changes.
|
// RebindSocket recreates the UDP socket when network connectivity changes.
|
||||||
// This is necessary on macOS/iOS when transitioning between WiFi and cellular,
|
// This is necessary on macOS/iOS when transitioning between WiFi and cellular,
|
||||||
// as the old socket becomes stale and can no longer route packets.
|
// as the old socket becomes stale and can no longer route packets.
|
||||||
|
|||||||
@@ -773,6 +773,21 @@ func (c *Client) sendPing() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PingNow sends a single ping immediately instead of waiting for the next
|
||||||
|
// scheduled tick of pingMonitor - useful as a fast liveness probe (e.g. right
|
||||||
|
// after a host wake from sleep) so a live connection confirms itself in one
|
||||||
|
// round trip and a dead one starts reconnecting immediately, rather than
|
||||||
|
// waiting for the earlier of the next scheduled ping or the read deadline to
|
||||||
|
// expire. Safe to call at any time, including before the ping monitor has
|
||||||
|
// started or while disconnected (sendPing is a no-op in that case). Runs
|
||||||
|
// asynchronously since sendPing can block up to writeDeadline.
|
||||||
|
func (c *Client) PingNow() {
|
||||||
|
if c == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go c.sendPing()
|
||||||
|
}
|
||||||
|
|
||||||
// pingMonitor sends pings at a short interval and triggers reconnect on failure
|
// pingMonitor sends pings at a short interval and triggers reconnect on failure
|
||||||
func (c *Client) pingMonitor() {
|
func (c *Client) pingMonitor() {
|
||||||
ticker := time.NewTicker(c.pingInterval)
|
ticker := time.NewTicker(c.pingInterval)
|
||||||
|
|||||||
Reference in New Issue
Block a user