From 9dcc0796a653eff6fc9548153c8a166393a7438b Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 15 Jan 2026 14:20:12 -0800 Subject: [PATCH] Small clean up and move ping to client.go Former-commit-id: af33218792fb9faf32249368ee08cfaedfeecc00 --- olm/data.go | 6 +++--- olm/olm.go | 15 --------------- olm/types.go | 6 +++++- websocket/client.go | 7 +++++-- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/olm/data.go b/olm/data.go index 80a52fc..cf7448a 100644 --- a/olm/data.go +++ b/olm/data.go @@ -216,15 +216,15 @@ func (o *Olm) handleSync(msg websocket.WSMessage) { return } - var wgData WgData - if err := json.Unmarshal(jsonData, &wgData); err != nil { + var syncData SyncData + if err := json.Unmarshal(jsonData, &syncData); err != nil { logger.Error("Error unmarshaling sync data: %v", err) return } // Build a map of expected peers from the incoming data expectedPeers := make(map[int]peers.SiteConfig) - for _, site := range wgData.Sites { + for _, site := range syncData.Sites { expectedPeers[site.SiteId] = site } diff --git a/olm/olm.go b/olm/olm.go index 85dcbe6..9582232 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -60,8 +60,6 @@ type Olm struct { stopRegister func() updateRegister func(newData any) - stopServerPing func() - stopPeerSend func() } @@ -332,14 +330,6 @@ func (o *Olm) StartTunnel(config TunnelConfig) { o.apiServer.SetConnectionStatus(true) - // restart the ping if we need to - if o.stopServerPing == nil { - o.stopServerPing, _ = olmClient.SendMessageInterval("olm/ping", map[string]any{ - "timestamp": time.Now().Unix(), - "userToken": olmClient.GetConfig().UserToken, - }, 30*time.Second, -1) // -1 means dont time out with the max attempts - } - if o.connected { logger.Debug("Already connected, skipping registration") return nil @@ -445,11 +435,6 @@ func (o *Olm) Close() { o.holePunchManager = nil } - if o.stopServerPing != nil { - o.stopServerPing() - o.stopServerPing = nil - } - if o.stopRegister != nil { o.stopRegister() o.stopRegister = nil diff --git a/olm/types.go b/olm/types.go index 397eab9..804f8e5 100644 --- a/olm/types.go +++ b/olm/types.go @@ -12,6 +12,10 @@ type WgData struct { UtilitySubnet string `json:"utilitySubnet"` // this is for things like the DNS server, and alias addresses } +type SyncData struct { + Sites []peers.SiteConfig `json:"sites"` +} + type OlmConfig struct { // Logging LogLevel string @@ -23,7 +27,7 @@ type OlmConfig struct { SocketPath string Version string Agent string - + WakeUpDebounce time.Duration // Debugging diff --git a/websocket/client.go b/websocket/client.go index ba70494..7877e6d 100644 --- a/websocket/client.go +++ b/websocket/client.go @@ -657,8 +657,11 @@ func (c *Client) pingMonitor() { c.configVersionMux.RUnlock() pingMsg := WSMessage{ - Type: "ping", - Data: map[string]interface{}{}, + Type: "olm/ping", + Data: map[string]any{ + "timestamp": time.Now().Unix(), + "userToken": c.config.UserToken, + }, ConfigVersion: configVersion, }