chore(provider): add safety connection count check

This commit is contained in:
Quentin McGaw
2022-04-17 16:23:53 +00:00
parent 7ad6fc8e73
commit 0dd723b29f

View File

@@ -11,6 +11,8 @@ import (
"github.com/qdm12/gluetun/internal/models"
)
var ErrNoConnectionToPickFrom = errors.New("no connection to pick from")
// 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.
@@ -19,6 +21,10 @@ import (
func PickConnection(connections []models.Connection,
selection settings.ServerSelection, randSource rand.Source) (
connection models.Connection, err error) {
if len(connections) == 0 {
return connection, ErrNoConnectionToPickFrom
}
if len(selection.TargetIP) > 0 && selection.VPN == constants.Wireguard {
// we need the right public key
return getTargetIPConnection(connections, selection.TargetIP)