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
}
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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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,
}