Feature: filter by hostname for PureVPN servers

- Record support for TCP and UDP for each hostname
- Fix: each hostname supports only TCP or UDP, not both
- Update PureVPN server information
This commit is contained in:
Quentin McGaw
2021-05-10 00:36:14 +00:00
parent 4fe1e062f2
commit 6c1c069261
11 changed files with 185 additions and 103 deletions

View File

@@ -8,10 +8,35 @@ import (
)
var (
ErrUnknownProto = errors.New("unknown protocol")
ErrNoRemoteHost = errors.New("remote host not found")
ErrNoRemoteIP = errors.New("remote IP not found")
)
func ExtractProto(b []byte) (tcp, udp bool, err error) {
lines := strings.Split(string(b), "\n")
const protoPrefix = "proto "
for _, line := range lines {
if !strings.HasPrefix(line, protoPrefix) {
continue
}
s := strings.TrimPrefix(line, protoPrefix)
s = strings.TrimSpace(s)
s = strings.ToLower(s)
switch s {
case "tcp":
return true, false, nil
case "udp":
return false, true, nil
default:
return false, false, fmt.Errorf("%w: %s", ErrUnknownProto, s)
}
}
// default is UDP if unspecified in openvpn configuration
return false, true, nil
}
func ExtractHost(b []byte) (host, warning string, err error) {
const (
rejectIP = true