diff options
| author | sergei <sergei@em-sysadmin.xyz> | 2026-04-14 06:23:55 +0400 |
|---|---|---|
| committer | sergei <sergei@em-sysadmin.xyz> | 2026-04-14 06:23:55 +0400 |
| commit | 3d51aa455006903345f554a2dd90034993796114 (patch) | |
| tree | 62a7be2faf047f5eb7886feebc3b815556f03d7f /internal/engine/healthcheck.go | |
| download | vpnem-main.tar.gz vpnem-main.tar.bz2 vpnem-main.zip | |
- Multi-protocol VPS nodes (VLESS-REALITY + Hysteria2 + SOCKS5)
- Smart load balancing via recommendation API
- Windows/Linux client (Go + Wails + sing-box)
- Server API with RealIP detection and connection tracking
- Auto-deployment via vpnui control plane
- Silent Windows installer with UAC elevation
- Load-based server recommendation (no sticky sessions)
- Best Server one-click connection workflow
Diffstat (limited to 'internal/engine/healthcheck.go')
| -rw-r--r-- | internal/engine/healthcheck.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/engine/healthcheck.go b/internal/engine/healthcheck.go new file mode 100644 index 0000000..a856608 --- /dev/null +++ b/internal/engine/healthcheck.go @@ -0,0 +1,63 @@ +package engine + +import ( + "io" + "net/http" + "strings" + "time" + + "vpnem/internal/config" +) + +const DefaultBlockedSiteProbeURL = "https://rutracker.org" + +func ModeRequiresExitIP(mode config.Mode) bool { + return mode.Final == "proxy" +} + +func CheckExitIP(localProxyPort int) string { + client, err := HTTPClientViaSOCKS5(config.LocalProxyHost, localProxyPort, 5*time.Second) + if err != nil { + return "" + } + resp, err := client.Get("http://ifconfig.me/ip") + if err != nil { + return "" + } + defer resp.Body.Close() + + body, err := io.ReadAll(io.LimitReader(resp.Body, 64)) + if err != nil { + return "" + } + return strings.TrimSpace(string(body)) +} + +func ProbeBlockedSite(localProxyPort int, rawURL string, timeout time.Duration) (int, error) { + client, err := HTTPClientViaSOCKS5(config.LocalProxyHost, localProxyPort, timeout) + if err != nil { + return 0, err + } + + req, err := http.NewRequest(http.MethodGet, rawURL, nil) + if err != nil { + return 0, err + } + req.Header.Set("User-Agent", "vpnem-health/1.0") + + resp, err := client.Do(req) + if err != nil { + return 0, err + } + defer resp.Body.Close() + + _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 256)) + return resp.StatusCode, nil +} + +func DeepCheckRequiresRestart(mode config.Mode, exitIP string, probeErr error) bool { + if ModeRequiresExitIP(mode) { + return exitIP == "" + } + return probeErr != nil +} |
