Add DoNotCreateNewClient

Former-commit-id: aedebb5579
This commit is contained in:
Owen
2025-11-07 15:26:45 -08:00
parent 235877c379
commit 7696ba2e36
3 changed files with 55 additions and 35 deletions

View File

@@ -40,6 +40,7 @@ type OlmConfig struct {
// Advanced
Holepunch bool `json:"holepunch"`
TlsClientCert string `json:"tlsClientCert"`
DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
// Parsed values (not in JSON)
PingIntervalDuration time.Duration `json:"-"`
@@ -82,6 +83,7 @@ func DefaultConfig() *OlmConfig {
PingInterval: "3s",
PingTimeout: "5s",
Holepunch: false,
DoNotCreateNewClient: false,
sources: make(map[string]string),
}
@@ -96,6 +98,7 @@ func DefaultConfig() *OlmConfig {
config.sources["pingInterval"] = string(SourceDefault)
config.sources["pingTimeout"] = string(SourceDefault)
config.sources["holepunch"] = string(SourceDefault)
config.sources["doNotCreateNewClient"] = string(SourceDefault)
return config
}
@@ -242,6 +245,10 @@ func loadConfigFromEnv(config *OlmConfig) {
config.Holepunch = true
config.sources["holepunch"] = string(SourceEnv)
}
if val := os.Getenv("DO_NOT_CREATE_NEW_CLIENT"); val == "true" {
config.DoNotCreateNewClient = true
config.sources["doNotCreateNewClient"] = string(SourceEnv)
}
}
// loadConfigFromCLI loads configuration from command-line arguments
@@ -265,6 +272,7 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
"pingTimeout": config.PingTimeout,
"enableApi": config.EnableAPI,
"holepunch": config.Holepunch,
"doNotCreateNewClient": config.DoNotCreateNewClient,
}
// Define flags
@@ -283,6 +291,7 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
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.DoNotCreateNewClient, "do-not-create-new-client", config.DoNotCreateNewClient, "Do not create new client")
version := serviceFlags.Bool("version", false, "Print the version")
showConfig := serviceFlags.Bool("show-config", false, "Show configuration sources and exit")
@@ -338,6 +347,9 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
if config.Holepunch != origValues["holepunch"].(bool) {
config.sources["holepunch"] = string(SourceCLI)
}
if config.DoNotCreateNewClient != origValues["doNotCreateNewClient"].(bool) {
config.sources["doNotCreateNewClient"] = string(SourceCLI)
}
return *version, *showConfig, nil
}
@@ -447,6 +459,10 @@ func mergeConfigs(dest, src *OlmConfig) {
dest.Holepunch = src.Holepunch
dest.sources["holepunch"] = string(SourceFile)
}
if src.DoNotCreateNewClient {
dest.DoNotCreateNewClient = src.DoNotCreateNewClient
dest.sources["doNotCreateNewClient"] = string(SourceFile)
}
}
// SaveConfig saves the current configuration to the config file
@@ -530,6 +546,7 @@ func (c *OlmConfig) ShowConfig() {
// Advanced
fmt.Println("\nAdvanced:")
fmt.Printf(" holepunch = %v [%s]\n", c.Holepunch, getSource("holepunch"))
fmt.Printf(" do-not-create-new-client = %v [%s]\n", c.DoNotCreateNewClient, getSource("doNotCreateNewClient"))
if c.TlsClientCert != "" {
fmt.Printf(" tls-cert = %s [%s]\n", c.TlsClientCert, getSource("tlsClientCert"))
}

View File

@@ -209,6 +209,7 @@ func main() {
PingTimeoutDuration: config.PingTimeoutDuration,
Version: config.Version,
OrgID: config.OrgID,
DoNotCreateNewClient: config.DoNotCreateNewClient,
}
// Create a context that will be cancelled on interrupt signals

View File

@@ -52,6 +52,7 @@ type Config struct {
Version string
OrgID string
DoNotCreateNewClient bool
}
var (
@@ -713,6 +714,7 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
"relay": !config.Holepunch,
"olmVersion": config.Version,
"orgId": config.OrgID,
"doNotCreateNewClient": config.DoNotCreateNewClient,
}, 1*time.Second)
}