mirror of
https://github.com/fosrl/olm.git
synced 2026-02-26 06:46:48 +00:00
75
config.go
75
config.go
@@ -38,8 +38,9 @@ type OlmConfig struct {
|
|||||||
PingTimeout string `json:"pingTimeout"`
|
PingTimeout string `json:"pingTimeout"`
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
Holepunch bool `json:"holepunch"`
|
Holepunch bool `json:"holepunch"`
|
||||||
TlsClientCert string `json:"tlsClientCert"`
|
TlsClientCert string `json:"tlsClientCert"`
|
||||||
|
DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
|
||||||
|
|
||||||
// Parsed values (not in JSON)
|
// Parsed values (not in JSON)
|
||||||
PingIntervalDuration time.Duration `json:"-"`
|
PingIntervalDuration time.Duration `json:"-"`
|
||||||
@@ -73,16 +74,17 @@ func DefaultConfig() *OlmConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config := &OlmConfig{
|
config := &OlmConfig{
|
||||||
MTU: 1280,
|
MTU: 1280,
|
||||||
DNS: "8.8.8.8",
|
DNS: "8.8.8.8",
|
||||||
LogLevel: "INFO",
|
LogLevel: "INFO",
|
||||||
InterfaceName: "olm",
|
InterfaceName: "olm",
|
||||||
EnableAPI: false,
|
EnableAPI: false,
|
||||||
SocketPath: socketPath,
|
SocketPath: socketPath,
|
||||||
PingInterval: "3s",
|
PingInterval: "3s",
|
||||||
PingTimeout: "5s",
|
PingTimeout: "5s",
|
||||||
Holepunch: false,
|
Holepunch: false,
|
||||||
sources: make(map[string]string),
|
DoNotCreateNewClient: false,
|
||||||
|
sources: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track default sources
|
// Track default sources
|
||||||
@@ -96,6 +98,7 @@ func DefaultConfig() *OlmConfig {
|
|||||||
config.sources["pingInterval"] = string(SourceDefault)
|
config.sources["pingInterval"] = string(SourceDefault)
|
||||||
config.sources["pingTimeout"] = string(SourceDefault)
|
config.sources["pingTimeout"] = string(SourceDefault)
|
||||||
config.sources["holepunch"] = string(SourceDefault)
|
config.sources["holepunch"] = string(SourceDefault)
|
||||||
|
config.sources["doNotCreateNewClient"] = string(SourceDefault)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
@@ -242,6 +245,10 @@ func loadConfigFromEnv(config *OlmConfig) {
|
|||||||
config.Holepunch = true
|
config.Holepunch = true
|
||||||
config.sources["holepunch"] = string(SourceEnv)
|
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
|
// loadConfigFromCLI loads configuration from command-line arguments
|
||||||
@@ -250,21 +257,22 @@ func loadConfigFromCLI(config *OlmConfig, args []string) (bool, bool, error) {
|
|||||||
|
|
||||||
// Store original values to detect changes
|
// Store original values to detect changes
|
||||||
origValues := map[string]interface{}{
|
origValues := map[string]interface{}{
|
||||||
"endpoint": config.Endpoint,
|
"endpoint": config.Endpoint,
|
||||||
"id": config.ID,
|
"id": config.ID,
|
||||||
"secret": config.Secret,
|
"secret": config.Secret,
|
||||||
"org": config.OrgID,
|
"org": config.OrgID,
|
||||||
"userToken": config.UserToken,
|
"userToken": config.UserToken,
|
||||||
"mtu": config.MTU,
|
"mtu": config.MTU,
|
||||||
"dns": config.DNS,
|
"dns": config.DNS,
|
||||||
"logLevel": config.LogLevel,
|
"logLevel": config.LogLevel,
|
||||||
"interface": config.InterfaceName,
|
"interface": config.InterfaceName,
|
||||||
"httpAddr": config.HTTPAddr,
|
"httpAddr": config.HTTPAddr,
|
||||||
"socketPath": config.SocketPath,
|
"socketPath": config.SocketPath,
|
||||||
"pingInterval": config.PingInterval,
|
"pingInterval": config.PingInterval,
|
||||||
"pingTimeout": config.PingTimeout,
|
"pingTimeout": config.PingTimeout,
|
||||||
"enableApi": config.EnableAPI,
|
"enableApi": config.EnableAPI,
|
||||||
"holepunch": config.Holepunch,
|
"holepunch": config.Holepunch,
|
||||||
|
"doNotCreateNewClient": config.DoNotCreateNewClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define flags
|
// 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.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.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.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")
|
version := serviceFlags.Bool("version", false, "Print the version")
|
||||||
showConfig := serviceFlags.Bool("show-config", false, "Show configuration sources and exit")
|
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) {
|
if config.Holepunch != origValues["holepunch"].(bool) {
|
||||||
config.sources["holepunch"] = string(SourceCLI)
|
config.sources["holepunch"] = string(SourceCLI)
|
||||||
}
|
}
|
||||||
|
if config.DoNotCreateNewClient != origValues["doNotCreateNewClient"].(bool) {
|
||||||
|
config.sources["doNotCreateNewClient"] = string(SourceCLI)
|
||||||
|
}
|
||||||
|
|
||||||
return *version, *showConfig, nil
|
return *version, *showConfig, nil
|
||||||
}
|
}
|
||||||
@@ -447,6 +459,10 @@ func mergeConfigs(dest, src *OlmConfig) {
|
|||||||
dest.Holepunch = src.Holepunch
|
dest.Holepunch = src.Holepunch
|
||||||
dest.sources["holepunch"] = string(SourceFile)
|
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
|
// SaveConfig saves the current configuration to the config file
|
||||||
@@ -529,9 +545,10 @@ func (c *OlmConfig) ShowConfig() {
|
|||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
fmt.Println("\nAdvanced:")
|
fmt.Println("\nAdvanced:")
|
||||||
fmt.Printf(" holepunch = %v [%s]\n", c.Holepunch, getSource("holepunch"))
|
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 != "" {
|
if c.TlsClientCert != "" {
|
||||||
fmt.Printf(" tls-cert = %s [%s]\n", c.TlsClientCert, getSource("tlsClientCert"))
|
fmt.Printf(" tls-cert = %s [%s]\n", c.TlsClientCert, getSource("tlsClientCert"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source legend
|
// Source legend
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -209,6 +209,7 @@ func main() {
|
|||||||
PingTimeoutDuration: config.PingTimeoutDuration,
|
PingTimeoutDuration: config.PingTimeoutDuration,
|
||||||
Version: config.Version,
|
Version: config.Version,
|
||||||
OrgID: config.OrgID,
|
OrgID: config.OrgID,
|
||||||
|
DoNotCreateNewClient: config.DoNotCreateNewClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a context that will be cancelled on interrupt signals
|
// Create a context that will be cancelled on interrupt signals
|
||||||
|
|||||||
14
olm/olm.go
14
olm/olm.go
@@ -50,8 +50,9 @@ type Config struct {
|
|||||||
// Source tracking (not in JSON)
|
// Source tracking (not in JSON)
|
||||||
sources map[string]string
|
sources map[string]string
|
||||||
|
|
||||||
Version string
|
Version string
|
||||||
OrgID string
|
OrgID string
|
||||||
|
DoNotCreateNewClient bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -709,10 +710,11 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
|
|||||||
if stopRegister == nil {
|
if stopRegister == nil {
|
||||||
logger.Debug("Sending registration message to server with public key: %s and relay: %v", publicKey, !config.Holepunch)
|
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{}{
|
stopRegister = olm.SendMessageInterval("olm/wg/register", map[string]interface{}{
|
||||||
"publicKey": publicKey.String(),
|
"publicKey": publicKey.String(),
|
||||||
"relay": !config.Holepunch,
|
"relay": !config.Holepunch,
|
||||||
"olmVersion": config.Version,
|
"olmVersion": config.Version,
|
||||||
"orgId": config.OrgID,
|
"orgId": config.OrgID,
|
||||||
|
"doNotCreateNewClient": config.DoNotCreateNewClient,
|
||||||
}, 1*time.Second)
|
}, 1*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user