44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package wevpn
|
|
|
|
import (
|
|
"github.com/qdm12/gluetun/internal/configuration"
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
|
)
|
|
|
|
func (w *Wevpn) GetConnection(selection configuration.ServerSelection) (
|
|
connection models.Connection, err error) {
|
|
port := getPort(selection)
|
|
protocol := utils.GetProtocol(selection)
|
|
|
|
servers, err := w.filterServers(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,
|
|
}
|
|
connections = append(connections, connection)
|
|
}
|
|
}
|
|
|
|
return utils.PickConnection(connections, selection, w.randSource)
|
|
}
|
|
|
|
func getPort(selection configuration.ServerSelection) (port uint16) {
|
|
const (
|
|
defaultOpenVPNTCP = 1195
|
|
defaultOpenVPNUDP = 1194
|
|
defaultWireguard = 0 // Wireguard not supported
|
|
)
|
|
return utils.GetPort(selection, defaultOpenVPNTCP,
|
|
defaultOpenVPNUDP, defaultWireguard)
|
|
}
|