Small clean up and move ping to client.go

Former-commit-id: af33218792
This commit is contained in:
Owen
2026-01-15 14:20:12 -08:00
parent 3710880ce0
commit 9dcc0796a6
4 changed files with 13 additions and 21 deletions

View File

@@ -216,15 +216,15 @@ func (o *Olm) handleSync(msg websocket.WSMessage) {
return return
} }
var wgData WgData var syncData SyncData
if err := json.Unmarshal(jsonData, &wgData); err != nil { if err := json.Unmarshal(jsonData, &syncData); err != nil {
logger.Error("Error unmarshaling sync data: %v", err) logger.Error("Error unmarshaling sync data: %v", err)
return return
} }
// Build a map of expected peers from the incoming data // Build a map of expected peers from the incoming data
expectedPeers := make(map[int]peers.SiteConfig) expectedPeers := make(map[int]peers.SiteConfig)
for _, site := range wgData.Sites { for _, site := range syncData.Sites {
expectedPeers[site.SiteId] = site expectedPeers[site.SiteId] = site
} }

View File

@@ -60,8 +60,6 @@ type Olm struct {
stopRegister func() stopRegister func()
updateRegister func(newData any) updateRegister func(newData any)
stopServerPing func()
stopPeerSend func() stopPeerSend func()
} }
@@ -332,14 +330,6 @@ func (o *Olm) StartTunnel(config TunnelConfig) {
o.apiServer.SetConnectionStatus(true) 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 { if o.connected {
logger.Debug("Already connected, skipping registration") logger.Debug("Already connected, skipping registration")
return nil return nil
@@ -445,11 +435,6 @@ func (o *Olm) Close() {
o.holePunchManager = nil o.holePunchManager = nil
} }
if o.stopServerPing != nil {
o.stopServerPing()
o.stopServerPing = nil
}
if o.stopRegister != nil { if o.stopRegister != nil {
o.stopRegister() o.stopRegister()
o.stopRegister = nil o.stopRegister = nil

View File

@@ -12,6 +12,10 @@ type WgData struct {
UtilitySubnet string `json:"utilitySubnet"` // this is for things like the DNS server, and alias addresses 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 { type OlmConfig struct {
// Logging // Logging
LogLevel string LogLevel string

View File

@@ -657,8 +657,11 @@ func (c *Client) pingMonitor() {
c.configVersionMux.RUnlock() c.configVersionMux.RUnlock()
pingMsg := WSMessage{ pingMsg := WSMessage{
Type: "ping", Type: "olm/ping",
Data: map[string]interface{}{}, Data: map[string]any{
"timestamp": time.Now().Unix(),
"userToken": c.config.UserToken,
},
ConfigVersion: configVersion, ConfigVersion: configVersion,
} }