Skip to content

Commit

Permalink
Use normal env variable reading as I couldn't figure reader out
Browse files Browse the repository at this point in the history
  • Loading branch information
Félix Pratt committed Oct 31, 2024
1 parent 727996d commit aabce5c
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions internal/provider/utils/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package utils
import (
"fmt"
"math/rand"
"os"
"strings"

"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/constants/vpn"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gosettings/reader"
)

type ConnectionDefaults struct {
Expand All @@ -31,30 +32,17 @@ type Storage interface {
servers []models.Server, err error)
}

type VPNSettings struct {
IPv6Server *bool
}

// Read method to populate the VPNSettings from the reader
func (v *VPNSettings) read(reader *reader.Reader) (err error) {
v.IPv6Server, err = reader.BoolPtr("VPN_IPV6_SERVER")
return err
}

func GetConnection(provider string,
storage Storage,
selection settings.ServerSelection,
defaults ConnectionDefaults,
ipv6Supported bool,
randSource rand.Source,
reader *reader.Reader) (
randSource rand.Source) (
connection models.Connection, err error,
) {
// Create an instance of VPNSettings and read settings
var vpnSettings VPNSettings
if err := vpnSettings.read(reader); err != nil {
return connection, fmt.Errorf("reading VPN settings: %w", err)
}
// Read the VPN_IPV6_SERVER environment variable
vpnIPv6Server := os.Getenv("VPN_IPV6_SERVER")
skipIPv6Servers := strings.EqualFold(vpnIPv6Server, "off")

servers, err := storage.FilterServers(provider, selection)
if err != nil {
Expand All @@ -68,8 +56,11 @@ func GetConnection(provider string,
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, ip := range server.IPs {
// Skip IPv6 if unsupported or if VPN_IPV6_SERVER is false
if !ipv6Supported || (vpnSettings.IPv6Server != nil && !*vpnSettings.IPv6Server && ip.Is6()) {
if skipIPv6Servers && ip.Is6() {
continue
}

if !ipv6Supported && ip.Is6() {
continue
}

Expand Down

0 comments on commit aabce5c

Please sign in to comment.