mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
2
main.go
2
main.go
@@ -226,5 +226,5 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
// DoNotCreateNewClient: config.DoNotCreateNewClient,
|
// DoNotCreateNewClient: config.DoNotCreateNewClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
olm.Run(ctx, olmConfig)
|
olm.Init(ctx, olmConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
18
olm/olm.go
18
olm/olm.go
@@ -78,7 +78,7 @@ var (
|
|||||||
stopPing chan struct{}
|
stopPing chan struct{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Run(ctx context.Context, config Config) {
|
func Init(ctx context.Context, config Config) {
|
||||||
// Create a cancellable context for internal shutdown control
|
// Create a cancellable context for internal shutdown control
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -144,7 +144,7 @@ func Run(ctx context.Context, config Config) {
|
|||||||
if id != "" && secret != "" && endpoint != "" {
|
if id != "" && secret != "" && endpoint != "" {
|
||||||
logger.Info("Starting tunnel with new credentials")
|
logger.Info("Starting tunnel with new credentials")
|
||||||
tunnelRunning = true
|
tunnelRunning = true
|
||||||
go TunnelProcess(ctx, config, id, secret, userToken, endpoint)
|
go StartTunnel(ctx, config, id, secret, userToken, endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-apiServer.GetDisconnectChannel():
|
case <-apiServer.GetDisconnectChannel():
|
||||||
@@ -161,7 +161,7 @@ func Run(ctx context.Context, config Config) {
|
|||||||
if id != "" && secret != "" && endpoint != "" && !tunnelRunning {
|
if id != "" && secret != "" && endpoint != "" && !tunnelRunning {
|
||||||
logger.Info("Starting tunnel process with initial credentials")
|
logger.Info("Starting tunnel process with initial credentials")
|
||||||
tunnelRunning = true
|
tunnelRunning = true
|
||||||
go TunnelProcess(ctx, config, id, secret, userToken, endpoint)
|
go StartTunnel(ctx, config, id, secret, userToken, endpoint)
|
||||||
} else if id == "" || secret == "" || endpoint == "" {
|
} else if id == "" || secret == "" || endpoint == "" {
|
||||||
// If we don't have credentials, check if API is enabled
|
// If we don't have credentials, check if API is enabled
|
||||||
if !config.EnableAPI {
|
if !config.EnableAPI {
|
||||||
@@ -187,12 +187,12 @@ func Run(ctx context.Context, config Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
Stop()
|
Close()
|
||||||
apiServer.Stop()
|
apiServer.Stop()
|
||||||
logger.Info("Olm service shutting down")
|
logger.Info("Olm service shutting down")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TunnelProcess(ctx context.Context, config Config, id string, secret string, userToken string, endpoint string) {
|
func StartTunnel(ctx context.Context, config Config, id string, secret string, userToken string, endpoint string) {
|
||||||
// Create a cancellable context for this tunnel process
|
// Create a cancellable context for this tunnel process
|
||||||
tunnelCtx, cancel := context.WithCancel(ctx)
|
tunnelCtx, cancel := context.WithCancel(ctx)
|
||||||
tunnelCancel = cancel
|
tunnelCancel = cancel
|
||||||
@@ -788,7 +788,7 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
|
|||||||
// Mark as not connected to trigger re-registration
|
// Mark as not connected to trigger re-registration
|
||||||
connected = false
|
connected = false
|
||||||
|
|
||||||
Stop()
|
Close()
|
||||||
|
|
||||||
// Clear peer statuses in API
|
// Clear peer statuses in API
|
||||||
apiServer.SetRegistered(false)
|
apiServer.SetRegistered(false)
|
||||||
@@ -812,7 +812,7 @@ func TunnelProcess(ctx context.Context, config Config, id string, secret string,
|
|||||||
logger.Info("Tunnel process context cancelled, cleaning up")
|
logger.Info("Tunnel process context cancelled, cleaning up")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Stop() {
|
func Close() {
|
||||||
// Stop hole punch manager
|
// Stop hole punch manager
|
||||||
if holePunchManager != nil {
|
if holePunchManager != nil {
|
||||||
holePunchManager.Stop()
|
holePunchManager.Stop()
|
||||||
@@ -881,7 +881,7 @@ func StopTunnel() {
|
|||||||
olmClient = nil
|
olmClient = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
Stop()
|
Close()
|
||||||
|
|
||||||
// Reset the connected state
|
// Reset the connected state
|
||||||
connected = false
|
connected = false
|
||||||
@@ -892,5 +892,7 @@ func StopTunnel() {
|
|||||||
apiServer.SetRegistered(false)
|
apiServer.SetRegistered(false)
|
||||||
apiServer.SetTunnelIP("")
|
apiServer.SetTunnelIP("")
|
||||||
|
|
||||||
|
network.ClearNetworkSettings()
|
||||||
|
|
||||||
logger.Info("Tunnel process stopped")
|
logger.Info("Tunnel process stopped")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user