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