Maint: internal/vpn package for vpn loop

This commit is contained in:
Quentin McGaw (desktop)
2021-08-18 22:01:04 +00:00
parent 05018ec971
commit d4ca5cf257
20 changed files with 60 additions and 60 deletions

View File

@@ -7,16 +7,16 @@ import (
"github.com/qdm12/gluetun/internal/dns"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn"
"github.com/qdm12/gluetun/internal/portforward"
"github.com/qdm12/gluetun/internal/publicip"
"github.com/qdm12/gluetun/internal/updater"
"github.com/qdm12/gluetun/internal/vpn"
"github.com/qdm12/golibs/logging"
)
func newHandler(ctx context.Context, logger logging.Logger, logging bool,
buildInfo models.BuildInformation,
openvpnLooper openvpn.Looper,
vpnLooper vpn.Looper,
pfGetter portforward.Getter,
unboundLooper dns.Looper,
updaterLooper updater.Looper,
@@ -24,12 +24,12 @@ func newHandler(ctx context.Context, logger logging.Logger, logging bool,
) http.Handler {
handler := &handler{}
openvpn := newOpenvpnHandler(ctx, openvpnLooper, pfGetter, logger)
openvpn := newOpenvpnHandler(ctx, vpnLooper, pfGetter, logger)
dns := newDNSHandler(ctx, unboundLooper, logger)
updater := newUpdaterHandler(ctx, updaterLooper, logger)
publicip := newPublicIPHandler(publicIPLooper, logger)
handler.v0 = newHandlerV0(ctx, logger, openvpnLooper, unboundLooper, updaterLooper)
handler.v0 = newHandlerV0(ctx, logger, vpnLooper, unboundLooper, updaterLooper)
handler.v1 = newHandlerV1(logger, buildInfo, openvpn, dns, updater, publicip)
handlerWithLog := withLogMiddleware(handler, logger, logging)

View File

@@ -6,17 +6,17 @@ import (
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/dns"
"github.com/qdm12/gluetun/internal/openvpn"
"github.com/qdm12/gluetun/internal/updater"
"github.com/qdm12/gluetun/internal/vpn"
"github.com/qdm12/golibs/logging"
)
func newHandlerV0(ctx context.Context, logger logging.Logger,
openvpn openvpn.Looper, dns dns.Looper, updater updater.Looper) http.Handler {
vpn vpn.Looper, dns dns.Looper, updater updater.Looper) http.Handler {
return &handlerV0{
ctx: ctx,
logger: logger,
openvpn: openvpn,
vpn: vpn,
dns: dns,
updater: updater,
}
@@ -25,7 +25,7 @@ func newHandlerV0(ctx context.Context, logger logging.Logger,
type handlerV0 struct {
ctx context.Context
logger logging.Logger
openvpn openvpn.Looper
vpn vpn.Looper
dns dns.Looper
updater updater.Looper
}
@@ -39,9 +39,9 @@ func (h *handlerV0) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "/version":
http.Redirect(w, r, "/v1/version", http.StatusPermanentRedirect)
case "/openvpn/actions/restart":
outcome, _ := h.openvpn.ApplyStatus(h.ctx, constants.Stopped)
outcome, _ := h.vpn.ApplyStatus(h.ctx, constants.Stopped)
h.logger.Info("openvpn: " + outcome)
outcome, _ = h.openvpn.ApplyStatus(h.ctx, constants.Running)
outcome, _ = h.vpn.ApplyStatus(h.ctx, constants.Running)
h.logger.Info("openvpn: " + outcome)
if _, err := w.Write([]byte("openvpn restarted, please consider using the /v1/ API in the future.")); err != nil {
h.logger.Warn(err.Error())

View File

@@ -6,12 +6,12 @@ import (
"net/http"
"strings"
"github.com/qdm12/gluetun/internal/openvpn"
"github.com/qdm12/gluetun/internal/portforward"
"github.com/qdm12/gluetun/internal/vpn"
"github.com/qdm12/golibs/logging"
)
func newOpenvpnHandler(ctx context.Context, looper openvpn.Looper,
func newOpenvpnHandler(ctx context.Context, looper vpn.Looper,
pfGetter portforward.Getter, logger logging.Logger) http.Handler {
return &openvpnHandler{
ctx: ctx,
@@ -23,7 +23,7 @@ func newOpenvpnHandler(ctx context.Context, looper openvpn.Looper,
type openvpnHandler struct {
ctx context.Context
looper openvpn.Looper
looper vpn.Looper
pf portforward.Getter
logger logging.Logger
}

View File

@@ -9,10 +9,10 @@ import (
"github.com/qdm12/gluetun/internal/dns"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn"
"github.com/qdm12/gluetun/internal/portforward"
"github.com/qdm12/gluetun/internal/publicip"
"github.com/qdm12/gluetun/internal/updater"
"github.com/qdm12/gluetun/internal/vpn"
"github.com/qdm12/golibs/logging"
)
@@ -27,7 +27,7 @@ type server struct {
}
func New(ctx context.Context, address string, logEnabled bool, logger logging.Logger,
buildInfo models.BuildInformation, openvpnLooper openvpn.Looper,
buildInfo models.BuildInformation, openvpnLooper vpn.Looper,
pfGetter portforward.Getter, unboundLooper dns.Looper,
updaterLooper updater.Looper, publicIPLooper publicip.Looper) Server {
handler := newHandler(ctx, logger, logEnabled, buildInfo,