From f23f2fb9aa6db7f4919799f01dfd9650d5f92e59 Mon Sep 17 00:00:00 2001 From: Owen Date: Fri, 7 Nov 2025 14:20:36 -0800 Subject: [PATCH] Starting and stopping working --- main.go | 2 -- olm/olm.go | 57 ++++++++++++++++++++++++++---------------------------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index 3976315..a113839 100644 --- a/main.go +++ b/main.go @@ -202,8 +202,6 @@ func main() { EnableAPI: config.EnableAPI, HTTPAddr: config.HTTPAddr, SocketPath: config.SocketPath, - PingInterval: config.PingInterval, - PingTimeout: config.PingTimeout, Holepunch: config.Holepunch, TlsClientCert: config.TlsClientCert, PingIntervalDuration: config.PingIntervalDuration, diff --git a/olm/olm.go b/olm/olm.go index a28f896..d571cc3 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -674,17 +674,10 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string, olm.RegisterHandler("olm/register/no-sites", func(msg websocket.WSMessage) { logger.Info("Received no-sites message - no sites available for connection") - // if stopRegister != nil { - // stopRegister() - // stopRegister = nil - // } - - // select { - // case <-stopHolepunch: - // // Channel already closed, do nothing - // default: - // close(stopHolepunch) - // } + if stopRegister != nil { + stopRegister() + stopRegister = nil + } logger.Info("No sites available - stopped registration and holepunch processes") }) @@ -706,18 +699,18 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string, publicKey := privateKey.PublicKey() - logger.Debug("Sending registration message to server with public key: %s and relay: %v", publicKey, !config.Holepunch) - - stopRegister = olm.SendMessageInterval("olm/wg/register", map[string]interface{}{ - "publicKey": publicKey.String(), - "relay": !config.Holepunch, - "olmVersion": config.Version, - "orgId": config.OrgID, - }, 1*time.Second) + if stopRegister == nil { + logger.Debug("Sending registration message to server with public key: %s and relay: %v", publicKey, !config.Holepunch) + stopRegister = olm.SendMessageInterval("olm/wg/register", map[string]interface{}{ + "publicKey": publicKey.String(), + "relay": !config.Holepunch, + "olmVersion": config.Version, + "orgId": config.OrgID, + }, 1*time.Second) + } go keepSendingPing(olm) - logger.Info("Sent registration message") return nil }) @@ -769,18 +762,22 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string, } func Stop() { - select { - case <-stopHolepunch: - // Channel already closed, do nothing - default: - close(stopHolepunch) + if stopHolepunch != nil { + select { + case <-stopHolepunch: + // Channel already closed, do nothing + default: + close(stopHolepunch) + } } - select { - case <-stopPing: - // Channel already closed - default: - close(stopPing) + if stopPing != nil { + select { + case <-stopPing: + // Channel already closed + default: + close(stopPing) + } } if stopRegister != nil {