-
Notifications
You must be signed in to change notification settings - Fork 1
/
technologies.go
113 lines (100 loc) · 4.42 KB
/
technologies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package nordapi
import "sync"
// Technology is a feature that a NordVPNserver can support.
type Technology struct {
ID int `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
}
// NordVPN server feature IDs
var (
TechIkev2 = &Technology{ID: 1, Name: "IKEv2/IPSec", Identifier: "ikev2"} // Ikev2/IPSec
TechOpenVPNUDP = &Technology{ID: 3, Name: "OpenVPN UDP", Identifier: "openvpn_udp"} // OpenVPN UDP
TechOpenVPNTCP = &Technology{ID: 5, Name: "OpenVPN TCP", Identifier: "openvpn_tcp"} // OpenVPN TCP
TechSocks = &Technology{ID: 7, Name: "Socks 5", Identifier: "socks"} // Socks 5 proxy
TechProxy = &Technology{ID: 9, Name: "HTTP Proxy", Identifier: "proxy"} // HTTP Proxy
TechPptp = &Technology{ID: 11, Name: "PPTP", Identifier: "pptp"} // Pptp
TechL2Tp = &Technology{ID: 13, Name: "L2TP/IPSec", Identifier: "l2tp"} // L2TP/IPSec
TechOpenVPNXorUDP = &Technology{ID: 15, Name: "OpenVPN UDP Obfuscated", Identifier: "openvpn_xor_udp"} // OpenVPN UDP Obfuscated
TechOpenVPNXorTCP = &Technology{ID: 17, Name: "OpenVPN TCP Obfuscated", Identifier: "openvpn_xor_tcp"} // OpenVPN TCP Obfuscated
TechProxyCybersec = &Technology{ID: 19, Name: "HTTP CyberSec Proxy", Identifier: "proxy_cybersec"} // HTTP CyberSec Proxy
TechProxySsl = &Technology{ID: 21, Name: "HTTP Proxy (SSL)", Identifier: "proxy_ssl"} // HTTP Proxy (SSL)
TechProxySslCybersec = &Technology{ID: 23, Name: "HTTP CyberSec Proxy (SSL)", Identifier: "proxy_ssl_cybersec"} // HTTP CyberSec Proxy (SSL)
TechIkev2V6 = &Technology{ID: 26, Name: "IKEv2/IPSec IPv6", Identifier: "ikev2_v6"} // IKEv2/IPSec IPv6
TechOpenVPNUDPV6 = &Technology{ID: 29, Name: "OpenVPN UDP IPv6", Identifier: "openvpn_udp_v6"} // OpenVPN UDP IPv6
TechOpenVPNTCPV6 = &Technology{ID: 32, Name: "OpenVPN TCP IPv6", Identifier: "openvpn_tcp_v6"} // OpenVPN TCP IPv6
TechWireguardUDP = &Technology{ID: 35, Name: "Wireguard", Identifier: "wireguard_udp"} // Wireguard
TechOpenVPNUDPTLSCrypt = &Technology{ID: 38, Name: "OpenVPN UDP TLS Crypt", Identifier: "openvpn_udp_tls_crypt"} // OpenVPN UDP TLS Crypt
TechOpenVPNTCPTLSCrypt = &Technology{ID: 41, Name: "OpenVPN TCP TLS Crypt", Identifier: "openvpn_tcp_tls_crypt"} // OpenVPN TCP TLS Crypt
)
// Avoid race conditions if two routines acess knownTechnologies
var knownTechnologiesMutex sync.Mutex
// Users should lock knownTechnologiesMutex
var knownTechnologies = []*Technology{
TechIkev2,
TechOpenVPNUDP,
TechOpenVPNTCP,
TechSocks,
TechProxy,
TechPptp,
TechL2Tp,
TechOpenVPNXorUDP,
TechOpenVPNXorTCP,
TechProxyCybersec,
TechProxySsl,
TechProxySslCybersec,
TechIkev2V6,
TechOpenVPNUDPV6,
TechOpenVPNTCPV6,
TechWireguardUDP,
TechOpenVPNUDPTLSCrypt,
TechOpenVPNTCPTLSCrypt,
}
// GetFilter implements Filter
func (t *Technology) GetFilter() string {
return "filters[servers_technologies][identifier]=" + t.Identifier
}
// Satisfies implements Filter
func (t *Technology) Satisfies(s *Server) bool {
for _, st := range s.Technologies {
if st.ID == t.ID {
return true
}
}
return false
}
// String implements fmt.Stringer
// It returns the identifier string for the technology
func (t *Technology) String() string {
return t.Identifier
}
// TechnologyIdentifier returns the Technology from its identifying string.
// If the Technology is not found, it will return nil.
func TechnologyIdentifier(identifier string) *Technology {
knownTechnologiesMutex.Lock()
defer knownTechnologiesMutex.Unlock()
for _, t := range knownTechnologies {
if t.Identifier == identifier {
return t
}
}
var technologies []*Technology
err := getAndUnmarshall("https://api.nordvpn.com/v1/technologies", &technologies)
if err != nil {
return nil
}
var found *Technology
AlreadyHave:
for i := range technologies {
for j := range knownTechnologies {
if technologies[i].Identifier == knownTechnologies[j].Identifier {
continue AlreadyHave
}
}
knownTechnologies = append(knownTechnologies, technologies[i])
if technologies[i].Identifier == identifier {
found = technologies[i]
}
}
return found
}