mirror of
https://github.com/qdm12/gluetun.git
synced 2026-07-22 02:16:29 +02:00
Compare commits
4 Commits
5b01324d5f
...
cd19093d1d
| Author | SHA1 | Date | |
|---|---|---|---|
| cd19093d1d | |||
| fd12e5f9e7 | |||
| 3ca4b48887 | |||
| 38cf094573 |
@@ -265,7 +265,6 @@ ENV VPN_SERVICE_PROVIDER=pia \
|
||||
PPROF_HTTP_SERVER_ADDRESS=":6060" \
|
||||
# Extras
|
||||
VERSION_INFORMATION=on \
|
||||
BORINGPOLL_GLUETUNCOM=off \
|
||||
TZ= \
|
||||
PUID=1000 \
|
||||
PGID=1000
|
||||
|
||||
@@ -132,10 +132,6 @@ services:
|
||||
|
||||
[](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
|
||||
|
||||
[](https://github.com/qdm12/gluetun/blob/master/LICENSE)
|
||||
|
||||
@@ -31,7 +31,7 @@ type urlData struct{}
|
||||
func New(client *http.Client, logger Logger, settings settings.BoringPoll) *BoringPoll {
|
||||
urlToData := make(map[string]*urlData)
|
||||
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{
|
||||
client: client,
|
||||
|
||||
@@ -53,6 +53,8 @@ func extractDataFromLines(lines []string) (
|
||||
func extractDataFromLine(line string) (
|
||||
ip netip.Addr, port uint16, protocol string, err error,
|
||||
) {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(line, "proto "):
|
||||
protocol, err = extractProto(line)
|
||||
|
||||
@@ -62,6 +62,14 @@ func Test_extractDataFromLines(t *testing.T) {
|
||||
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 {
|
||||
|
||||
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"slices"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
@@ -44,6 +45,12 @@ func GetConnection(provider string,
|
||||
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)
|
||||
port := getPort(selection, defaults.OpenVPNTCPPort,
|
||||
defaults.OpenVPNUDPPort, defaults.WireguardPort)
|
||||
|
||||
@@ -27,11 +27,12 @@ func Test_GetConnection(t *testing.T) {
|
||||
defaults ConnectionDefaults
|
||||
ipv6Supported bool
|
||||
randSource rand.Source
|
||||
connection models.Connection
|
||||
connections []models.Connection
|
||||
errMessage string
|
||||
}{
|
||||
"storage filter error": {
|
||||
filterError: errors.New("test error"),
|
||||
connections: []models.Connection{{}},
|
||||
errMessage: "filtering servers: test error",
|
||||
},
|
||||
"server without IPs": {
|
||||
@@ -46,7 +47,8 @@ func Test_GetConnection(t *testing.T) {
|
||||
OpenVPNUDPPort: 1,
|
||||
WireguardPort: 1,
|
||||
},
|
||||
errMessage: "no connection to pick from",
|
||||
connections: []models.Connection{{}},
|
||||
errMessage: "no connection to pick from",
|
||||
},
|
||||
"OpenVPN server with hostname": {
|
||||
filteredServers: []models.Server{
|
||||
@@ -61,13 +63,13 @@ func Test_GetConnection(t *testing.T) {
|
||||
WithDefaults(providers.Mullvad),
|
||||
defaults: NewConnectionDefaults(443, 1194, 58820),
|
||||
randSource: rand.NewSource(0),
|
||||
connection: models.Connection{
|
||||
connections: []models.Connection{{
|
||||
Type: vpn.OpenVPN,
|
||||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
|
||||
Protocol: constants.UDP,
|
||||
Port: 1194,
|
||||
Hostname: "name",
|
||||
},
|
||||
}},
|
||||
},
|
||||
"OpenVPN server with x509": {
|
||||
filteredServers: []models.Server{
|
||||
@@ -83,13 +85,13 @@ func Test_GetConnection(t *testing.T) {
|
||||
WithDefaults(providers.Mullvad),
|
||||
defaults: NewConnectionDefaults(443, 1194, 58820),
|
||||
randSource: rand.NewSource(0),
|
||||
connection: models.Connection{
|
||||
connections: []models.Connection{{
|
||||
Type: vpn.OpenVPN,
|
||||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
|
||||
Protocol: constants.UDP,
|
||||
Port: 1194,
|
||||
Hostname: "x509",
|
||||
},
|
||||
}},
|
||||
},
|
||||
"server with IPv4 and IPv6": {
|
||||
filteredServers: []models.Server{
|
||||
@@ -111,12 +113,12 @@ func Test_GetConnection(t *testing.T) {
|
||||
WithDefaults(providers.Mullvad),
|
||||
defaults: NewConnectionDefaults(443, 1194, 58820),
|
||||
randSource: rand.NewSource(0),
|
||||
connection: models.Connection{
|
||||
connections: []models.Connection{{
|
||||
Type: vpn.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{
|
||||
@@ -134,12 +136,12 @@ func Test_GetConnection(t *testing.T) {
|
||||
defaults: NewConnectionDefaults(443, 1194, 58820),
|
||||
ipv6Supported: true,
|
||||
randSource: rand.NewSource(0),
|
||||
connection: models.Connection{
|
||||
connections: []models.Connection{{
|
||||
Type: vpn.OpenVPN,
|
||||
IP: netip.IPv6Unspecified(),
|
||||
Protocol: constants.UDP,
|
||||
Port: 1194,
|
||||
},
|
||||
}},
|
||||
},
|
||||
"mixed servers": {
|
||||
filteredServers: []models.Server{
|
||||
@@ -149,12 +151,6 @@ func Test_GetConnection(t *testing.T) {
|
||||
IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})},
|
||||
OvpnX509: "ovpnx509",
|
||||
},
|
||||
{
|
||||
VPN: vpn.Wireguard,
|
||||
UDP: true,
|
||||
IPs: []netip.Addr{netip.AddrFrom4([4]byte{2, 2, 2, 2})},
|
||||
OvpnX509: "ovpnx509",
|
||||
},
|
||||
{
|
||||
VPN: vpn.OpenVPN,
|
||||
UDP: true,
|
||||
@@ -169,13 +165,19 @@ func Test_GetConnection(t *testing.T) {
|
||||
WithDefaults(providers.Mullvad),
|
||||
defaults: NewConnectionDefaults(443, 1194, 58820),
|
||||
randSource: rand.NewSource(0),
|
||||
connection: models.Connection{
|
||||
connections: []models.Connection{{
|
||||
Type: vpn.OpenVPN,
|
||||
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
|
||||
Protocol: constants.UDP,
|
||||
Port: 1194,
|
||||
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,
|
||||
connPicker)
|
||||
|
||||
assert.Equal(t, testCase.connection, connection)
|
||||
assert.Contains(t, testCase.connections, connection)
|
||||
if testCase.errMessage != "" {
|
||||
assert.EqualError(t, err, testCase.errMessage)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user