From 02c838eb862de868e6aa35e0db05d093340bbc20 Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 7 Dec 2025 12:05:27 -0500 Subject: [PATCH] Fix small bugs = --- config.go | 86 +++++++++++++++++++++++++++--------------------------- main.go | 2 +- olm/olm.go | 58 +++++++++++++++++------------------- 3 files changed, 71 insertions(+), 75 deletions(-) diff --git a/config.go b/config.go index 739e8b6..4b1c824 100644 --- a/config.go +++ b/config.go @@ -40,10 +40,10 @@ type OlmConfig struct { PingTimeout string `json:"pingTimeout"` // Advanced - Holepunch bool `json:"holepunch"` - TlsClientCert string `json:"tlsClientCert"` - OverrideDNS bool `json:"overrideDNS"` - DisableRelay bool `json:"disableRelay"` + DisableHolepunch bool `json:"disableHolepunch"` + TlsClientCert string `json:"tlsClientCert"` + OverrideDNS bool `json:"overrideDNS"` + DisableRelay bool `json:"disableRelay"` // DoNotCreateNewClient bool `json:"doNotCreateNewClient"` // Parsed values (not in JSON) @@ -78,16 +78,16 @@ func DefaultConfig() *OlmConfig { } config := &OlmConfig{ - MTU: 1280, - DNS: "8.8.8.8", - UpstreamDNS: []string{"8.8.8.8:53"}, - LogLevel: "INFO", - InterfaceName: "olm", - EnableAPI: false, - SocketPath: socketPath, - PingInterval: "3s", - PingTimeout: "5s", - Holepunch: false, + MTU: 1280, + DNS: "8.8.8.8", + UpstreamDNS: []string{"8.8.8.8:53"}, + LogLevel: "INFO", + InterfaceName: "olm", + EnableAPI: false, + SocketPath: socketPath, + PingInterval: "3s", + PingTimeout: "5s", + DisableHolepunch: false, // DoNotCreateNewClient: false, sources: make(map[string]string), } @@ -103,7 +103,7 @@ func DefaultConfig() *OlmConfig { config.sources["socketPath"] = string(SourceDefault) config.sources["pingInterval"] = string(SourceDefault) config.sources["pingTimeout"] = string(SourceDefault) - config.sources["holepunch"] = string(SourceDefault) + config.sources["disableHolepunch"] = string(SourceDefault) config.sources["overrideDNS"] = string(SourceDefault) config.sources["disableRelay"] = string(SourceDefault) // config.sources["doNotCreateNewClient"] = string(SourceDefault) @@ -253,9 +253,9 @@ func loadConfigFromEnv(config *OlmConfig) { config.SocketPath = val config.sources["socketPath"] = string(SourceEnv) } - if val := os.Getenv("HOLEPUNCH"); val == "true" { - config.Holepunch = true - config.sources["holepunch"] = string(SourceEnv) + if val := os.Getenv("DISABLE_HOLEPUNCH"); val == "true" { + config.DisableHolepunch = true + config.sources["disableHolepunch"] = string(SourceEnv) } if val := os.Getenv("OVERRIDE_DNS"); val == "true" { config.OverrideDNS = true @@ -277,24 +277,24 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) { // Store original values to detect changes origValues := map[string]interface{}{ - "endpoint": config.Endpoint, - "id": config.ID, - "secret": config.Secret, - "org": config.OrgID, - "userToken": config.UserToken, - "mtu": config.MTU, - "dns": config.DNS, - "upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS), - "logLevel": config.LogLevel, - "interface": config.InterfaceName, - "httpAddr": config.HTTPAddr, - "socketPath": config.SocketPath, - "pingInterval": config.PingInterval, - "pingTimeout": config.PingTimeout, - "enableApi": config.EnableAPI, - "holepunch": config.Holepunch, - "overrideDNS": config.OverrideDNS, - "disableRelay": config.DisableRelay, + "endpoint": config.Endpoint, + "id": config.ID, + "secret": config.Secret, + "org": config.OrgID, + "userToken": config.UserToken, + "mtu": config.MTU, + "dns": config.DNS, + "upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS), + "logLevel": config.LogLevel, + "interface": config.InterfaceName, + "httpAddr": config.HTTPAddr, + "socketPath": config.SocketPath, + "pingInterval": config.PingInterval, + "pingTimeout": config.PingTimeout, + "enableApi": config.EnableAPI, + "disableHolepunch": config.DisableHolepunch, + "overrideDNS": config.OverrideDNS, + "disableRelay": config.DisableRelay, // "doNotCreateNewClient": config.DoNotCreateNewClient, } @@ -315,7 +315,7 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) { serviceFlags.StringVar(&config.PingInterval, "ping-interval", config.PingInterval, "Interval for pinging the server") serviceFlags.StringVar(&config.PingTimeout, "ping-timeout", config.PingTimeout, "Timeout for each ping") serviceFlags.BoolVar(&config.EnableAPI, "enable-api", config.EnableAPI, "Enable API server for receiving connection requests") - serviceFlags.BoolVar(&config.Holepunch, "holepunch", config.Holepunch, "Enable hole punching") + serviceFlags.BoolVar(&config.DisableHolepunch, "disable-holepunch", config.DisableHolepunch, "Disable hole punching") serviceFlags.BoolVar(&config.OverrideDNS, "override-dns", config.OverrideDNS, "Override system DNS settings") serviceFlags.BoolVar(&config.DisableRelay, "disable-relay", config.DisableRelay, "Disable relay connections") // serviceFlags.BoolVar(&config.DoNotCreateNewClient, "do-not-create-new-client", config.DoNotCreateNewClient, "Do not create new client") @@ -384,8 +384,8 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) { if config.EnableAPI != origValues["enableApi"].(bool) { config.sources["enableApi"] = string(SourceCLI) } - if config.Holepunch != origValues["holepunch"].(bool) { - config.sources["holepunch"] = string(SourceCLI) + if config.DisableHolepunch != origValues["disableHolepunch"].(bool) { + config.sources["disableHolepunch"] = string(SourceCLI) } if config.OverrideDNS != origValues["overrideDNS"].(bool) { config.sources["overrideDNS"] = string(SourceCLI) @@ -505,9 +505,9 @@ func mergeConfigs(dest, src *OlmConfig) { dest.EnableAPI = src.EnableAPI dest.sources["enableApi"] = string(SourceFile) } - if src.Holepunch { - dest.Holepunch = src.Holepunch - dest.sources["holepunch"] = string(SourceFile) + if src.DisableHolepunch { + dest.DisableHolepunch = src.DisableHolepunch + dest.sources["disableHolepunch"] = string(SourceFile) } if src.OverrideDNS { dest.OverrideDNS = src.OverrideDNS @@ -604,7 +604,7 @@ func (c *OlmConfig) ShowConfig() { // Advanced fmt.Println("\nAdvanced:") - fmt.Printf(" holepunch = %v [%s]\n", c.Holepunch, getSource("holepunch")) + fmt.Printf(" disable-holepunch = %v [%s]\n", c.DisableHolepunch, getSource("disableHolepunch")) fmt.Printf(" override-dns = %v [%s]\n", c.OverrideDNS, getSource("overrideDNS")) fmt.Printf(" disable-relay = %v [%s]\n", c.DisableRelay, getSource("disableRelay")) // fmt.Printf(" do-not-create-new-client = %v [%s]\n", c.DoNotCreateNewClient, getSource("doNotCreateNewClient")) diff --git a/main.go b/main.go index 0309c50..f637cc0 100644 --- a/main.go +++ b/main.go @@ -235,7 +235,7 @@ func runOlmMainWithArgs(ctx context.Context, cancel context.CancelFunc, signalCt DNS: config.DNS, UpstreamDNS: config.UpstreamDNS, InterfaceName: config.InterfaceName, - Holepunch: config.Holepunch, + Holepunch: !config.DisableHolepunch, TlsClientCert: config.TlsClientCert, PingIntervalDuration: config.PingIntervalDuration, PingTimeoutDuration: config.PingTimeoutDuration, diff --git a/olm/olm.go b/olm/olm.go index c911c3e..1f02d8e 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -778,23 +778,21 @@ func StartTunnel(config TunnelConfig) { return } - // Add exit node to holepunch rotation if we have a holepunch manager - if holePunchManager != nil { - exitNode := holepunch.ExitNode{ - Endpoint: handshakeData.ExitNode.Endpoint, - PublicKey: handshakeData.ExitNode.PublicKey, - } - - added := holePunchManager.AddExitNode(exitNode) - if added { - logger.Info("Added exit node %s to holepunch rotation for handshake", exitNode.Endpoint) - } else { - logger.Debug("Exit node %s already in holepunch rotation", exitNode.Endpoint) - } - - holePunchManager.ResetInterval() // start sending immediately again so we fill in the endpoint on the cloud + exitNode := holepunch.ExitNode{ + Endpoint: handshakeData.ExitNode.Endpoint, + PublicKey: handshakeData.ExitNode.PublicKey, } + added := holePunchManager.AddExitNode(exitNode) + if added { + logger.Info("Added exit node %s to holepunch rotation for handshake", exitNode.Endpoint) + } else { + logger.Debug("Exit node %s already in holepunch rotation", exitNode.Endpoint) + } + + holePunchManager.TriggerHolePunch() // Trigger immediate hole punch attempt + holePunchManager.ResetInterval() // start sending immediately again so we fill in the endpoint on the cloud + // Send handshake acknowledgment back to server with retry stopPeerSend, _ = olm.SendMessageInterval("olm/wg/server/peer/add", map[string]interface{}{ "siteId": handshakeData.SiteId, @@ -859,27 +857,25 @@ func StartTunnel(config TunnelConfig) { }) olm.OnTokenUpdate(func(token string, exitNodes []websocket.ExitNode) { - if holePunchManager != nil { - holePunchManager.SetToken(token) + holePunchManager.SetToken(token) - logger.Debug("Got exit nodes for hole punching: %v", exitNodes) + logger.Debug("Got exit nodes for hole punching: %v", exitNodes) - // Convert websocket.ExitNode to holepunch.ExitNode - hpExitNodes := make([]holepunch.ExitNode, len(exitNodes)) - for i, node := range exitNodes { - hpExitNodes[i] = holepunch.ExitNode{ - Endpoint: node.Endpoint, - PublicKey: node.PublicKey, - } + // Convert websocket.ExitNode to holepunch.ExitNode + hpExitNodes := make([]holepunch.ExitNode, len(exitNodes)) + for i, node := range exitNodes { + hpExitNodes[i] = holepunch.ExitNode{ + Endpoint: node.Endpoint, + PublicKey: node.PublicKey, } + } - logger.Debug("Updated hole punch exit nodes: %v", hpExitNodes) + logger.Debug("Updated hole punch exit nodes: %v", hpExitNodes) - // Start hole punching using the manager - logger.Info("Starting hole punch for %d exit nodes", len(exitNodes)) - if err := holePunchManager.StartMultipleExitNodes(hpExitNodes); err != nil { - logger.Warn("Failed to start hole punch: %v", err) - } + // Start hole punching using the manager + logger.Info("Starting hole punch for %d exit nodes", len(exitNodes)) + if err := holePunchManager.StartMultipleExitNodes(hpExitNodes); err != nil { + logger.Warn("Failed to start hole punch: %v", err) } })