mirror of
https://github.com/fosrl/olm.git
synced 2026-02-07 21:46:40 +00:00
Small clean up and move ping to client.go
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
15
olm/olm.go
15
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user