chore: use gofumpt for code formatting
This commit is contained in:
@@ -7,7 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func (p *Provider) GetConnection(selection settings.ServerSelection, ipv6Supported bool) (
|
||||
connection models.Connection, err error) {
|
||||
connection models.Connection, err error,
|
||||
) {
|
||||
defaults := utils.NewConnectionDefaults(443, 1194, 51820) //nolint:mnd
|
||||
return utils.GetConnection(p.Name(),
|
||||
p.storage, selection, defaults, ipv6Supported, p.randSource)
|
||||
|
||||
@@ -8,7 +8,8 @@ import (
|
||||
)
|
||||
|
||||
func (p *Provider) OpenVPNConfig(connection models.Connection,
|
||||
settings settings.OpenVPN, ipv6Supported bool) (lines []string) {
|
||||
settings settings.OpenVPN, ipv6Supported bool,
|
||||
) (lines []string) {
|
||||
//nolint:mnd
|
||||
providerSettings := utils.OpenVPNProviderSettings{
|
||||
RemoteCertTLS: true,
|
||||
|
||||
@@ -11,13 +11,12 @@ import (
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrServerPortForwardNotSupported = errors.New("server does not support port forwarding")
|
||||
)
|
||||
var ErrServerPortForwardNotSupported = errors.New("server does not support port forwarding")
|
||||
|
||||
// PortForward obtains a VPN server side port forwarded from ProtonVPN gateway.
|
||||
func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) (
|
||||
ports []uint16, err error) {
|
||||
ports []uint16, err error,
|
||||
) {
|
||||
if !objects.CanPortForward {
|
||||
return nil, fmt.Errorf("%w", ErrServerPortForwardNotSupported)
|
||||
}
|
||||
@@ -38,17 +37,15 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
|
||||
const internalPort, externalPort = 0, 1
|
||||
const lifetime = 60 * time.Second
|
||||
|
||||
_, _, assignedUDPExternalPort, assignedLifetime, err :=
|
||||
client.AddPortMapping(ctx, objects.Gateway, "udp",
|
||||
internalPort, externalPort, lifetime)
|
||||
_, _, assignedUDPExternalPort, assignedLifetime, err := client.AddPortMapping(ctx, objects.Gateway, "udp",
|
||||
internalPort, externalPort, lifetime)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("adding UDP port mapping: %w", err)
|
||||
}
|
||||
checkLifetime(logger, "UDP", lifetime, assignedLifetime)
|
||||
|
||||
_, _, assignedTCPExternalPort, assignedLifetime, err :=
|
||||
client.AddPortMapping(ctx, objects.Gateway, "tcp",
|
||||
internalPort, externalPort, lifetime)
|
||||
_, _, assignedTCPExternalPort, assignedLifetime, err := client.AddPortMapping(ctx, objects.Gateway, "tcp",
|
||||
internalPort, externalPort, lifetime)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("adding TCP port mapping: %w", err)
|
||||
}
|
||||
@@ -62,7 +59,8 @@ func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObj
|
||||
}
|
||||
|
||||
func checkLifetime(logger utils.Logger, protocol string,
|
||||
requested, actual time.Duration) {
|
||||
requested, actual time.Duration,
|
||||
) {
|
||||
if requested != actual {
|
||||
logger.Warn(fmt.Sprintf("assigned %s port lifetime %s differs"+
|
||||
" from requested lifetime %s", strings.ToUpper(protocol),
|
||||
@@ -80,7 +78,8 @@ func checkExternalPorts(logger utils.Logger, udpPort, tcpPort uint16) {
|
||||
var ErrExternalPortChanged = errors.New("external port changed")
|
||||
|
||||
func (p *Provider) KeepPortForward(ctx context.Context,
|
||||
objects utils.PortForwardObjects) (err error) {
|
||||
objects utils.PortForwardObjects,
|
||||
) (err error) {
|
||||
client := natpmp.New()
|
||||
const refreshTimeout = 45 * time.Second
|
||||
timer := time.NewTimer(refreshTimeout)
|
||||
@@ -98,9 +97,8 @@ func (p *Provider) KeepPortForward(ctx context.Context,
|
||||
const lifetime = 60 * time.Second
|
||||
|
||||
for _, networkProtocol := range networkProtocols {
|
||||
_, _, assignedExternalPort, assignedLiftetime, err :=
|
||||
client.AddPortMapping(ctx, objects.Gateway, networkProtocol,
|
||||
internalPort, p.portForwarded, lifetime)
|
||||
_, _, assignedExternalPort, assignedLiftetime, err := client.AddPortMapping(ctx, objects.Gateway, networkProtocol,
|
||||
internalPort, p.portForwarded, lifetime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("adding port mapping: %w", err)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ type Provider struct {
|
||||
}
|
||||
|
||||
func New(storage common.Storage, randSource rand.Source,
|
||||
client *http.Client, updaterWarner common.Warner) *Provider {
|
||||
client *http.Client, updaterWarner common.Warner,
|
||||
) *Provider {
|
||||
return &Provider{
|
||||
storage: storage,
|
||||
randSource: randSource,
|
||||
|
||||
@@ -9,9 +9,7 @@ import (
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK")
|
||||
)
|
||||
var ErrHTTPStatusCodeNotOK = errors.New("HTTP status code not OK")
|
||||
|
||||
type apiData struct {
|
||||
LogicalServers []logicalServer `json:"LogicalServers"`
|
||||
@@ -36,7 +34,8 @@ type physicalServer struct {
|
||||
}
|
||||
|
||||
func fetchAPI(ctx context.Context, client *http.Client) (
|
||||
data apiData, err error) {
|
||||
data apiData, err error,
|
||||
) {
|
||||
const url = "https://api.protonmail.ch/vpn/logicals"
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
|
||||
@@ -3,7 +3,8 @@ package updater
|
||||
import "strings"
|
||||
|
||||
func codeToCountry(countryCode string, countryCodes map[string]string) (
|
||||
country string, warning string) {
|
||||
country string, warning string,
|
||||
) {
|
||||
countryCode = strings.ToLower(countryCode)
|
||||
country, ok := countryCodes[countryCode]
|
||||
if !ok {
|
||||
|
||||
@@ -17,7 +17,8 @@ type features struct {
|
||||
}
|
||||
|
||||
func (its ipToServers) add(country, region, city, name, hostname, wgPubKey string,
|
||||
free bool, entryIP netip.Addr, features features) {
|
||||
free bool, entryIP netip.Addr, features features,
|
||||
) {
|
||||
key := entryIP.String()
|
||||
|
||||
servers, ok := its[key]
|
||||
|
||||
@@ -11,7 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
servers []models.Server, err error) {
|
||||
servers []models.Server, err error,
|
||||
) {
|
||||
data, err := fetchAPI(ctx, u.client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user