Maint: openvpn loop is a concrete struct
This commit is contained in:
@@ -321,7 +321,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
tickersGroupHandler := goshutdown.NewGroupHandler("tickers", defaultGroupSettings)
|
tickersGroupHandler := goshutdown.NewGroupHandler("tickers", defaultGroupSettings)
|
||||||
otherGroupHandler := goshutdown.NewGroupHandler("other", 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)
|
ovpnConf, firewallConf, routingConf, logger, httpClient, tunnelReadyCh)
|
||||||
openvpnHandler, openvpnCtx, openvpnDone := goshutdown.NewGoRoutineHandler(
|
openvpnHandler, openvpnCtx, openvpnDone := goshutdown.NewGoRoutineHandler(
|
||||||
"openvpn", goshutdown.GoRoutineSettings{Timeout: time.Second})
|
"openvpn", goshutdown.GoRoutineSettings{Timeout: time.Second})
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
|
|
||||||
var errProcessCustomConfig = errors.New("cannot process custom config")
|
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 []string, connection models.OpenVPNConnection, err error) {
|
||||||
lines, err = readCustomConfigLines(settings.Config)
|
lines, err = readCustomConfigLines(settings.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *looper) signalOrSetStatus(status models.LoopStatus) {
|
func (l *Loop) signalOrSetStatus(status models.LoopStatus) {
|
||||||
if l.userTrigger {
|
if l.userTrigger {
|
||||||
l.userTrigger = false
|
l.userTrigger = false
|
||||||
select {
|
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 {
|
if err != nil {
|
||||||
l.logger.Error(err.Error())
|
l.logger.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/qdm12/golibs/logging"
|
"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)
|
defer close(done)
|
||||||
var line string
|
var line string
|
||||||
var ok, errLine bool
|
var ok, errLine bool
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type Looper interface {
|
|||||||
PortForwader
|
PortForwader
|
||||||
}
|
}
|
||||||
|
|
||||||
type looper struct {
|
type Loop struct {
|
||||||
statusManager loopstate.Manager
|
statusManager loopstate.Manager
|
||||||
state state.Manager
|
state state.Manager
|
||||||
// Fixed parameters
|
// Fixed parameters
|
||||||
@@ -56,11 +56,11 @@ const (
|
|||||||
defaultBackoffTime = 15 * time.Second
|
defaultBackoffTime = 15 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewLooper(settings configuration.OpenVPN,
|
func NewLoop(settings configuration.OpenVPN,
|
||||||
username string, puid, pgid int, allServers models.AllServers,
|
username string, puid, pgid int, allServers models.AllServers,
|
||||||
conf Configurator, fw firewall.Configurator, routing routing.Routing,
|
conf Configurator, fw firewall.Configurator, routing routing.Routing,
|
||||||
logger logging.ParentLogger, client *http.Client,
|
logger logging.ParentLogger, client *http.Client,
|
||||||
tunnelReady chan<- struct{}) Looper {
|
tunnelReady chan<- struct{}) *Loop {
|
||||||
start := make(chan struct{})
|
start := make(chan struct{})
|
||||||
running := make(chan models.LoopStatus)
|
running := make(chan models.LoopStatus)
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
@@ -69,7 +69,7 @@ func NewLooper(settings configuration.OpenVPN,
|
|||||||
statusManager := loopstate.New(constants.Stopped, start, running, stop, stopped)
|
statusManager := loopstate.New(constants.Stopped, start, running, stop, stopped)
|
||||||
state := state.New(statusManager, settings, allServers)
|
state := state.New(statusManager, settings, allServers)
|
||||||
|
|
||||||
return &looper{
|
return &Loop{
|
||||||
statusManager: statusManager,
|
statusManager: statusManager,
|
||||||
state: state,
|
state: state,
|
||||||
username: username,
|
username: username,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
type PortForwadedGetter = state.PortForwardedGetter
|
type PortForwadedGetter = state.PortForwardedGetter
|
||||||
|
|
||||||
func (l *looper) GetPortForwarded() (port uint16) {
|
func (l *Loop) GetPortForwarded() (port uint16) {
|
||||||
return l.state.GetPortForwarded()
|
return l.state.GetPortForwarded()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,11 +21,11 @@ type PortForwader interface {
|
|||||||
PortForward(vpnGatewayIP net.IP)
|
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.
|
// portForward is a blocking operation which may or may not be infinite.
|
||||||
// You should therefore always call it in a goroutine.
|
// 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) {
|
providerConf provider.Provider, client *http.Client, gateway net.IP) {
|
||||||
settings := l.state.GetSettings()
|
settings := l.state.GetSettings()
|
||||||
if !settings.Provider.PortForwarding.Enabled {
|
if !settings.Provider.PortForwarding.Enabled {
|
||||||
@@ -40,7 +40,7 @@ func (l *looper) portForward(ctx context.Context,
|
|||||||
gateway, l.fw, syncState)
|
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)
|
file, err := os.OpenFile(l.targetConfPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type Runner interface {
|
|||||||
Run(ctx context.Context, done chan<- struct{})
|
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)
|
defer close(done)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
|
|
||||||
type ServersGetterSetter = state.ServersGetterSetter
|
type ServersGetterSetter = state.ServersGetterSetter
|
||||||
|
|
||||||
func (l *looper) GetServers() (servers models.AllServers) {
|
func (l *Loop) GetServers() (servers models.AllServers) {
|
||||||
return l.state.GetServers()
|
return l.state.GetServers()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *looper) SetServers(servers models.AllServers) {
|
func (l *Loop) SetServers(servers models.AllServers) {
|
||||||
l.state.SetServers(servers)
|
l.state.SetServers(servers)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import (
|
|||||||
|
|
||||||
type SettingsGetterSetter = state.SettingsGetterSetter
|
type SettingsGetterSetter = state.SettingsGetterSetter
|
||||||
|
|
||||||
func (l *looper) GetSettings() (settings configuration.OpenVPN) {
|
func (l *Loop) GetSettings() (settings configuration.OpenVPN) {
|
||||||
return l.state.GetSettings()
|
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) {
|
outcome string) {
|
||||||
return l.state.SetSettings(ctx, settings)
|
return l.state.SetSettings(ctx, settings)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *looper) GetStatus() (status models.LoopStatus) {
|
func (l *Loop) GetStatus() (status models.LoopStatus) {
|
||||||
return l.statusManager.GetStatus()
|
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) {
|
outcome string, err error) {
|
||||||
return l.statusManager.ApplyStatus(ctx, status)
|
return l.statusManager.ApplyStatus(ctx, status)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user