chore(updater): move updater packages to pkg/updaters/<name>

This commit is contained in:
Quentin McGaw
2026-04-23 03:47:57 +00:00
parent 5b01324d5f
commit 13503b0ae0
268 changed files with 1602 additions and 1026 deletions
+4 -3
View File
@@ -5,8 +5,9 @@ import (
"slices"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
)
type ConnectionDefaults struct {
@@ -27,7 +28,7 @@ func NewConnectionDefaults(openvpnTCPPort, openvpnUDPPort,
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (
servers []models.Server, err error)
servers []umodels.Server, err error)
}
func GetConnection(provider string,
@@ -56,7 +57,7 @@ func GetConnection(provider string,
}
hostname := server.Hostname
if selection.VPN == vpn.OpenVPN && server.OvpnX509 != "" {
if selection.VPN == constants.OpenVPN && server.OvpnX509 != "" {
// For Windscribe where hostname and
// OpenVPN x509 are not the same.
hostname = server.OvpnX509
+23 -23
View File
@@ -8,11 +8,11 @@ import (
"github.com/golang/mock/gomock"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/common"
"github.com/qdm12/gluetun/pkg/updaters/constants"
umodels "github.com/qdm12/gluetun/pkg/updaters/models"
"github.com/stretchr/testify/assert"
)
@@ -21,7 +21,7 @@ func Test_GetConnection(t *testing.T) {
testCases := map[string]struct {
provider string
filteredServers []models.Server
filteredServers []umodels.Server
filterError error
serverSelection settings.ServerSelection
defaults ConnectionDefaults
@@ -35,9 +35,9 @@ func Test_GetConnection(t *testing.T) {
errMessage: "filtering servers: test error",
},
"server without IPs": {
filteredServers: []models.Server{
{VPN: vpn.OpenVPN, UDP: true},
{VPN: vpn.OpenVPN, UDP: true},
filteredServers: []umodels.Server{
{VPN: constants.OpenVPN, UDP: true},
{VPN: constants.OpenVPN, UDP: true},
},
serverSelection: settings.ServerSelection{}.
WithDefaults(providers.Mullvad),
@@ -49,9 +49,9 @@ func Test_GetConnection(t *testing.T) {
errMessage: "no connection to pick from",
},
"OpenVPN server with hostname": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
Hostname: "name",
@@ -62,7 +62,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
@@ -70,9 +70,9 @@ func Test_GetConnection(t *testing.T) {
},
},
"OpenVPN server with x509": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
Hostname: "hostname",
@@ -84,7 +84,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
@@ -92,9 +92,9 @@ func Test_GetConnection(t *testing.T) {
},
},
"server with IPv4 and IPv6": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
@@ -112,16 +112,16 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
},
},
"server with IPv4 and IPv6 and ipv6 supported": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
@@ -135,28 +135,28 @@ func Test_GetConnection(t *testing.T) {
ipv6Supported: true,
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.IPv6Unspecified(),
Protocol: constants.UDP,
Port: 1194,
},
},
"mixed servers": {
filteredServers: []models.Server{
filteredServers: []umodels.Server{
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
OvpnX509: "ovpnx509",
},
{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{2, 2, 2, 2})},
OvpnX509: "ovpnx509",
},
{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
UDP: true,
IPs: []netip.Addr{
netip.AddrFrom4([4]byte{3, 3, 3, 3}),
@@ -170,7 +170,7 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0),
connection: models.Connection{
Type: vpn.OpenVPN,
Type: constants.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP,
Port: 1194,
+9 -1
View File
@@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/models"
)
type NoFetcher struct {
@@ -22,3 +22,11 @@ func (n *NoFetcher) FetchServers(context.Context, int) (
) {
return nil, fmt.Errorf("fetching of servers is not supported for %s", n.providerName)
}
func (n *NoFetcher) Version() uint16 {
return 1
}
func (n *NoFetcher) Name() string {
return n.providerName
}
+1 -1
View File
@@ -5,10 +5,10 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/openvpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/openvpn/pkcs8"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
type OpenVPNProviderSettings struct {
+4 -4
View File
@@ -9,8 +9,8 @@ import (
"sync"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
// ConnectionPicker is a struct that holds the state of the connection pool cycler.
@@ -89,16 +89,16 @@ func pickConnection(connections []models.Connection,
var targetIP netip.Addr
switch selection.VPN {
case vpn.OpenVPN:
case constants.OpenVPN:
targetIP = selection.OpenVPN.EndpointIP
case vpn.Wireguard, vpn.AmneziaWg:
case constants.Wireguard, constants.AmneziaWg:
targetIP = selection.Wireguard.EndpointIP
default:
panic("unknown VPN type: " + selection.VPN)
}
targetIPSet := targetIP.IsValid() && !targetIP.IsUnspecified()
if targetIPSet && selection.VPN == vpn.Wireguard {
if targetIPSet && selection.VPN == constants.Wireguard {
// we need the right public key
return getTargetIPConnection(connections, targetIP)
}
+16 -16
View File
@@ -5,8 +5,8 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -58,56 +58,56 @@ func Test_pickConnection(t *testing.T) {
},
"openvpn_cycles": {
connections: []models.Connection{
{Type: vpn.OpenVPN, Port: 1, Hostname: "one"},
{Type: vpn.OpenVPN, Port: 2, Hostname: "two"},
{Type: constants.OpenVPN, Port: 1, Hostname: "one"},
{Type: constants.OpenVPN, Port: 2, Hostname: "two"},
},
selection: settings.ServerSelection{VPN: vpn.OpenVPN},
selection: settings.ServerSelection{VPN: constants.OpenVPN},
connection1: models.Connection{
Type: vpn.OpenVPN, Port: 1,
Type: constants.OpenVPN, Port: 1,
Hostname: "one",
},
connection2: models.Connection{
Type: vpn.OpenVPN, Port: 2,
Type: constants.OpenVPN, Port: 2,
Hostname: "two",
},
},
"openvpn_endpoint_ip_overrides_cycle_pick": {
connections: []models.Connection{
{Type: vpn.OpenVPN, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: vpn.OpenVPN, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
{Type: constants.OpenVPN, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: constants.OpenVPN, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
},
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
EndpointIP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
},
connection1: models.Connection{
Type: vpn.OpenVPN, Hostname: "one",
Type: constants.OpenVPN, Hostname: "one",
IP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
connection2: models.Connection{
Type: vpn.OpenVPN, Hostname: "two",
Type: constants.OpenVPN, Hostname: "two",
IP: netip.AddrFrom4([4]byte{9, 9, 9, 9}),
},
},
"wireguard_endpoint_ip_picks_target": {
connections: []models.Connection{
{Type: vpn.Wireguard, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: vpn.Wireguard, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
{Type: constants.Wireguard, Hostname: "one", IP: netip.AddrFrom4([4]byte{1, 1, 1, 1})},
{Type: constants.Wireguard, Hostname: "two", IP: netip.AddrFrom4([4]byte{2, 2, 2, 2})},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointIP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
},
connection1: models.Connection{
Type: vpn.Wireguard, Hostname: "two",
Type: constants.Wireguard, Hostname: "two",
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
connection2: models.Connection{
Type: vpn.Wireguard, Hostname: "two",
Type: constants.Wireguard, Hostname: "two",
IP: netip.AddrFrom4([4]byte{2, 2, 2, 2}),
},
},
+2 -3
View File
@@ -4,15 +4,14 @@ import (
"fmt"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func getPort(selection settings.ServerSelection,
defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16,
) (port uint16) {
switch selection.VPN {
case vpn.Wireguard:
case constants.Wireguard:
customPort := *selection.Wireguard.EndpointPort
if customPort > 0 {
return customPort
+9 -10
View File
@@ -4,8 +4,7 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -37,7 +36,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.UDP,
@@ -50,7 +49,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN UDP no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.UDP,
@@ -60,7 +59,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.TCP,
@@ -71,7 +70,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN TCP no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(0),
Protocol: constants.TCP,
@@ -81,7 +80,7 @@ func Test_GetPort(t *testing.T) {
},
"OpenVPN custom port": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
CustomPort: uint16Ptr(1234),
},
@@ -90,14 +89,14 @@ func Test_GetPort(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(""),
defaultWireguard: defaultWireguard,
port: defaultWireguard,
},
"Wireguard custom port": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
Wireguard: settings.WireguardSelection{
EndpointPort: uint16Ptr(1234),
},
@@ -107,7 +106,7 @@ func Test_GetPort(t *testing.T) {
},
"Wireguard no default port defined": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
}.WithDefaults(""),
panics: "no default Wireguard port is defined!",
},
+3 -4
View File
@@ -2,12 +2,11 @@ package utils
import (
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
)
func getProtocol(selection settings.ServerSelection) (protocol string) {
if selection.VPN == vpn.OpenVPN && selection.OpenVPN.Protocol == constants.TCP {
if selection.VPN == constants.OpenVPN && selection.OpenVPN.Protocol == constants.TCP {
return constants.TCP
}
return constants.UDP
@@ -17,7 +16,7 @@ func filterByProtocol(selection settings.ServerSelection,
serverTCP, serverUDP bool,
) (filtered bool) {
switch selection.VPN {
case vpn.Wireguard:
case constants.Wireguard:
return !serverUDP
default: // OpenVPN
wantTCP := selection.OpenVPN.Protocol == constants.TCP
+10 -11
View File
@@ -4,8 +4,7 @@ import (
"testing"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/pkg/updaters/constants"
"github.com/stretchr/testify/assert"
)
@@ -21,7 +20,7 @@ func Test_getProtocol(t *testing.T) {
},
"OpenVPN UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -30,7 +29,7 @@ func Test_getProtocol(t *testing.T) {
},
"OpenVPN TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},
@@ -39,7 +38,7 @@ func Test_getProtocol(t *testing.T) {
},
"Wireguard": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
protocol: constants.UDP,
},
@@ -67,21 +66,21 @@ func Test_filterByProtocol(t *testing.T) {
}{
"Wireguard and server has UDP": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
serverUDP: true,
filtered: false,
},
"Wireguard and server has not UDP": {
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
VPN: constants.Wireguard,
},
serverUDP: false,
filtered: true,
},
"OpenVPN UDP and server has UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -91,7 +90,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN UDP and server has not UDP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.UDP,
},
@@ -101,7 +100,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},
@@ -111,7 +110,7 @@ func Test_filterByProtocol(t *testing.T) {
},
"OpenVPN TCP and server has not TCP": {
selection: settings.ServerSelection{
VPN: vpn.OpenVPN,
VPN: constants.OpenVPN,
OpenVPN: settings.OpenVPNSelection{
Protocol: constants.TCP,
},