Compare commits

..

4 Commits

7 changed files with 39 additions and 25 deletions
-1
View File
@@ -265,7 +265,6 @@ ENV VPN_SERVICE_PROVIDER=pia \
PPROF_HTTP_SERVER_ADDRESS=":6060" \ PPROF_HTTP_SERVER_ADDRESS=":6060" \
# Extras # Extras
VERSION_INFORMATION=on \ VERSION_INFORMATION=on \
BORINGPOLL_GLUETUNCOM=off \
TZ= \ TZ= \
PUID=1000 \ PUID=1000 \
PGID=1000 PGID=1000
-4
View File
@@ -132,10 +132,6 @@ services:
[![Star History Chart](https://api.star-history.com/svg?repos=qdm12/gluetun&type=date&legend=top-left)](https://www.star-history.com/#qdm12/gluetun&type=date&legend=top-left) [![Star History Chart](https://api.star-history.com/svg?repos=qdm12/gluetun&type=date&legend=top-left)](https://www.star-history.com/#qdm12/gluetun&type=date&legend=top-left)
## Fight AI scamming
💁 You can optionally set `BORINGPOLL_GLUETUNCOM=on` to... [poll](./internal/boringpoll/boringpoll.go) that **scammy AI slop** website every few minutes so it costs them in terms of egress traffic. My gentle email reminders to take it down are being grossly ignored 🤷 This would make me very happy and serve this community.
## License ## License
[![MIT](https://img.shields.io/github/license/qdm12/gluetun)](https://github.com/qdm12/gluetun/blob/master/LICENSE) [![MIT](https://img.shields.io/github/license/qdm12/gluetun)](https://github.com/qdm12/gluetun/blob/master/LICENSE)
+1 -1
View File
@@ -31,7 +31,7 @@ type urlData struct{}
func New(client *http.Client, logger Logger, settings settings.BoringPoll) *BoringPoll { func New(client *http.Client, logger Logger, settings settings.BoringPoll) *BoringPoll {
urlToData := make(map[string]*urlData) urlToData := make(map[string]*urlData)
if *settings.GluetunCom { if *settings.GluetunCom {
urlToData["https://gluetun.com/wp-json"] = &urlData{} logger.Infof("gluetun.com is DOWN most likely thanks to you! so not doing anything anymore")
} }
return &BoringPoll{ return &BoringPoll{
client: client, client: client,
+2
View File
@@ -53,6 +53,8 @@ func extractDataFromLines(lines []string) (
func extractDataFromLine(line string) ( func extractDataFromLine(line string) (
ip netip.Addr, port uint16, protocol string, err error, ip netip.Addr, port uint16, protocol string, err error,
) { ) {
line = strings.TrimSpace(line)
switch { switch {
case strings.HasPrefix(line, "proto "): case strings.HasPrefix(line, "proto "):
protocol, err = extractProto(line) protocol, err = extractProto(line)
+8
View File
@@ -62,6 +62,14 @@ func Test_extractDataFromLines(t *testing.T) {
Protocol: constants.UDP, Protocol: constants.UDP,
}, },
}, },
"leading_whitespace": {
lines: []string{" proto tcp", "\tremote 1.2.3.4 443 tcp"},
connection: models.Connection{
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 443,
Protocol: constants.TCP,
},
},
} }
for name, testCase := range testCases { for name, testCase := range testCases {
+7
View File
@@ -2,6 +2,7 @@ package utils
import ( import (
"fmt" "fmt"
"math/rand/v2"
"slices" "slices"
"github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/configuration/settings"
@@ -44,6 +45,12 @@ func GetConnection(provider string,
return connection, fmt.Errorf("filtering servers: %w", err) return connection, fmt.Errorf("filtering servers: %w", err)
} }
// Randomize order of the servers struct so the first connection to be picked
// won't always be the same one.
rand.Shuffle(len(servers), func(i, j int) {
servers[i], servers[j] = servers[j], servers[i]
})
protocol := getProtocol(selection) protocol := getProtocol(selection)
port := getPort(selection, defaults.OpenVPNTCPPort, port := getPort(selection, defaults.OpenVPNTCPPort,
defaults.OpenVPNUDPPort, defaults.WireguardPort) defaults.OpenVPNUDPPort, defaults.WireguardPort)
+21 -19
View File
@@ -27,11 +27,12 @@ func Test_GetConnection(t *testing.T) {
defaults ConnectionDefaults defaults ConnectionDefaults
ipv6Supported bool ipv6Supported bool
randSource rand.Source randSource rand.Source
connection models.Connection connections []models.Connection
errMessage string errMessage string
}{ }{
"storage filter error": { "storage filter error": {
filterError: errors.New("test error"), filterError: errors.New("test error"),
connections: []models.Connection{{}},
errMessage: "filtering servers: test error", errMessage: "filtering servers: test error",
}, },
"server without IPs": { "server without IPs": {
@@ -46,7 +47,8 @@ func Test_GetConnection(t *testing.T) {
OpenVPNUDPPort: 1, OpenVPNUDPPort: 1,
WireguardPort: 1, WireguardPort: 1,
}, },
errMessage: "no connection to pick from", connections: []models.Connection{{}},
errMessage: "no connection to pick from",
}, },
"OpenVPN server with hostname": { "OpenVPN server with hostname": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -61,13 +63,13 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "name", Hostname: "name",
}, }},
}, },
"OpenVPN server with x509": { "OpenVPN server with x509": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -83,13 +85,13 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "x509", Hostname: "x509",
}, }},
}, },
"server with IPv4 and IPv6": { "server with IPv4 and IPv6": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -111,12 +113,12 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
}, }},
}, },
"server with IPv4 and IPv6 and ipv6 supported": { "server with IPv4 and IPv6 and ipv6 supported": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -134,12 +136,12 @@ func Test_GetConnection(t *testing.T) {
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
ipv6Supported: true, ipv6Supported: true,
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.IPv6Unspecified(), IP: netip.IPv6Unspecified(),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
}, }},
}, },
"mixed servers": { "mixed servers": {
filteredServers: []models.Server{ filteredServers: []models.Server{
@@ -149,12 +151,6 @@ func Test_GetConnection(t *testing.T) {
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
OvpnX509: "ovpnx509", OvpnX509: "ovpnx509",
}, },
{
VPN: vpn.Wireguard,
UDP: true,
IPs: []netip.Addr{netip.AddrFrom4([4]byte{2, 2, 2, 2})},
OvpnX509: "ovpnx509",
},
{ {
VPN: vpn.OpenVPN, VPN: vpn.OpenVPN,
UDP: true, UDP: true,
@@ -169,13 +165,19 @@ func Test_GetConnection(t *testing.T) {
WithDefaults(providers.Mullvad), WithDefaults(providers.Mullvad),
defaults: NewConnectionDefaults(443, 1194, 58820), defaults: NewConnectionDefaults(443, 1194, 58820),
randSource: rand.NewSource(0), randSource: rand.NewSource(0),
connection: models.Connection{ connections: []models.Connection{{
Type: vpn.OpenVPN, Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}), IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Protocol: constants.UDP, Protocol: constants.UDP,
Port: 1194, Port: 1194,
Hostname: "ovpnx509", Hostname: "ovpnx509",
}, }, {
Type: vpn.OpenVPN,
IP: netip.AddrFrom4([4]byte{3, 3, 3, 3}),
Protocol: constants.UDP,
Port: 1194,
Hostname: "hostname",
}},
}, },
} }
@@ -194,7 +196,7 @@ func Test_GetConnection(t *testing.T) {
testCase.serverSelection, testCase.defaults, testCase.ipv6Supported, testCase.serverSelection, testCase.defaults, testCase.ipv6Supported,
connPicker) connPicker)
assert.Equal(t, testCase.connection, connection) assert.Contains(t, testCase.connections, connection)
if testCase.errMessage != "" { if testCase.errMessage != "" {
assert.EqualError(t, err, testCase.errMessage) assert.EqualError(t, err, testCase.errMessage)
} else { } else {