Skip to content

Commit

Permalink
Remove support for multihop
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Dec 27, 2024
1 parent 51103b2 commit 0a2bb62
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 3,496 deletions.
26 changes: 10 additions & 16 deletions internal/provider/ovpn/updater/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ type apiDataCenter struct {
}

type apiServer struct {
IP netip.Addr `json:"ip"`
Ptr string `json:"ptr"` // hostname
Online bool `json:"online"`
PublicKey string `json:"public_key"`
WireguardPorts []uint16 `json:"wireguard_ports"`
MultiHopOpenvpnPort uint16 `json:"multihop_openvpn_port"`
MultiHopWireguardPort uint16 `json:"multihop_wireguard_port"`
IP netip.Addr `json:"ip"`
Ptr string `json:"ptr"` // hostname
Online bool `json:"online"`
PublicKey string `json:"public_key"`
WireguardPorts []uint16 `json:"wireguard_ports"`
}

func fetchAPI(ctx context.Context, client *http.Client) (
Expand Down Expand Up @@ -109,13 +107,11 @@ func (a *apiDataCenter) validate() (err error) {
}

var (
ErrIPFieldNotValid = errors.New("ip address is not set")
ErrHostnameFieldNotSet = errors.New("hostname field is not set")
ErrPublicKeyFieldNotSet = errors.New("public key field is not set")
ErrWireguardPortsNotSet = errors.New("wireguard ports array is not set")
ErrWireguardPortNotDefault = errors.New("wireguard port is not the default 9929")
ErrMultiHopOpenVPNPortNotSet = errors.New("multihop OpenVPN port is not set")
ErrMultiHopWireguardPortNotSet = errors.New("multihop WireGuard port is not set")
ErrIPFieldNotValid = errors.New("ip address is not set")
ErrHostnameFieldNotSet = errors.New("hostname field is not set")
ErrPublicKeyFieldNotSet = errors.New("public key field is not set")
ErrWireguardPortsNotSet = errors.New("wireguard ports array is not set")
ErrWireguardPortNotDefault = errors.New("wireguard port is not the default 9929")
)

func (a *apiServer) validate() (err error) {
Expand All @@ -129,8 +125,6 @@ func (a *apiServer) validate() (err error) {
err: ErrWireguardPortNotDefault,
condition: len(a.WireguardPorts) != 1 || a.WireguardPorts[0] != defaultWireguardPort,
},
{err: ErrMultiHopOpenVPNPortNotSet, condition: a.MultiHopOpenvpnPort == 0},
{err: ErrMultiHopWireguardPortNotSet, condition: a.MultiHopWireguardPort == 0},
}
err = collectErrors(conditionalErrors)
switch {
Expand Down
12 changes: 5 additions & 7 deletions internal/provider/ovpn/updater/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ func Test_fetchAPI(t *testing.T) {
DataCenters: []apiDataCenter{
{CountryName: "Austria", City: "Vienna", Servers: []apiServer{
{
IP: netip.MustParseAddr("37.120.212.227"),
Ptr: "vpn44.prd.vienna.ovpn.com",
Online: true,
PublicKey: "r83LIc0Q2F8s3dY9x5y17Yz8wTADJc7giW1t5eSmoXc=",
WireguardPorts: []uint16{9929},
MultiHopOpenvpnPort: 20044,
MultiHopWireguardPort: 30044,
IP: netip.MustParseAddr("37.120.212.227"),
Ptr: "vpn44.prd.vienna.ovpn.com",
Online: true,
PublicKey: "r83LIc0Q2F8s3dY9x5y17Yz8wTADJc7giW1t5eSmoXc=",
WireguardPorts: []uint16{9929},
},
}},
},
Expand Down
11 changes: 2 additions & 9 deletions internal/provider/ovpn/updater/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
openVPNServer.VPN = vpn.OpenVPN
openVPNServer.TCP = true
openVPNServer.UDP = true
multiHopOpenVPNServer := openVPNServer
multiHopOpenVPNServer.MultiHop = true
multiHopOpenVPNServer.PortsTCP = []uint16{apiServer.MultiHopOpenvpnPort}
multiHopOpenVPNServer.PortsUDP = []uint16{apiServer.MultiHopOpenvpnPort}
servers = append(servers, openVPNServer, multiHopOpenVPNServer)
servers = append(servers, openVPNServer)

wireguardServer := baseServer
wireguardServer.VPN = vpn.Wireguard
wireguardServer.WgPubKey = apiServer.PublicKey
multiHopWireguardServer := wireguardServer
multiHopWireguardServer.MultiHop = true
multiHopWireguardServer.PortsUDP = []uint16{apiServer.MultiHopWireguardPort}
servers = append(servers, wireguardServer, multiHopWireguardServer)
servers = append(servers, wireguardServer)
}
}

Expand Down
Loading

0 comments on commit 0a2bb62

Please sign in to comment.