mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
Fix small bugs =
This commit is contained in:
86
config.go
86
config.go
@@ -40,10 +40,10 @@ type OlmConfig struct {
|
|||||||
PingTimeout string `json:"pingTimeout"`
|
PingTimeout string `json:"pingTimeout"`
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
Holepunch bool `json:"holepunch"`
|
DisableHolepunch bool `json:"disableHolepunch"`
|
||||||
TlsClientCert string `json:"tlsClientCert"`
|
TlsClientCert string `json:"tlsClientCert"`
|
||||||
OverrideDNS bool `json:"overrideDNS"`
|
OverrideDNS bool `json:"overrideDNS"`
|
||||||
DisableRelay bool `json:"disableRelay"`
|
DisableRelay bool `json:"disableRelay"`
|
||||||
// DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
|
// DoNotCreateNewClient bool `json:"doNotCreateNewClient"`
|
||||||
|
|
||||||
// Parsed values (not in JSON)
|
// Parsed values (not in JSON)
|
||||||
@@ -78,16 +78,16 @@ func DefaultConfig() *OlmConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
config := &OlmConfig{
|
config := &OlmConfig{
|
||||||
MTU: 1280,
|
MTU: 1280,
|
||||||
DNS: "8.8.8.8",
|
DNS: "8.8.8.8",
|
||||||
UpstreamDNS: []string{"8.8.8.8:53"},
|
UpstreamDNS: []string{"8.8.8.8:53"},
|
||||||
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,
|
DisableHolepunch: false,
|
||||||
// DoNotCreateNewClient: false,
|
// DoNotCreateNewClient: false,
|
||||||
sources: make(map[string]string),
|
sources: make(map[string]string),
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ func DefaultConfig() *OlmConfig {
|
|||||||
config.sources["socketPath"] = string(SourceDefault)
|
config.sources["socketPath"] = string(SourceDefault)
|
||||||
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["disableHolepunch"] = string(SourceDefault)
|
||||||
config.sources["overrideDNS"] = string(SourceDefault)
|
config.sources["overrideDNS"] = string(SourceDefault)
|
||||||
config.sources["disableRelay"] = string(SourceDefault)
|
config.sources["disableRelay"] = string(SourceDefault)
|
||||||
// config.sources["doNotCreateNewClient"] = string(SourceDefault)
|
// config.sources["doNotCreateNewClient"] = string(SourceDefault)
|
||||||
@@ -253,9 +253,9 @@ func loadConfigFromEnv(config *OlmConfig) {
|
|||||||
config.SocketPath = val
|
config.SocketPath = val
|
||||||
config.sources["socketPath"] = string(SourceEnv)
|
config.sources["socketPath"] = string(SourceEnv)
|
||||||
}
|
}
|
||||||
if val := os.Getenv("HOLEPUNCH"); val == "true" {
|
if val := os.Getenv("DISABLE_HOLEPUNCH"); val == "true" {
|
||||||
config.Holepunch = true
|
config.DisableHolepunch = true
|
||||||
config.sources["holepunch"] = string(SourceEnv)
|
config.sources["disableHolepunch"] = string(SourceEnv)
|
||||||
}
|
}
|
||||||
if val := os.Getenv("OVERRIDE_DNS"); val == "true" {
|
if val := os.Getenv("OVERRIDE_DNS"); val == "true" {
|
||||||
config.OverrideDNS = true
|
config.OverrideDNS = true
|
||||||
@@ -277,24 +277,24 @@ 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,
|
||||||
"upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS),
|
"upstreamDNS": fmt.Sprintf("%v", config.UpstreamDNS),
|
||||||
"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,
|
"disableHolepunch": config.DisableHolepunch,
|
||||||
"overrideDNS": config.OverrideDNS,
|
"overrideDNS": config.OverrideDNS,
|
||||||
"disableRelay": config.DisableRelay,
|
"disableRelay": config.DisableRelay,
|
||||||
// "doNotCreateNewClient": config.DoNotCreateNewClient,
|
// "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.PingInterval, "ping-interval", config.PingInterval, "Interval for pinging the server")
|
||||||
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.DisableHolepunch, "disable-holepunch", config.DisableHolepunch, "Disable hole punching")
|
||||||
serviceFlags.BoolVar(&config.OverrideDNS, "override-dns", config.OverrideDNS, "Override system DNS settings")
|
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.DisableRelay, "disable-relay", config.DisableRelay, "Disable relay connections")
|
||||||
// serviceFlags.BoolVar(&config.DoNotCreateNewClient, "do-not-create-new-client", config.DoNotCreateNewClient, "Do not create new client")
|
// 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) {
|
if config.EnableAPI != origValues["enableApi"].(bool) {
|
||||||
config.sources["enableApi"] = string(SourceCLI)
|
config.sources["enableApi"] = string(SourceCLI)
|
||||||
}
|
}
|
||||||
if config.Holepunch != origValues["holepunch"].(bool) {
|
if config.DisableHolepunch != origValues["disableHolepunch"].(bool) {
|
||||||
config.sources["holepunch"] = string(SourceCLI)
|
config.sources["disableHolepunch"] = string(SourceCLI)
|
||||||
}
|
}
|
||||||
if config.OverrideDNS != origValues["overrideDNS"].(bool) {
|
if config.OverrideDNS != origValues["overrideDNS"].(bool) {
|
||||||
config.sources["overrideDNS"] = string(SourceCLI)
|
config.sources["overrideDNS"] = string(SourceCLI)
|
||||||
@@ -505,9 +505,9 @@ func mergeConfigs(dest, src *OlmConfig) {
|
|||||||
dest.EnableAPI = src.EnableAPI
|
dest.EnableAPI = src.EnableAPI
|
||||||
dest.sources["enableApi"] = string(SourceFile)
|
dest.sources["enableApi"] = string(SourceFile)
|
||||||
}
|
}
|
||||||
if src.Holepunch {
|
if src.DisableHolepunch {
|
||||||
dest.Holepunch = src.Holepunch
|
dest.DisableHolepunch = src.DisableHolepunch
|
||||||
dest.sources["holepunch"] = string(SourceFile)
|
dest.sources["disableHolepunch"] = string(SourceFile)
|
||||||
}
|
}
|
||||||
if src.OverrideDNS {
|
if src.OverrideDNS {
|
||||||
dest.OverrideDNS = src.OverrideDNS
|
dest.OverrideDNS = src.OverrideDNS
|
||||||
@@ -604,7 +604,7 @@ func (c *OlmConfig) ShowConfig() {
|
|||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
fmt.Println("\nAdvanced:")
|
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(" override-dns = %v [%s]\n", c.OverrideDNS, getSource("overrideDNS"))
|
||||||
fmt.Printf(" disable-relay = %v [%s]\n", c.DisableRelay, getSource("disableRelay"))
|
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"))
|
// fmt.Printf(" do-not-create-new-client = %v [%s]\n", c.DoNotCreateNewClient, getSource("doNotCreateNewClient"))
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -235,7 +235,7 @@ func runOlmMainWithArgs(ctx context.Context, cancel context.CancelFunc, signalCt
|
|||||||
DNS: config.DNS,
|
DNS: config.DNS,
|
||||||
UpstreamDNS: config.UpstreamDNS,
|
UpstreamDNS: config.UpstreamDNS,
|
||||||
InterfaceName: config.InterfaceName,
|
InterfaceName: config.InterfaceName,
|
||||||
Holepunch: config.Holepunch,
|
Holepunch: !config.DisableHolepunch,
|
||||||
TlsClientCert: config.TlsClientCert,
|
TlsClientCert: config.TlsClientCert,
|
||||||
PingIntervalDuration: config.PingIntervalDuration,
|
PingIntervalDuration: config.PingIntervalDuration,
|
||||||
PingTimeoutDuration: config.PingTimeoutDuration,
|
PingTimeoutDuration: config.PingTimeoutDuration,
|
||||||
|
|||||||
58
olm/olm.go
58
olm/olm.go
@@ -778,23 +778,21 @@ func StartTunnel(config TunnelConfig) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add exit node to holepunch rotation if we have a holepunch manager
|
exitNode := holepunch.ExitNode{
|
||||||
if holePunchManager != nil {
|
Endpoint: handshakeData.ExitNode.Endpoint,
|
||||||
exitNode := holepunch.ExitNode{
|
PublicKey: handshakeData.ExitNode.PublicKey,
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// Send handshake acknowledgment back to server with retry
|
||||||
stopPeerSend, _ = olm.SendMessageInterval("olm/wg/server/peer/add", map[string]interface{}{
|
stopPeerSend, _ = olm.SendMessageInterval("olm/wg/server/peer/add", map[string]interface{}{
|
||||||
"siteId": handshakeData.SiteId,
|
"siteId": handshakeData.SiteId,
|
||||||
@@ -859,27 +857,25 @@ func StartTunnel(config TunnelConfig) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
olm.OnTokenUpdate(func(token string, exitNodes []websocket.ExitNode) {
|
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
|
// Convert websocket.ExitNode to holepunch.ExitNode
|
||||||
hpExitNodes := make([]holepunch.ExitNode, len(exitNodes))
|
hpExitNodes := make([]holepunch.ExitNode, len(exitNodes))
|
||||||
for i, node := range exitNodes {
|
for i, node := range exitNodes {
|
||||||
hpExitNodes[i] = holepunch.ExitNode{
|
hpExitNodes[i] = holepunch.ExitNode{
|
||||||
Endpoint: node.Endpoint,
|
Endpoint: node.Endpoint,
|
||||||
PublicKey: node.PublicKey,
|
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
|
// Start hole punching using the manager
|
||||||
logger.Info("Starting hole punch for %d exit nodes", len(exitNodes))
|
logger.Info("Starting hole punch for %d exit nodes", len(exitNodes))
|
||||||
if err := holePunchManager.StartMultipleExitNodes(hpExitNodes); err != nil {
|
if err := holePunchManager.StartMultipleExitNodes(hpExitNodes); err != nil {
|
||||||
logger.Warn("Failed to start hole punch: %v", err)
|
logger.Warn("Failed to start hole punch: %v", err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user