Maint: common no port forwarding implementation

This commit is contained in:
Quentin McGaw (desktop)
2021-07-26 16:29:40 +00:00
parent d7a6caa2ac
commit 49885c63c4
33 changed files with 128 additions and 288 deletions

View File

@@ -1,16 +0,0 @@
package cyberghost
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (c *Cyberghost) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Cyberghost")
}

View File

@@ -3,17 +3,21 @@ package cyberghost
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Cyberghost struct { type Cyberghost struct {
servers []models.CyberghostServer servers []models.CyberghostServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.CyberghostServer, randSource rand.Source) *Cyberghost { func New(servers []models.CyberghostServer, randSource rand.Source) *Cyberghost {
return &Cyberghost{ return &Cyberghost{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Cyberghost),
} }
} }

View File

@@ -1,16 +0,0 @@
package fastestvpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (f *Fastestvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for FastestVPN")
}

View File

@@ -3,17 +3,21 @@ package fastestvpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Fastestvpn struct { type Fastestvpn struct {
servers []models.FastestvpnServer servers []models.FastestvpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.FastestvpnServer, randSource rand.Source) *Fastestvpn { func New(servers []models.FastestvpnServer, randSource rand.Source) *Fastestvpn {
return &Fastestvpn{ return &Fastestvpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Fastestvpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package hidemyass
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (f *HideMyAss) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for HideMyAss")
}

View File

@@ -3,17 +3,21 @@ package hidemyass
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type HideMyAss struct { type HideMyAss struct {
servers []models.HideMyAssServer servers []models.HideMyAssServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.HideMyAssServer, randSource rand.Source) *HideMyAss { func New(servers []models.HideMyAssServer, randSource rand.Source) *HideMyAss {
return &HideMyAss{ return &HideMyAss{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.HideMyAss),
} }
} }

View File

@@ -1,16 +0,0 @@
package ipvanish
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (i *Ipvanish) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Ipvanish")
}

View File

@@ -3,17 +3,21 @@ package ipvanish
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Ipvanish struct { type Ipvanish struct {
servers []models.IpvanishServer servers []models.IpvanishServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.IpvanishServer, randSource rand.Source) *Ipvanish { func New(servers []models.IpvanishServer, randSource rand.Source) *Ipvanish {
return &Ipvanish{ return &Ipvanish{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Ipvanish),
} }
} }

View File

@@ -1,16 +0,0 @@
package ivpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (i *Ivpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Ivpn")
}

View File

@@ -3,17 +3,21 @@ package ivpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Ivpn struct { type Ivpn struct {
servers []models.IvpnServer servers []models.IvpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.IvpnServer, randSource rand.Source) *Ivpn { func New(servers []models.IvpnServer, randSource rand.Source) *Ivpn {
return &Ivpn{ return &Ivpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Ivpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package mullvad
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (m *Mullvad) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding logic is not needed for Mullvad")
}

View File

@@ -3,17 +3,21 @@ package mullvad
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Mullvad struct { type Mullvad struct {
servers []models.MullvadServer servers []models.MullvadServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.MullvadServer, randSource rand.Source) *Mullvad { func New(servers []models.MullvadServer, randSource rand.Source) *Mullvad {
return &Mullvad{ return &Mullvad{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Mullvad),
} }
} }

View File

@@ -1,16 +0,0 @@
package nordvpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (n *Nordvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for NordVPN")
}

View File

@@ -3,17 +3,21 @@ package nordvpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Nordvpn struct { type Nordvpn struct {
servers []models.NordvpnServer servers []models.NordvpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.NordvpnServer, randSource rand.Source) *Nordvpn { func New(servers []models.NordvpnServer, randSource rand.Source) *Nordvpn {
return &Nordvpn{ return &Nordvpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Nordvpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package privado
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (p *Privado) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Privado")
}

View File

@@ -3,17 +3,21 @@ package privado
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Privado struct { type Privado struct {
servers []models.PrivadoServer servers []models.PrivadoServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.PrivadoServer, randSource rand.Source) *Privado { func New(servers []models.PrivadoServer, randSource rand.Source) *Privado {
return &Privado{ return &Privado{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Privado),
} }
} }

View File

@@ -1,16 +0,0 @@
package privatevpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (p *Privatevpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for PrivateVPN")
}

View File

@@ -3,17 +3,21 @@ package privatevpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Privatevpn struct { type Privatevpn struct {
servers []models.PrivatevpnServer servers []models.PrivatevpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.PrivatevpnServer, randSource rand.Source) *Privatevpn { func New(servers []models.PrivatevpnServer, randSource rand.Source) *Privatevpn {
return &Privatevpn{ return &Privatevpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Privatevpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package protonvpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (p *Protonvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for ProtonVPN")
}

View File

@@ -3,17 +3,21 @@ package protonvpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Protonvpn struct { type Protonvpn struct {
servers []models.ProtonvpnServer servers []models.ProtonvpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.ProtonvpnServer, randSource rand.Source) *Protonvpn { func New(servers []models.ProtonvpnServer, randSource rand.Source) *Protonvpn {
return &Protonvpn{ return &Protonvpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Protonvpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package purevpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (p *Purevpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for PureVPN")
}

View File

@@ -3,17 +3,21 @@ package purevpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Purevpn struct { type Purevpn struct {
servers []models.PurevpnServer servers []models.PurevpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.PurevpnServer, randSource rand.Source) *Purevpn { func New(servers []models.PurevpnServer, randSource rand.Source) *Purevpn {
return &Purevpn{ return &Purevpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Purevpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package surfshark
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (s *Surfshark) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Surfshark")
}

View File

@@ -3,17 +3,21 @@ package surfshark
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Surfshark struct { type Surfshark struct {
servers []models.SurfsharkServer servers []models.SurfsharkServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.SurfsharkServer, randSource rand.Source) *Surfshark { func New(servers []models.SurfsharkServer, randSource rand.Source) *Surfshark {
return &Surfshark{ return &Surfshark{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Surfshark),
} }
} }

View File

@@ -1,16 +0,0 @@
package torguard
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (t *Torguard) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Torguard")
}

View File

@@ -3,17 +3,21 @@ package torguard
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Torguard struct { type Torguard struct {
servers []models.TorguardServer servers []models.TorguardServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.TorguardServer, randSource rand.Source) *Torguard { func New(servers []models.TorguardServer, randSource rand.Source) *Torguard {
return &Torguard{ return &Torguard{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Torguard),
} }
} }

View File

@@ -0,0 +1,32 @@
package utils
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
type NoPortForwarder interface {
PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string))
}
type NoPortForwarding struct {
providerName string
}
func NewNoPortForwarding(providerName string) *NoPortForwarding {
return &NoPortForwarding{
providerName: providerName,
}
}
func (n *NoPortForwarding) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("custom port forwarding obtention is not supported for " + n.providerName)
}

View File

@@ -1,16 +0,0 @@
package vpnunlimited
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (p *Provider) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for VPN Unlimited")
}

View File

@@ -3,17 +3,21 @@ package vpnunlimited
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Provider struct { type Provider struct {
servers []models.VPNUnlimitedServer servers []models.VPNUnlimitedServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.VPNUnlimitedServer, randSource rand.Source) *Provider { func New(servers []models.VPNUnlimitedServer, randSource rand.Source) *Provider {
return &Provider{ return &Provider{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.VPNUnlimited),
} }
} }

View File

@@ -1,16 +0,0 @@
package vyprvpn
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (v *Vyprvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Vyprvpn")
}

View File

@@ -3,17 +3,21 @@ package vyprvpn
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Vyprvpn struct { type Vyprvpn struct {
servers []models.VyprvpnServer servers []models.VyprvpnServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.VyprvpnServer, randSource rand.Source) *Vyprvpn { func New(servers []models.VyprvpnServer, randSource rand.Source) *Vyprvpn {
return &Vyprvpn{ return &Vyprvpn{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Vyprvpn),
} }
} }

View File

@@ -1,16 +0,0 @@
package windscribe
import (
"context"
"net"
"net/http"
"github.com/qdm12/gluetun/internal/firewall"
"github.com/qdm12/golibs/logging"
)
func (w *Windscribe) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Windscribe")
}

View File

@@ -3,17 +3,21 @@ package windscribe
import ( import (
"math/rand" "math/rand"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/provider/utils"
) )
type Windscribe struct { type Windscribe struct {
servers []models.WindscribeServer servers []models.WindscribeServer
randSource rand.Source randSource rand.Source
utils.NoPortForwarder
} }
func New(servers []models.WindscribeServer, randSource rand.Source) *Windscribe { func New(servers []models.WindscribeServer, randSource rand.Source) *Windscribe {
return &Windscribe{ return &Windscribe{
servers: servers, servers: servers,
randSource: randSource, randSource: randSource,
NoPortForwarder: utils.NewNoPortForwarding(constants.Windscribe),
} }
} }