Release 1.2.0 Windows amd64 with Hysteria 2

This commit is contained in:
Navis
2026-07-28 07:14:52 +03:00
parent 5d968dc0e3
commit 7eaf53f7c2
22 changed files with 801 additions and 75 deletions
+47 -27
View File
@@ -4,50 +4,70 @@ import (
"context"
"fmt"
"net"
"net/url"
"strings"
"time"
"vpnclient/internal/protocols/naive"
"vpnclient/internal/config"
"vpnclient/internal/linknorm"
"vpnclient/internal/protocols/hysteria2"
)
// Result is a TCP reachability measurement to a proxy host.
type Result struct {
Name string `json:"name"`
Host string `json:"host"`
Port string `json:"port"`
Ms int64 `json:"ms"`
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
Name string `json:"name"`
Host string `json:"host"`
Port string `json:"port"`
Ms int64 `json:"ms"`
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
}
// PingProxyURI measures TCP connect time to the host in a naive share/proxy URI.
// PingProxyURI measures TCP connect time to the host in a share/proxy URI.
func PingProxyURI(ctx context.Context, name, proxyURI string) Result {
return PingProfile(ctx, name, "", proxyURI)
}
// PingProfile pings using protocol hints when available.
func PingProfile(ctx context.Context, name string, proto config.Protocol, proxyURI string) Result {
res := Result{Name: name}
if strings.TrimSpace(proxyURI) == "" {
res.Error = "нет ссылки сервера"
return res
}
normalized, err := naive.NormalizeProxyURI(proxyURI)
if err != nil {
res.Error = err.Error()
return res
}
u, err := url.Parse(normalized)
if err != nil {
res.Error = err.Error()
return res
}
host := u.Hostname()
port := u.Port()
if port == "" {
switch strings.ToLower(u.Scheme) {
case "https", "quic":
port = "443"
default:
port = "80"
var host, port string
if proto == config.ProtocolHysteria2 || hysteria2.Detect(proxyURI) {
h, p, err := hysteria2.HostPort(proxyURI)
if err != nil {
res.Error = err.Error()
return res
}
host, port = h, p
} else {
normalized, _, _, err := linknorm.Normalize(proto, proxyURI)
if err != nil {
res.Error = err.Error()
return res
}
// Parse host from normalized URI without importing net/url dance twice
rest := normalized
if i := strings.Index(rest, "://"); i >= 0 {
rest = rest[i+3:]
}
if at := strings.LastIndex(rest, "@"); at >= 0 {
rest = rest[at+1:]
}
if i := strings.IndexAny(rest, "/?#"); i >= 0 {
rest = rest[:i]
}
host = rest
port = "443"
if i := strings.LastIndex(rest, ":"); i >= 0 {
host = rest[:i]
port = rest[i+1:]
}
}
res.Host = host
res.Port = port
if host == "" {