Feature: Multiple IPs for each Torguard server

- Fallback on IP from configuration file if DNS resolution fails
- Download both TCP and UDP zip files to detect support for each
- Filter servers by supported network protocol
-
This commit is contained in:
Quentin McGaw
2021-05-10 01:48:52 +00:00
parent eff65dce00
commit 95b0fb81d6
9 changed files with 248 additions and 119 deletions

View File

@@ -62,8 +62,8 @@ func GetAllServers() (allServers models.AllServers) {
Servers: SurfsharkServers(),
},
Torguard: models.TorguardServers{
Version: 1,
Timestamp: 1613357861,
Version: 2,
Timestamp: 1620611129,
Servers: TorguardServers(),
},
Vyprvpn: models.VyprvpnServers{

View File

@@ -92,7 +92,7 @@ func Test_versions(t *testing.T) {
"Torguard": {
model: models.TorguardServer{},
version: allServers.Torguard.Version,
digest: "752702f3",
digest: "6eb9028e",
},
"Vyprvpn": {
model: models.VyprvpnServer{},
@@ -198,7 +198,7 @@ func Test_timestamps(t *testing.T) {
"Torguard": {
servers: allServers.Torguard.Servers,
timestamp: allServers.Torguard.Timestamp,
digest: "dffab93e",
digest: "af54b9e8",
},
"Vyprvpn": {
servers: allServers.Vyprvpn.Servers,

View File

@@ -43,59 +43,59 @@ func TorguardHostnamesChoices() (choices []string) {
// TorguardServers returns a slice of all the server information for Torguard.
func TorguardServers() []models.TorguardServer {
return []models.TorguardServer{
{Country: "Australia", City: "Sydney", Hostname: "au.torguardvpnaccess.com", IP: net.IP{168, 1, 210, 188}},
{Country: "Austria", City: "", Hostname: "aus.torguardvpnaccess.com", IP: net.IP{37, 120, 155, 18}},
{Country: "Belarus", City: "", Hostname: "bl.torguardvpnaccess.com", IP: net.IP{95, 47, 99, 12}},
{Country: "Belgium", City: "", Hostname: "bg.torguardvpnaccess.com", IP: net.IP{89, 249, 73, 250}},
{Country: "Brazil", City: "", Hostname: "br.torguardvpnaccess.com", IP: net.IP{169, 57, 191, 3}},
{Country: "Bulgaria", City: "", Hostname: "bul.torguardvpnaccess.com", IP: net.IP{82, 102, 23, 186}},
{Country: "Canada", City: "Toronto", Hostname: "ca.torguardvpnaccess.com", IP: net.IP{184, 75, 209, 250}},
{Country: "Canada", City: "Vancouver", Hostname: "vanc.ca.west.torguardvpnaccess.com", IP: net.IP{107, 181, 189, 48}},
{Country: "Chile", City: "", Hostname: "chil.torguardvpnaccess.com", IP: net.IP{37, 235, 52, 19}},
{Country: "Cyprus", City: "", Hostname: "cp.torguardvpnaccess.com", IP: net.IP{185, 173, 226, 49}},
{Country: "Czech", City: "", Hostname: "czech.torguardvpnaccess.com", IP: net.IP{185, 189, 115, 103}},
{Country: "Denmark", City: "", Hostname: "den.torguardvpnaccess.com", IP: net.IP{37, 120, 131, 29}},
{Country: "Finland", City: "", Hostname: "fin.torguardvpnaccess.com", IP: net.IP{91, 233, 116, 228}},
{Country: "France", City: "", Hostname: "fr.torguardvpnaccess.com", IP: net.IP{93, 177, 75, 90}},
{Country: "Germany", City: "", Hostname: "gr.torguardvpnaccess.com", IP: net.IP{93, 177, 73, 90}},
{Country: "Greece", City: "", Hostname: "gre.torguardvpnaccess.com", IP: net.IP{45, 92, 33, 10}},
{Country: "Hong", City: "Kong", Hostname: "hk.torguardvpnaccess.com", IP: net.IP{45, 133, 181, 158}},
{Country: "Hungary", City: "", Hostname: "hg.torguardvpnaccess.com", IP: net.IP{37, 120, 144, 106}},
{Country: "Iceland", City: "", Hostname: "ice.torguardvpnaccess.com", IP: net.IP{82, 221, 111, 11}},
{Country: "India", City: "Bangalore", Hostname: "in.torguardvpnaccess.com", IP: net.IP{139, 59, 62, 109}},
{Country: "Ireland", City: "", Hostname: "ire.torguardvpnaccess.com", IP: net.IP{81, 17, 246, 108}},
{Country: "Israel", City: "", Hostname: "isr.torguardvpnaccess.com", IP: net.IP{91, 223, 106, 201}},
{Country: "Italy", City: "", Hostname: "it.torguardvpnaccess.com", IP: net.IP{192, 145, 127, 190}},
{Country: "Japan", City: "", Hostname: "jp.torguardvpnaccess.com", IP: net.IP{91, 207, 174, 50}},
{Country: "Latvia", City: "", Hostname: "lv.torguardvpnaccess.com", IP: net.IP{109, 248, 149, 167}},
{Country: "Luxembourg", City: "", Hostname: "lux.torguardvpnaccess.com", IP: net.IP{94, 242, 238, 66}},
{Country: "Mexico", City: "", Hostname: "mx.torguardvpnaccess.com", IP: net.IP{45, 133, 180, 34}},
{Country: "Moldova", City: "", Hostname: "md.torguardvpnaccess.com", IP: net.IP{178, 175, 128, 74}},
{Country: "Netherlands", City: "", Hostname: "nl.torguardvpnaccess.com", IP: net.IP{88, 202, 177, 181}},
{Country: "New", City: "Zealand", Hostname: "nz.torguardvpnaccess.com", IP: net.IP{103, 108, 94, 58}},
{Country: "Norway", City: "", Hostname: "no.torguardvpnaccess.com", IP: net.IP{185, 125, 169, 31}},
{Country: "Poland", City: "", Hostname: "pl.torguardvpnaccess.com", IP: net.IP{37, 120, 156, 194}},
{Country: "Portugal", City: "", Hostname: "por.torguardvpnaccess.com", IP: net.IP{94, 46, 179, 75}},
{Country: "Romania", City: "", Hostname: "ro.torguardvpnaccess.com", IP: net.IP{93, 120, 27, 162}},
{Country: "Singapore", City: "", Hostname: "singp.torguardvpnaccess.com", IP: net.IP{206, 189, 43, 152}},
{Country: "Slovakia", City: "", Hostname: "slk.torguardvpnaccess.com", IP: net.IP{46, 29, 2, 113}},
{Country: "South", City: "Korea", Hostname: "sk.torguardvpnaccess.com", IP: net.IP{169, 56, 83, 216}},
{Country: "Spain", City: "", Hostname: "sp.torguardvpnaccess.com", IP: net.IP{192, 145, 124, 242}},
{Country: "Sweden", City: "", Hostname: "swe.torguardvpnaccess.com", IP: net.IP{37, 120, 153, 72}},
{Country: "Switzerland", City: "", Hostname: "swiss.torguardvpnaccess.com", IP: net.IP{195, 206, 105, 37}},
{Country: "Taiwan", City: "", Hostname: "tw.torguardvpnaccess.com", IP: net.IP{61, 216, 159, 176}},
{Country: "Thailand", City: "", Hostname: "thai.torguardvpnaccess.com", IP: net.IP{202, 129, 16, 104}},
{Country: "UAE", City: "", Hostname: "uae.secureconnect.me", IP: net.IP{45, 9, 250, 10}},
{Country: "UK", City: "London", Hostname: "uk.torguardvpnaccess.com", IP: net.IP{109, 123, 118, 13}},
{Country: "USA", City: "Atlanta", Hostname: "atl.east.usa.torguardvpnaccess.com", IP: net.IP{104, 223, 95, 50}},
{Country: "USA", City: "Chicago", Hostname: "chi.central.usa.torguardvpnaccess.com", IP: net.IP{167, 160, 172, 106}},
{Country: "USA", City: "Dallas", Hostname: "dal.central.usa.torguardvpnaccess.com", IP: net.IP{96, 44, 145, 26}},
{Country: "USA", City: "Las Vegas", Hostname: "lv.west.usa.torguardvpnaccess.com", IP: net.IP{76, 164, 203, 130}},
{Country: "USA", City: "Los Angeles", Hostname: "la.west.usa.torguardvpnaccess.com", IP: net.IP{67, 215, 236, 58}},
{Country: "USA", City: "Miami", Hostname: "fl.east.usa.torguardvpnaccess.com", IP: net.IP{96, 47, 226, 42}},
{Country: "USA", City: "New Jersey", Hostname: "nj.east.usa.torguardvpnaccess.com", IP: net.IP{23, 226, 128, 146}},
{Country: "USA", City: "New York", Hostname: "ny.east.usa.torguardvpnaccess.com", IP: net.IP{209, 95, 50, 116}},
{Country: "USA", City: "San Francisco", Hostname: "sf.west.usa.torguardvpnaccess.com", IP: net.IP{206, 189, 218, 238}},
{Country: "USA", City: "Seattle", Hostname: "sa.west.usa.torguardvpnaccess.com", IP: net.IP{199, 229, 250, 38}},
{Country: "Australia", City: "Sydney", Hostname: "au.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{193, 56, 253, 50}, {217, 138, 205, 106}, {93, 115, 35, 106}, {93, 115, 35, 122}, {217, 138, 205, 218}, {93, 115, 35, 98}, {217, 138, 205, 98}, {193, 56, 253, 146}, {217, 138, 205, 114}, {93, 115, 35, 130}, {217, 138, 205, 194}, {93, 115, 35, 114}, {93, 115, 35, 154}, {193, 56, 253, 98}, {93, 115, 35, 138}, {193, 56, 253, 82}, {193, 56, 253, 66}, {193, 56, 253, 18}, {193, 56, 253, 34}, {93, 115, 35, 146}, {217, 138, 205, 202}, {193, 56, 253, 114}, {217, 138, 205, 210}, {193, 56, 253, 130}}},
{Country: "Austria", City: "", Hostname: "aus.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{37, 120, 155, 26}, {37, 120, 155, 10}, {37, 120, 155, 18}, {37, 120, 155, 2}, {37, 120, 155, 34}}},
{Country: "Belarus", City: "", Hostname: "bl.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{95, 47, 99, 12}}},
{Country: "Belgium", City: "", Hostname: "bg.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 232, 21, 210}, {89, 249, 73, 162}, {89, 249, 73, 130}, {89, 249, 73, 170}, {185, 104, 186, 2}, {185, 232, 21, 34}, {185, 232, 21, 242}, {194, 187, 251, 34}, {185, 232, 21, 250}, {89, 249, 73, 250}, {185, 232, 21, 42}}},
{Country: "Brazil", City: "", Hostname: "br.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 133, 180, 162}, {45, 133, 180, 154}, {45, 133, 180, 138}, {45, 133, 180, 130}, {45, 133, 180, 146}}},
{Country: "Bulgaria", City: "", Hostname: "bul.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{82, 102, 23, 170}, {82, 102, 23, 202}, {82, 102, 23, 194}, {82, 102, 23, 210}, {82, 102, 23, 186}, {82, 102, 23, 178}, {82, 102, 23, 218}}},
{Country: "Canada", City: "Toronto", Hostname: "ca.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{184, 75, 209, 250}}},
{Country: "Canada", City: "Vancouver", Hostname: "vanc.ca.west.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{107, 181, 189, 41}, {107, 181, 189, 37}, {107, 181, 189, 43}, {107, 181, 189, 36}, {107, 181, 189, 38}, {107, 181, 189, 34}, {107, 181, 189, 42}, {107, 181, 189, 45}, {107, 181, 189, 35}, {107, 181, 189, 40}, {107, 181, 189, 48}, {107, 181, 189, 44}, {107, 181, 189, 46}, {107, 181, 189, 47}, {107, 181, 189, 39}}},
{Country: "Chile", City: "", Hostname: "chil.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{37, 235, 52, 71}, {193, 235, 146, 104}, {37, 235, 52, 42}, {37, 235, 52, 19}}},
{Country: "Cyprus", City: "", Hostname: "cp.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 173, 226, 49}}},
{Country: "Czech", City: "", Hostname: "czech.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 189, 115, 98}, {185, 189, 115, 103}, {185, 189, 115, 108}, {185, 189, 115, 113}, {185, 189, 115, 118}}},
{Country: "Denmark", City: "", Hostname: "den.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 12, 221, 26}, {45, 12, 221, 2}, {2, 58, 46, 146}, {185, 245, 84, 74}, {2, 58, 46, 138}, {2, 58, 46, 170}, {45, 12, 221, 42}, {45, 12, 221, 34}, {45, 12, 221, 18}, {2, 58, 46, 178}, {2, 58, 46, 162}, {2, 58, 46, 154}, {2, 58, 46, 186}, {45, 12, 221, 10}}},
{Country: "Finland", City: "", Hostname: "fin.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{91, 132, 197, 192}, {91, 132, 197, 188}, {91, 132, 197, 186}}},
{Country: "France", City: "", Hostname: "fr.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{93, 177, 75, 58}, {93, 177, 75, 66}, {93, 177, 75, 122}, {93, 177, 75, 90}, {93, 177, 75, 106}, {93, 177, 75, 82}, {93, 177, 75, 2}, {93, 177, 75, 138}, {93, 177, 75, 146}, {93, 177, 75, 26}, {93, 177, 75, 18}, {93, 177, 75, 34}, {93, 177, 75, 10}, {93, 177, 75, 210}, {37, 120, 158, 138}, {93, 177, 75, 162}, {93, 177, 75, 114}, {93, 177, 75, 202}, {93, 177, 75, 130}, {93, 177, 75, 98}, {93, 177, 75, 154}, {93, 177, 75, 42}, {93, 177, 75, 74}, {93, 177, 75, 50}, {93, 177, 75, 218}}},
{Country: "Germany", City: "", Hostname: "gr.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{93, 177, 73, 90}}},
{Country: "Greece", City: "", Hostname: "gre.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 92, 33, 10}, {45, 92, 33, 18}, {45, 92, 33, 2}}},
{Country: "Hong", City: "Kong", Hostname: "hk.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 133, 181, 158}}},
{Country: "Hungary", City: "", Hostname: "hg.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{37, 120, 144, 98}, {37, 120, 144, 106}}},
{Country: "Iceland", City: "", Hostname: "ice.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 133, 192, 250}, {45, 133, 192, 218}, {45, 133, 192, 214}, {45, 133, 192, 226}, {45, 133, 192, 230}, {45, 133, 192, 210}, {45, 133, 192, 234}, {45, 133, 192, 254}}},
{Country: "India", City: "Bangalore", Hostname: "in.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{43, 251, 180, 6}, {103, 78, 121, 182}, {103, 78, 121, 142}, {43, 251, 180, 26}, {43, 251, 180, 10}, {172, 107, 172, 6}, {43, 251, 180, 2}}},
{Country: "Ireland", City: "", Hostname: "ire.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{77, 81, 139, 90}, {77, 81, 139, 66}, {77, 81, 139, 82}, {77, 81, 139, 74}, {77, 81, 139, 58}}},
{Country: "Israel", City: "", Hostname: "isr.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{91, 223, 106, 201}}},
{Country: "Italy", City: "", Hostname: "it.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 9, 251, 182}, {192, 145, 127, 190}, {185, 128, 27, 106}, {45, 9, 251, 14}, {45, 9, 251, 178}}},
{Country: "Japan", City: "", Hostname: "jp.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{91, 207, 174, 50}}},
{Country: "Latvia", City: "", Hostname: "lv.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{109, 248, 149, 167}}},
{Country: "Luxembourg", City: "", Hostname: "lux.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{5, 253, 204, 74}, {5, 253, 204, 90}, {5, 253, 204, 66}, {5, 253, 204, 58}, {5, 253, 204, 82}}},
{Country: "Mexico", City: "", Hostname: "mx.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{45, 133, 180, 26}, {45, 133, 180, 34}, {45, 133, 180, 2}, {45, 133, 180, 18}, {45, 133, 180, 10}}},
{Country: "Moldova", City: "", Hostname: "md.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{178, 175, 131, 114}, {178, 175, 131, 106}}},
{Country: "Netherlands", City: "", Hostname: "nl.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{88, 202, 177, 181}}},
{Country: "New", City: "Zealand", Hostname: "nz.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{103, 108, 94, 58}}},
{Country: "Norway", City: "", Hostname: "no.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 181, 61, 38}, {185, 125, 169, 32}, {185, 181, 61, 40}, {185, 125, 169, 28}, {185, 181, 61, 37}, {185, 181, 61, 39}, {185, 125, 169, 30}, {185, 125, 169, 31}, {185, 125, 169, 29}, {185, 125, 169, 24}, {185, 125, 169, 26}, {185, 125, 169, 27}, {185, 125, 169, 23}, {185, 125, 169, 25}, {185, 125, 168, 247}, {185, 125, 168, 248}, {185, 181, 61, 36}}},
{Country: "Poland", City: "", Hostname: "pl.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{37, 120, 156, 194}}},
{Country: "Portugal", City: "", Hostname: "por.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{94, 46, 179, 75}}},
{Country: "Romania", City: "", Hostname: "ro.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 45, 14, 250}, {194, 59, 248, 202}, {31, 14, 252, 146}, {31, 14, 252, 18}, {89, 46, 103, 106}, {194, 59, 248, 210}, {89, 46, 103, 2}, {93, 120, 27, 162}, {31, 14, 252, 178}, {185, 45, 14, 122}, {31, 14, 252, 90}, {185, 45, 15, 106}, {89, 40, 71, 106}}},
{Country: "Singapore", City: "", Hostname: "singp.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{91, 245, 253, 134}, {185, 200, 117, 142}, {91, 245, 253, 138}, {92, 119, 178, 22}, {82, 102, 25, 2}, {185, 200, 116, 250}, {185, 200, 117, 138}, {82, 102, 25, 226}, {92, 119, 178, 26}, {185, 200, 117, 186}}},
{Country: "Slovakia", City: "", Hostname: "slk.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{193, 37, 255, 162}, {193, 37, 255, 130}, {193, 37, 255, 122}, {193, 37, 255, 146}, {193, 37, 255, 138}}},
{Country: "South", City: "Korea", Hostname: "sk.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{169, 56, 83, 216}}},
{Country: "Spain", City: "", Hostname: "sp.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{192, 145, 124, 242}}},
{Country: "Sweden", City: "", Hostname: "swe.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{37, 120, 153, 82}, {37, 120, 153, 72}, {37, 120, 153, 32}, {37, 120, 153, 97}, {37, 120, 153, 102}, {37, 120, 153, 92}, {37, 120, 153, 77}, {37, 120, 153, 42}, {37, 120, 153, 52}, {37, 120, 153, 47}, {37, 120, 153, 22}, {37, 120, 153, 57}, {37, 120, 153, 107}, {37, 120, 153, 67}, {37, 120, 153, 7}, {37, 120, 153, 37}, {37, 120, 153, 2}, {37, 120, 153, 12}, {37, 120, 153, 87}, {37, 120, 153, 17}, {37, 120, 153, 62}, {37, 120, 153, 27}}},
{Country: "Switzerland", City: "", Hostname: "swiss.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{195, 206, 105, 17}, {195, 206, 105, 22}, {195, 206, 105, 32}, {195, 206, 105, 52}, {195, 206, 105, 7}, {185, 236, 201, 210}, {195, 206, 105, 42}, {217, 138, 203, 242}, {195, 206, 105, 12}, {195, 206, 105, 37}, {185, 236, 201, 215}, {195, 206, 105, 27}, {195, 206, 105, 57}, {195, 206, 105, 47}, {195, 206, 105, 2}, {217, 138, 203, 154}}},
{Country: "Taiwan", City: "", Hostname: "tw.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{61, 216, 159, 176}}},
{Country: "Thailand", City: "", Hostname: "thai.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{202, 129, 16, 106}, {202, 129, 16, 104}, {202, 129, 16, 42}, {202, 129, 16, 140}, {202, 129, 16, 143}}},
{Country: "UAE", City: "", Hostname: "uae.secureconnect.me", TCP: true, UDP: true, IPs: []net.IP{{45, 9, 249, 158}, {45, 9, 249, 238}, {45, 9, 250, 10}}},
{Country: "UK", City: "London", Hostname: "uk.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{109, 123, 118, 13}}},
{Country: "USA", City: "Atlanta", Hostname: "atl.east.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{104, 223, 95, 50}}},
{Country: "USA", City: "Chicago", Hostname: "chi.central.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{167, 160, 172, 106}}},
{Country: "USA", City: "Dallas", Hostname: "dal.central.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{96, 44, 145, 26}}},
{Country: "USA", City: "Las Vegas", Hostname: "lv.west.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{185, 242, 5, 82}, {45, 89, 173, 106}, {37, 120, 147, 250}, {185, 242, 5, 74}, {185, 242, 5, 178}, {45, 89, 173, 114}, {45, 89, 173, 98}, {185, 242, 5, 66}, {185, 242, 5, 186}, {37, 120, 147, 234}, {185, 242, 5, 170}, {37, 120, 147, 242}, {185, 242, 5, 90}, {45, 89, 173, 162}, {185, 242, 5, 162}, {45, 89, 173, 122}}},
{Country: "USA", City: "Los Angeles", Hostname: "la.west.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{67, 215, 236, 58}}},
{Country: "USA", City: "Miami", Hostname: "fl.east.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{96, 47, 226, 42}}},
{Country: "USA", City: "New Jersey", Hostname: "nj.east.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{23, 226, 128, 146}}},
{Country: "USA", City: "New York", Hostname: "ny.east.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{67, 213, 221, 12}, {67, 213, 221, 26}, {67, 213, 221, 6}, {67, 213, 221, 7}, {67, 213, 221, 15}, {67, 213, 221, 5}, {67, 213, 221, 22}, {67, 213, 221, 24}, {67, 213, 221, 13}, {67, 213, 221, 23}, {67, 213, 221, 9}, {67, 213, 221, 16}, {67, 213, 221, 19}, {67, 213, 221, 25}, {67, 213, 221, 3}, {67, 213, 221, 10}, {67, 213, 221, 20}, {67, 213, 221, 18}, {67, 213, 221, 17}, {67, 213, 221, 21}, {67, 213, 221, 14}, {67, 213, 221, 8}, {67, 213, 221, 4}, {67, 213, 221, 11}, {67, 213, 221, 27}}},
{Country: "USA", City: "San Francisco", Hostname: "sf.west.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{206, 189, 218, 238}, {206, 189, 64, 126}, {206, 189, 218, 114}, {206, 189, 169, 41}, {206, 189, 64, 78}, {167, 99, 109, 166}, {206, 189, 214, 52}, {206, 189, 208, 52}, {206, 189, 218, 112}, {206, 189, 208, 113}, {206, 189, 214, 46}}},
{Country: "USA", City: "Seattle", Hostname: "sa.west.usa.torguardvpnaccess.com", TCP: true, UDP: true, IPs: []net.IP{{199, 229, 250, 38}}},
}
}

View File

@@ -161,15 +161,17 @@ func (s *SurfsharkServer) String() string {
}
type TorguardServer struct {
Country string `json:"country"`
City string `json:"city"`
Hostname string `json:"hostname"`
IP net.IP `json:"ip"`
Country string `json:"country"`
City string `json:"city"`
Hostname string `json:"hostname"`
TCP bool `json:"tcp"`
UDP bool `json:"udp"`
IPs []net.IP `json:"ips"`
}
func (s *TorguardServer) String() string {
return fmt.Sprintf("{Country: %q, City: %q, Hostname: %q, IP: %s}",
s.Country, s.City, s.Hostname, goStringifyIP(s.IP))
return fmt.Sprintf("{Country: %q, City: %q, Hostname: %q, TCP: %t, UDP: %t, IPs: %s}",
s.Country, s.City, s.Hostname, s.TCP, s.UDP, goStringifyIPs(s.IPs))
}
type VyprvpnServer struct {

View File

@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"strconv"
"strings"
"github.com/qdm12/gluetun/internal/configuration"
"github.com/qdm12/gluetun/internal/constants"
@@ -28,12 +29,16 @@ func newTorguard(servers []models.TorguardServer, timeNow timeNowFunc) *torguard
}
}
func (t *torguard) filterServers(countries, cities, hostnames []string) (servers []models.TorguardServer) {
func (t *torguard) filterServers(countries, cities, hostnames []string,
protocol string) (servers []models.TorguardServer) {
for _, server := range t.servers {
switch {
case filterByPossibilities(server.Country, countries):
case filterByPossibilities(server.City, cities):
case filterByPossibilities(server.Hostname, hostnames):
case
filterByPossibilities(server.Country, countries),
filterByPossibilities(server.City, cities),
filterByPossibilities(server.Hostname, hostnames),
strings.EqualFold(protocol, "tcp") && !server.TCP,
strings.EqualFold(protocol, "udp") && !server.UDP:
default:
servers = append(servers, server)
}
@@ -70,17 +75,21 @@ func (t *torguard) GetOpenVPNConnection(selection configuration.ServerSelection)
return models.OpenVPNConnection{IP: selection.TargetIP, Port: port, Protocol: selection.Protocol}, nil
}
servers := t.filterServers(selection.Countries, selection.Cities, selection.Hostnames)
servers := t.filterServers(selection.Countries, selection.Cities,
selection.Hostnames, selection.Protocol)
if len(servers) == 0 {
return connection, t.notFoundErr(selection)
}
connections := make([]models.OpenVPNConnection, len(servers))
for i := range servers {
connections[i] = models.OpenVPNConnection{
IP: servers[i].IP,
Port: port,
Protocol: selection.Protocol,
var connections []models.OpenVPNConnection
for _, server := range servers {
for _, ip := range server.IPs {
connection := models.OpenVPNConnection{
IP: ip,
Port: port,
Protocol: selection.Protocol,
}
connections = append(connections, connection)
}
}

View File

@@ -222,7 +222,8 @@ func (u *updater) updateSurfshark(ctx context.Context) (err error) {
func (u *updater) updateTorguard(ctx context.Context) (err error) {
minServers := getMinServers(len(u.servers.Torguard.Servers))
servers, warnings, err := torguard.GetServers(ctx, u.unzipper, minServers)
servers, warnings, err := torguard.GetServers(
ctx, u.unzipper, u.presolver, minServers)
if u.options.CLI {
for _, warning := range warnings {
u.logger.Warn("Torguard: %s", warning)

View File

@@ -0,0 +1,55 @@
package torguard
import (
"net"
"github.com/qdm12/gluetun/internal/models"
)
type hostToServer map[string]models.TorguardServer
func (hts hostToServer) add(host, country, city string, tcp, udp bool, ip net.IP) {
server, ok := hts[host]
if !ok {
server.Hostname = host
server.Country = country
server.City = city
server.IPs = append(server.IPs, ip) // used if DNS resolution fails downstream
}
if tcp {
server.TCP = tcp
}
if udp {
server.UDP = udp
}
hts[host] = server
}
func (hts hostToServer) toHostsSlice() (hosts []string) {
hosts = make([]string, 0, len(hts))
for host := range hts {
hosts = append(hosts, host)
}
return hosts
}
func (hts hostToServer) adaptWithIPs(hostToIPs map[string][]net.IP) {
for host, IPs := range hostToIPs {
server := hts[host]
server.IPs = IPs
hts[host] = server
}
for host, server := range hts {
if len(server.IPs) == 0 {
delete(hts, host)
}
}
}
func (hts hostToServer) toServersSlice() (servers []models.TorguardServer) {
servers = make([]models.TorguardServer, 0, len(hts))
for _, server := range hts {
servers = append(servers, server)
}
return servers
}

View File

@@ -0,0 +1,32 @@
package torguard
import (
"context"
"net"
"time"
"github.com/qdm12/gluetun/internal/updater/resolver"
)
func resolveHosts(ctx context.Context, presolver resolver.Parallel,
hosts []string, minServers int) (hostToIPs map[string][]net.IP,
warnings []string, err error) {
const (
maxFailRatio = 0.1
maxDuration = 20 * time.Second
betweenDuration = time.Second
maxNoNew = 2
maxFails = 2
)
settings := resolver.ParallelSettings{
MaxFailRatio: maxFailRatio,
MinFound: minServers,
Repeat: resolver.RepeatSettings{
MaxDuration: maxDuration,
BetweenDuration: betweenDuration,
MaxNoNew: maxNoNew,
MaxFails: maxFails,
},
}
return presolver.Resolve(ctx, hosts, settings)
}

View File

@@ -10,61 +10,57 @@ import (
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/updater/openvpn"
"github.com/qdm12/gluetun/internal/updater/resolver"
"github.com/qdm12/gluetun/internal/updater/unzip"
)
var ErrNotEnoughServers = errors.New("not enough servers found")
func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
func GetServers(ctx context.Context, unzipper unzip.Unzipper,
presolver resolver.Parallel, minServers int) (
servers []models.TorguardServer, warnings []string, err error) {
const url = "https://torguard.net/downloads/OpenVPN-TCP-Linux.zip"
contents, err := unzipper.FetchAndExtract(ctx, url)
const tcpURL = "https://torguard.net/downloads/OpenVPN-TCP-Linux.zip"
tcpContents, err := unzipper.FetchAndExtract(ctx, tcpURL)
if err != nil {
return nil, nil, err
} else if len(contents) < minServers {
return nil, nil, fmt.Errorf("%w: %d and expected at least %d",
ErrNotEnoughServers, len(contents), minServers)
}
servers = make([]models.TorguardServer, 0, len(contents))
for fileName, content := range contents {
if !strings.HasSuffix(fileName, ".ovpn") {
continue // not an OpenVPN file
}
country, city := parseFilename(fileName)
host, warning, err := openvpn.ExtractHost(content)
if warning != "" {
warnings = append(warnings, warning)
}
if err != nil {
// treat error as warning and go to next file
warning := err.Error() + " in " + fileName
warnings = append(warnings, warning)
continue
}
ip, warning, err := openvpn.ExtractIP(content)
if warning != "" {
warnings = append(warnings, warning)
}
if err != nil {
// treat error as warning and go to next file
warning := err.Error() + " in " + fileName
warnings = append(warnings, warning)
continue
}
server := models.TorguardServer{
Country: country,
City: city,
Hostname: host,
IP: ip,
}
servers = append(servers, server)
const udpURL = "https://torguard.net/downloads/OpenVPN-UDP-Linux.zip"
udpContents, err := unzipper.FetchAndExtract(ctx, udpURL)
if err != nil {
return nil, nil, err
}
hts := make(hostToServer)
for fileName, content := range tcpContents {
const tcp, udp = true, false
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp)
warnings = append(warnings, newWarnings...)
}
for fileName, content := range udpContents {
const tcp, udp = false, true
newWarnings := addServerFromOvpn(fileName, content, hts, tcp, udp)
warnings = append(warnings, newWarnings...)
}
if len(hts) < minServers {
return nil, warnings, fmt.Errorf("%w: %d and expected at least %d",
ErrNotEnoughServers, len(hts), minServers)
}
hosts := hts.toHostsSlice()
hostToIPs, newWarnings, err := resolveHosts(ctx, presolver, hosts, minServers)
warnings = append(warnings, newWarnings...)
if err != nil {
return nil, warnings, err
}
hts.adaptWithIPs(hostToIPs)
servers = hts.toServersSlice()
if len(servers) < minServers {
return nil, warnings, fmt.Errorf("%w: %d and expected at least %d",
ErrNotEnoughServers, len(servers), minServers)
@@ -74,3 +70,37 @@ func GetServers(ctx context.Context, unzipper unzip.Unzipper, minServers int) (
return servers, warnings, nil
}
func addServerFromOvpn(fileName string, content []byte,
hts hostToServer, tcp, udp bool) (warnings []string) {
if !strings.HasSuffix(fileName, ".ovpn") {
return nil // not an OpenVPN file
}
country, city := parseFilename(fileName)
host, warning, err := openvpn.ExtractHost(content)
if warning != "" {
warnings = append(warnings, warning)
}
if err != nil {
// treat error as warning and go to next file
warning := err.Error() + " in " + fileName
warnings = append(warnings, warning)
return warnings
}
ip, warning, err := openvpn.ExtractIP(content)
if warning != "" {
warnings = append(warnings, warning)
}
if err != nil {
// treat error as warning and go to next file
warning := err.Error() + " in " + fileName
warnings = append(warnings, warning)
return warnings
}
hts.add(host, country, city, tcp, udp, ip)
return warnings
}