chore: simplify provider GetConnection
This commit is contained in:
@@ -6,40 +6,8 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (w *Windscribe) GetConnection(selection settings.ServerSelection) (
|
||||
func (p *Windscribe) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
|
||||
servers, err := utils.FilterServers(w.servers, selection)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Hostname: server.OvpnX509,
|
||||
PubKey: server.WgPubKey,
|
||||
}
|
||||
connections = append(connections, connection)
|
||||
}
|
||||
}
|
||||
|
||||
return utils.PickConnection(connections, selection, w.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection settings.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 443
|
||||
defaultOpenVPNUDP = 1194
|
||||
defaultWireguard = 1194
|
||||
)
|
||||
return utils.GetPort(selection, defaultOpenVPNTCP,
|
||||
defaultOpenVPNUDP, defaultWireguard)
|
||||
defaults := utils.NewConnectionDefaults(443, 1194, 1194) //nolint:gomnd
|
||||
return utils.GetConnection(p.servers, selection, defaults, p.randSource)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user