Maint: better openvpn loop interface composition
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package openvpn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -17,17 +16,13 @@ import (
|
||||
)
|
||||
|
||||
type Looper interface {
|
||||
Run(ctx context.Context, done chan<- struct{})
|
||||
GetStatus() (status models.LoopStatus)
|
||||
ApplyStatus(ctx context.Context, status models.LoopStatus) (
|
||||
outcome string, err error)
|
||||
GetSettings() (settings configuration.OpenVPN)
|
||||
SetSettings(ctx context.Context, settings configuration.OpenVPN) (
|
||||
outcome string)
|
||||
GetServers() (servers models.AllServers)
|
||||
SetServers(servers models.AllServers)
|
||||
GetPortForwarded() (port uint16)
|
||||
PortForward(vpnGatewayIP net.IP)
|
||||
Runner
|
||||
loopstate.Getter
|
||||
loopstate.Applier
|
||||
SettingsGetterSetter
|
||||
ServersGetterSetter
|
||||
PortForwadedGetter
|
||||
PortForwader
|
||||
}
|
||||
|
||||
type looper struct {
|
||||
|
||||
@@ -7,13 +7,20 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/openvpn/state"
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
)
|
||||
|
||||
type PortForwadedGetter = state.PortForwardedGetter
|
||||
|
||||
func (l *looper) GetPortForwarded() (port uint16) {
|
||||
return l.state.GetPortForwarded()
|
||||
}
|
||||
|
||||
type PortForwader interface {
|
||||
PortForward(vpnGatewayIP net.IP)
|
||||
}
|
||||
|
||||
func (l *looper) PortForward(vpnGateway net.IP) { l.portForwardSignals <- vpnGateway }
|
||||
|
||||
// portForward is a blocking operation which may or may not be infinite.
|
||||
|
||||
@@ -9,6 +9,10 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider"
|
||||
)
|
||||
|
||||
type Runner interface {
|
||||
Run(ctx context.Context, done chan<- struct{})
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
|
||||
defer close(done)
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package openvpn
|
||||
|
||||
import "github.com/qdm12/gluetun/internal/models"
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/state"
|
||||
)
|
||||
|
||||
type ServersGetterSetter = state.ServersGetterSetter
|
||||
|
||||
func (l *looper) GetServers() (servers models.AllServers) {
|
||||
return l.state.GetServers()
|
||||
|
||||
@@ -4,8 +4,11 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/state"
|
||||
)
|
||||
|
||||
type SettingsGetterSetter = state.SettingsGetterSetter
|
||||
|
||||
func (l *looper) GetSettings() (settings configuration.OpenVPN) {
|
||||
return l.state.GetSettings()
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package state
|
||||
|
||||
type PortForwardedGetterSetter interface {
|
||||
GetPortForwarded() (port uint16)
|
||||
PortForwardedGetter
|
||||
SetPortForwarded(port uint16)
|
||||
}
|
||||
|
||||
type PortForwardedGetter interface {
|
||||
GetPortForwarded() (port uint16)
|
||||
}
|
||||
|
||||
// GetPortForwarded is used by the control HTTP server
|
||||
// to obtain the port currently forwarded.
|
||||
func (s *State) GetPortForwarded() (port uint16) {
|
||||
|
||||
Reference in New Issue
Block a user