diff --git a/internal/provider/utils/connection.go b/internal/provider/utils/connection.go index 140e4e19..1e3853a5 100644 --- a/internal/provider/utils/connection.go +++ b/internal/provider/utils/connection.go @@ -35,13 +35,13 @@ func GetConnection(servers []models.Server, return connection, ErrNoServer } - servers = FilterServers(servers, selection) + servers = filterServers(servers, selection) if len(servers) == 0 { - return connection, NoServerFoundError(selection) + return connection, noServerFoundError(selection) } protocol := getProtocol(selection) - port := GetPort(selection, defaults.OpenVPNTCPPort, + port := getPort(selection, defaults.OpenVPNTCPPort, defaults.OpenVPNUDPPort, defaults.WireguardPort) connections := make([]models.Connection, 0, len(servers)) @@ -71,5 +71,5 @@ func GetConnection(servers []models.Server, } } - return PickConnection(connections, selection, randSource) + return pickConnection(connections, selection, randSource) } diff --git a/internal/provider/utils/filtering.go b/internal/provider/utils/filtering.go index b6648d16..2124b729 100644 --- a/internal/provider/utils/filtering.go +++ b/internal/provider/utils/filtering.go @@ -7,7 +7,7 @@ import ( "github.com/qdm12/gluetun/internal/models" ) -func FilterServers(servers []models.Server, +func filterServers(servers []models.Server, selection settings.ServerSelection) (filtered []models.Server) { for _, server := range servers { if filterServer(server, selection) { diff --git a/internal/provider/utils/filtering_test.go b/internal/provider/utils/filtering_test.go index 5fd6c4de..63b27208 100644 --- a/internal/provider/utils/filtering_test.go +++ b/internal/provider/utils/filtering_test.go @@ -212,7 +212,7 @@ func Test_FilterServers(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - filtered := FilterServers(testCase.servers, testCase.selection) + filtered := filterServers(testCase.servers, testCase.selection) assert.Equal(t, testCase.filtered, filtered) }) diff --git a/internal/provider/utils/formatting.go b/internal/provider/utils/formatting.go index b9890e68..918f6131 100644 --- a/internal/provider/utils/formatting.go +++ b/internal/provider/utils/formatting.go @@ -16,7 +16,7 @@ func commaJoin(slice []string) string { var ErrNoServerFound = errors.New("no server found") -func NoServerFoundError(selection settings.ServerSelection) (err error) { +func noServerFoundError(selection settings.ServerSelection) (err error) { var messageParts []string messageParts = append(messageParts, "VPN "+selection.VPN) diff --git a/internal/provider/utils/pick.go b/internal/provider/utils/pick.go index d594a8a0..94dae872 100644 --- a/internal/provider/utils/pick.go +++ b/internal/provider/utils/pick.go @@ -13,12 +13,12 @@ import ( var ErrNoConnectionToPickFrom = errors.New("no connection to pick from") -// PickConnection picks a connection from a pool of connections. +// pickConnection picks a connection from a pool of connections. // If the VPN protocol is Wireguard and the target IP is set, // it finds the connection corresponding to this target IP. // Otherwise, it picks a random connection from the pool of connections // and sets the target IP address as the IP if this one is set. -func PickConnection(connections []models.Connection, +func pickConnection(connections []models.Connection, selection settings.ServerSelection, randSource rand.Source) ( connection models.Connection, err error) { if len(connections) == 0 { diff --git a/internal/provider/utils/port.go b/internal/provider/utils/port.go index 8cfff4e4..6aea9fb6 100644 --- a/internal/provider/utils/port.go +++ b/internal/provider/utils/port.go @@ -1,15 +1,13 @@ package utils import ( - "errors" "fmt" "github.com/qdm12/gluetun/internal/configuration/settings" - "github.com/qdm12/gluetun/internal/constants" "github.com/qdm12/gluetun/internal/constants/vpn" ) -func GetPort(selection settings.ServerSelection, +func getPort(selection settings.ServerSelection, defaultOpenVPNTCP, defaultOpenVPNUDP, defaultWireguard uint16) (port uint16) { switch selection.VPN { case vpn.Wireguard: @@ -41,24 +39,3 @@ func checkDefined(portName string, port uint16) { message := fmt.Sprintf("no default %s port is defined!", portName) panic(message) } - -var ErrInvalidPort = errors.New("invalid port number") - -// CheckPortAllowed for custom port used for OpenVPN. -func CheckPortAllowed(port uint16, tcp bool, - allowedTCP, allowedUDP []uint16) (err error) { - allowedPorts := allowedUDP - protocol := constants.UDP - if tcp { - allowedPorts = allowedTCP - protocol = constants.TCP - } - for _, allowedPort := range allowedPorts { - if port == allowedPort { - return nil - } - } - - return fmt.Errorf("%w: %d for protocol %s", - ErrInvalidPort, port, protocol) -} diff --git a/internal/provider/utils/port_test.go b/internal/provider/utils/port_test.go index 6b608757..cf047d0a 100644 --- a/internal/provider/utils/port_test.go +++ b/internal/provider/utils/port_test.go @@ -120,7 +120,7 @@ func Test_GetPort(t *testing.T) { if testCase.panics != "" { assert.PanicsWithValue(t, testCase.panics, func() { - _ = GetPort(testCase.selection, + _ = getPort(testCase.selection, testCase.defaultOpenVPNTCP, testCase.defaultOpenVPNUDP, testCase.defaultWireguard) @@ -128,7 +128,7 @@ func Test_GetPort(t *testing.T) { return } - port := GetPort(testCase.selection, + port := getPort(testCase.selection, testCase.defaultOpenVPNTCP, testCase.defaultOpenVPNUDP, testCase.defaultWireguard)