Skip to content

Commit

Permalink
feat(config): only use port forwarding servers when port forwarding i…
Browse files Browse the repository at this point in the history
…s enabled for ProtonVPN and PIA
  • Loading branch information
qdm12 committed Jul 31, 2024
1 parent 72e227f commit 5d75bbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/configuration/settings/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (p *Provider) overrideWith(other Provider) {

func (p *Provider) setDefaults() {
p.Name = gosettings.DefaultComparable(p.Name, providers.PrivateInternetAccess)
p.ServerSelection.setDefaults(p.Name)
p.PortForwarding.setDefaults()
p.ServerSelection.setDefaults(p.Name, *p.PortForwarding.Enabled)
}

func (p Provider) String() string {
Expand Down
12 changes: 9 additions & 3 deletions internal/configuration/settings/serverselection.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (ss *ServerSelection) overrideWith(other ServerSelection) {
ss.Wireguard.overrideWith(other.Wireguard)
}

func (ss *ServerSelection) setDefaults(vpnProvider string) {
func (ss *ServerSelection) setDefaults(vpnProvider string, portForwardingEnabled bool) {
ss.VPN = gosettings.DefaultComparable(ss.VPN, vpn.OpenVPN)
ss.TargetIP = gosettings.DefaultValidator(ss.TargetIP, netip.IPv4Unspecified())
ss.OwnedOnly = gosettings.DefaultPointer(ss.OwnedOnly, false)
Expand All @@ -304,7 +304,12 @@ func (ss *ServerSelection) setDefaults(vpnProvider string) {
ss.SecureCoreOnly = gosettings.DefaultPointer(ss.SecureCoreOnly, false)
ss.TorOnly = gosettings.DefaultPointer(ss.TorOnly, false)
ss.MultiHopOnly = gosettings.DefaultPointer(ss.MultiHopOnly, false)
ss.PortForwardOnly = gosettings.DefaultPointer(ss.PortForwardOnly, false)
defaultPortForwardOnly := false
if portForwardingEnabled && helpers.IsOneOf(vpnProvider,
providers.PrivateInternetAccess, providers.Protonvpn) {
defaultPortForwardOnly = true
}
ss.PortForwardOnly = gosettings.DefaultPointer(ss.PortForwardOnly, defaultPortForwardOnly)
ss.OpenVPN.setDefaults(vpnProvider)
ss.Wireguard.setDefaults()
}
Expand Down Expand Up @@ -399,7 +404,8 @@ func (ss ServerSelection) toLinesNode() (node *gotree.Node) {
// WithDefaults is a shorthand using setDefaults.
// It's used in unit tests in other packages.
func (ss ServerSelection) WithDefaults(provider string) ServerSelection {
ss.setDefaults(provider)
const portForwardingEnabled = false
ss.setDefaults(provider, portForwardingEnabled)
return ss
}

Expand Down

0 comments on commit 5d75bbc

Please sign in to comment.