chore(surfshark): add package internal/provider/surshark/server
- Merge `internal/models/location.go` and `internal/constants/surfshark.go` into `internal/provider/surfshark/servers/locationdata.go`
This commit is contained in:
@@ -3,15 +3,14 @@ package settings
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func surfsharkRetroRegion(selection ServerSelection) (
|
func surfsharkRetroRegion(selection ServerSelection) (
|
||||||
updatedSelection ServerSelection) {
|
updatedSelection ServerSelection) {
|
||||||
locationData := constants.SurfsharkLocationData()
|
locationData := servers.LocationData()
|
||||||
|
|
||||||
retroToLocation := make(map[string]models.SurfsharkLocationData, len(locationData))
|
retroToLocation := make(map[string]servers.ServerLocation, len(locationData))
|
||||||
for _, data := range locationData {
|
for _, data := range locationData {
|
||||||
if data.RetroLoc == "" {
|
if data.RetroLoc == "" {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO remove in v4.
|
// TODO remove in v4.
|
||||||
func SurfsharkRetroLocChoices() (choices []string) {
|
func SurfsharkRetroLocChoices() (choices []string) {
|
||||||
locationData := constants.SurfsharkLocationData()
|
locationData := servers.LocationData()
|
||||||
choices = make([]string, 0, len(locationData))
|
choices = make([]string, 0, len(locationData))
|
||||||
seen := make(map[string]struct{}, len(locationData))
|
seen := make(map[string]struct{}, len(locationData))
|
||||||
for _, data := range locationData {
|
for _, data := range locationData {
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
// SurfsharkLocationData is required to keep location data on Surfshark
|
|
||||||
// servers that are not obtained through their API.
|
|
||||||
type SurfsharkLocationData struct {
|
|
||||||
Region string
|
|
||||||
Country string
|
|
||||||
City string
|
|
||||||
RetroLoc string // TODO remove in v4
|
|
||||||
Hostname string
|
|
||||||
MultiHop bool
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,20 @@
|
|||||||
package constants
|
package servers
|
||||||
|
|
||||||
import (
|
// LocationData is required to keep location data on Surfshark
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
// servers that are not obtained through their API.
|
||||||
)
|
type ServerLocation struct {
|
||||||
|
Region string
|
||||||
|
Country string
|
||||||
|
City string
|
||||||
|
RetroLoc string // TODO remove in v4
|
||||||
|
Hostname string
|
||||||
|
MultiHop bool
|
||||||
|
}
|
||||||
|
|
||||||
// TODO remove retroRegion and servers from API in v4.
|
// TODO remove retroRegion and servers from API in v4.
|
||||||
func SurfsharkLocationData() (data []models.SurfsharkLocationData) {
|
func LocationData() (data []ServerLocation) {
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
return []models.SurfsharkLocationData{
|
return []ServerLocation{
|
||||||
{Region: "Asia Pacific", Country: "Australia", City: "Adelaide", RetroLoc: "Australia Adelaide", Hostname: "au-adl.prod.surfshark.com", MultiHop: false},
|
{Region: "Asia Pacific", Country: "Australia", City: "Adelaide", RetroLoc: "Australia Adelaide", Hostname: "au-adl.prod.surfshark.com", MultiHop: false},
|
||||||
{Region: "Asia Pacific", Country: "Australia", City: "Brisbane", RetroLoc: "Australia Brisbane", Hostname: "au-bne.prod.surfshark.com", MultiHop: false},
|
{Region: "Asia Pacific", Country: "Australia", City: "Brisbane", RetroLoc: "Australia Brisbane", Hostname: "au-bne.prod.surfshark.com", MultiHop: false},
|
||||||
{Region: "Asia Pacific", Country: "Australia", City: "Melbourne", RetroLoc: "Australia Melbourne", Hostname: "au-mel.prod.surfshark.com", MultiHop: false},
|
{Region: "Asia Pacific", Country: "Australia", City: "Melbourne", RetroLoc: "Australia Melbourne", Hostname: "au-mel.prod.surfshark.com", MultiHop: false},
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Note: no multi-hop and some servers are missing from their API.
|
// Note: no multi-hop and some servers are missing from their API.
|
||||||
@@ -18,7 +18,7 @@ func addServersFromAPI(ctx context.Context, client *http.Client,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
locationData := constants.SurfsharkLocationData()
|
locationData := servers.LocationData()
|
||||||
hostToLocation := hostToLocation(locationData)
|
hostToLocation := hostToLocation(locationData)
|
||||||
|
|
||||||
const tcp, udp = true, true
|
const tcp, udp = true, true
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errHostnameNotFound = errors.New("hostname not found in hostname to location mapping")
|
errHostnameNotFound = errors.New("hostname not found in hostname to location mapping")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getHostInformation(host string, hostnameToLocation map[string]models.SurfsharkLocationData) (
|
func getHostInformation(host string, hostnameToLocation map[string]servers.ServerLocation) (
|
||||||
data models.SurfsharkLocationData, err error) {
|
data servers.ServerLocation, err error) {
|
||||||
locationData, ok := hostnameToLocation[host]
|
locationData, ok := hostnameToLocation[host]
|
||||||
if !ok {
|
if !ok {
|
||||||
return locationData, fmt.Errorf("%w: %s", errHostnameNotFound, host)
|
return locationData, fmt.Errorf("%w: %s", errHostnameNotFound, host)
|
||||||
@@ -21,9 +21,9 @@ func getHostInformation(host string, hostnameToLocation map[string]models.Surfsh
|
|||||||
return locationData, nil
|
return locationData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func hostToLocation(locationData []models.SurfsharkLocationData) (
|
func hostToLocation(locationData []servers.ServerLocation) (
|
||||||
hostToLocation map[string]models.SurfsharkLocationData) {
|
hostToLocation map[string]servers.ServerLocation) {
|
||||||
hostToLocation = make(map[string]models.SurfsharkLocationData, len(locationData))
|
hostToLocation = make(map[string]servers.ServerLocation, len(locationData))
|
||||||
for _, data := range locationData {
|
for _, data := range locationData {
|
||||||
hostToLocation[data.Hostname] = data
|
hostToLocation[data.Hostname] = data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package surfshark
|
package surfshark
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getRemainingServers finds extra servers not found in the API or in the ZIP file.
|
// getRemainingServers finds extra servers not found in the API or in the ZIP file.
|
||||||
func getRemainingServers(hts hostToServer) {
|
func getRemainingServers(hts hostToServer) {
|
||||||
locationData := constants.SurfsharkLocationData()
|
locationData := servers.LocationData()
|
||||||
hostnameToLocationLeft := hostToLocation(locationData)
|
hostnameToLocationLeft := hostToLocation(locationData)
|
||||||
for _, hostnameDone := range hts.toHostsSlice() {
|
for _, hostnameDone := range hts.toHostsSlice() {
|
||||||
delete(hostnameToLocationLeft, hostnameDone)
|
delete(hostnameToLocationLeft, hostnameDone)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/provider/surfshark/servers"
|
||||||
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
||||||
"github.com/qdm12/gluetun/internal/updater/unzip"
|
"github.com/qdm12/gluetun/internal/updater/unzip"
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ func addOpenVPNServersFromZip(ctx context.Context,
|
|||||||
hostnamesDoneSet[hostname] = struct{}{}
|
hostnamesDoneSet[hostname] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
locationData := constants.SurfsharkLocationData()
|
locationData := servers.LocationData()
|
||||||
hostToLocation := hostToLocation(locationData)
|
hostToLocation := hostToLocation(locationData)
|
||||||
|
|
||||||
for fileName, content := range contents {
|
for fileName, content := range contents {
|
||||||
|
|||||||
Reference in New Issue
Block a user