chore: simplify provider GetConnection
This commit is contained in:
@@ -2,34 +2,12 @@ package privado
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Privado) GetConnection(selection settings.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
const port = 1194
|
||||
const protocol = constants.UDP
|
||||
|
||||
servers, err := utils.FilterServers(p.servers, selection)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
connections := make([]models.Connection, 0, len(servers))
|
||||
for _, server := range servers {
|
||||
for _, ip := range server.IPs {
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: ip,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Hostname: server.Hostname,
|
||||
}
|
||||
connections = append(connections, connection)
|
||||
}
|
||||
}
|
||||
|
||||
return utils.PickConnection(connections, selection, p.randSource)
|
||||
defaults := utils.NewConnectionDefaults(0, 1194, 0) //nolint:gomnd
|
||||
return utils.GetConnection(p.servers, selection, defaults, p.randSource)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user