diff --git a/cmd/gluetun/main.go b/cmd/gluetun/main.go index b3734ea8..f2536b61 100644 --- a/cmd/gluetun/main.go +++ b/cmd/gluetun/main.go @@ -321,7 +321,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation, tickersGroupHandler := goshutdown.NewGroupHandler("tickers", defaultGroupSettings) otherGroupHandler := goshutdown.NewGroupHandler("other", defaultGroupSettings) - openvpnLooper := openvpn.NewLooper(allSettings.OpenVPN, nonRootUsername, puid, pgid, allServers, + openvpnLooper := openvpn.NewLoop(allSettings.OpenVPN, nonRootUsername, puid, pgid, allServers, ovpnConf, firewallConf, routingConf, logger, httpClient, tunnelReadyCh) openvpnHandler, openvpnCtx, openvpnDone := goshutdown.NewGoRoutineHandler( "openvpn", goshutdown.GoRoutineSettings{Timeout: time.Second}) diff --git a/internal/openvpn/custom.go b/internal/openvpn/custom.go index c7f02c2b..b35b7d45 100644 --- a/internal/openvpn/custom.go +++ b/internal/openvpn/custom.go @@ -17,7 +17,7 @@ import ( var errProcessCustomConfig = errors.New("cannot process custom config") -func (l *looper) processCustomConfig(settings configuration.OpenVPN) ( +func (l *Loop) processCustomConfig(settings configuration.OpenVPN) ( lines []string, connection models.OpenVPNConnection, err error) { lines, err = readCustomConfigLines(settings.Config) if err != nil { diff --git a/internal/openvpn/helpers.go b/internal/openvpn/helpers.go index e8c2f44b..8145c0a4 100644 --- a/internal/openvpn/helpers.go +++ b/internal/openvpn/helpers.go @@ -7,7 +7,7 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -func (l *looper) signalOrSetStatus(status models.LoopStatus) { +func (l *Loop) signalOrSetStatus(status models.LoopStatus) { if l.userTrigger { l.userTrigger = false select { @@ -19,7 +19,7 @@ func (l *looper) signalOrSetStatus(status models.LoopStatus) { } } -func (l *looper) logAndWait(ctx context.Context, err error) { +func (l *Loop) logAndWait(ctx context.Context, err error) { if err != nil { l.logger.Error(err.Error()) } diff --git a/internal/openvpn/logs.go b/internal/openvpn/logs.go index 7957dbb8..31f01e1b 100644 --- a/internal/openvpn/logs.go +++ b/internal/openvpn/logs.go @@ -8,7 +8,7 @@ import ( "github.com/qdm12/golibs/logging" ) -func (l *looper) collectLines(stdout, stderr <-chan string, done chan<- struct{}) { +func (l *Loop) collectLines(stdout, stderr <-chan string, done chan<- struct{}) { defer close(done) var line string var ok, errLine bool diff --git a/internal/openvpn/loop.go b/internal/openvpn/loop.go index bb2810f2..8840f468 100644 --- a/internal/openvpn/loop.go +++ b/internal/openvpn/loop.go @@ -25,7 +25,7 @@ type Looper interface { PortForwader } -type looper struct { +type Loop struct { statusManager loopstate.Manager state state.Manager // Fixed parameters @@ -56,11 +56,11 @@ const ( defaultBackoffTime = 15 * time.Second ) -func NewLooper(settings configuration.OpenVPN, +func NewLoop(settings configuration.OpenVPN, username string, puid, pgid int, allServers models.AllServers, conf Configurator, fw firewall.Configurator, routing routing.Routing, logger logging.ParentLogger, client *http.Client, - tunnelReady chan<- struct{}) Looper { + tunnelReady chan<- struct{}) *Loop { start := make(chan struct{}) running := make(chan models.LoopStatus) stop := make(chan struct{}) @@ -69,7 +69,7 @@ func NewLooper(settings configuration.OpenVPN, statusManager := loopstate.New(constants.Stopped, start, running, stop, stopped) state := state.New(statusManager, settings, allServers) - return &looper{ + return &Loop{ statusManager: statusManager, state: state, username: username, diff --git a/internal/openvpn/portforwarded.go b/internal/openvpn/portforwarded.go index 600ada2a..083bb162 100644 --- a/internal/openvpn/portforwarded.go +++ b/internal/openvpn/portforwarded.go @@ -13,7 +13,7 @@ import ( type PortForwadedGetter = state.PortForwardedGetter -func (l *looper) GetPortForwarded() (port uint16) { +func (l *Loop) GetPortForwarded() (port uint16) { return l.state.GetPortForwarded() } @@ -21,11 +21,11 @@ type PortForwader interface { PortForward(vpnGatewayIP net.IP) } -func (l *looper) PortForward(vpnGateway net.IP) { l.portForwardSignals <- vpnGateway } +func (l *Loop) PortForward(vpnGateway net.IP) { l.portForwardSignals <- vpnGateway } // portForward is a blocking operation which may or may not be infinite. // You should therefore always call it in a goroutine. -func (l *looper) portForward(ctx context.Context, +func (l *Loop) portForward(ctx context.Context, providerConf provider.Provider, client *http.Client, gateway net.IP) { settings := l.state.GetSettings() if !settings.Provider.PortForwarding.Enabled { @@ -40,7 +40,7 @@ func (l *looper) portForward(ctx context.Context, gateway, l.fw, syncState) } -func (l *looper) writeOpenvpnConf(lines []string) error { +func (l *Loop) writeOpenvpnConf(lines []string) error { file, err := os.OpenFile(l.targetConfPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) if err != nil { return err diff --git a/internal/openvpn/run.go b/internal/openvpn/run.go index 3f923e10..51fbe38a 100644 --- a/internal/openvpn/run.go +++ b/internal/openvpn/run.go @@ -13,7 +13,7 @@ type Runner interface { Run(ctx context.Context, done chan<- struct{}) } -func (l *looper) Run(ctx context.Context, done chan<- struct{}) { +func (l *Loop) Run(ctx context.Context, done chan<- struct{}) { defer close(done) select { diff --git a/internal/openvpn/servers.go b/internal/openvpn/servers.go index 80a36ee1..3f03a814 100644 --- a/internal/openvpn/servers.go +++ b/internal/openvpn/servers.go @@ -7,10 +7,10 @@ import ( type ServersGetterSetter = state.ServersGetterSetter -func (l *looper) GetServers() (servers models.AllServers) { +func (l *Loop) GetServers() (servers models.AllServers) { return l.state.GetServers() } -func (l *looper) SetServers(servers models.AllServers) { +func (l *Loop) SetServers(servers models.AllServers) { l.state.SetServers(servers) } diff --git a/internal/openvpn/settings.go b/internal/openvpn/settings.go index 4b3078bc..244b7d9c 100644 --- a/internal/openvpn/settings.go +++ b/internal/openvpn/settings.go @@ -9,11 +9,11 @@ import ( type SettingsGetterSetter = state.SettingsGetterSetter -func (l *looper) GetSettings() (settings configuration.OpenVPN) { +func (l *Loop) GetSettings() (settings configuration.OpenVPN) { return l.state.GetSettings() } -func (l *looper) SetSettings(ctx context.Context, settings configuration.OpenVPN) ( +func (l *Loop) SetSettings(ctx context.Context, settings configuration.OpenVPN) ( outcome string) { return l.state.SetSettings(ctx, settings) } diff --git a/internal/openvpn/status.go b/internal/openvpn/status.go index 1ba530dc..bc1b327a 100644 --- a/internal/openvpn/status.go +++ b/internal/openvpn/status.go @@ -6,11 +6,11 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -func (l *looper) GetStatus() (status models.LoopStatus) { +func (l *Loop) GetStatus() (status models.LoopStatus) { return l.statusManager.GetStatus() } -func (l *looper) ApplyStatus(ctx context.Context, status models.LoopStatus) ( +func (l *Loop) ApplyStatus(ctx context.Context, status models.LoopStatus) ( outcome string, err error) { return l.statusManager.ApplyStatus(ctx, status) }