Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureSingBoxBinary() (string, error)
- func FormatBytes(b int64) string
- func FormatSpeed(bytesPerSec int64) string
- func VerifyNodeReal(ctx context.Context, node *model.ProxyNode, testURL string, ...) (time.Duration, error)
- type Engine
- type SingBoxConfig
- type SystemProxyController
- type TrafficStats
- type Watchdog
Constants ¶
const VerifyPortBase = 29000
VerifyPortBase is the start of the scratch port range used only by short-lived VerifyNodeReal processes. Deliberately distinct from the user's configured ports so verification never collides with an already-running session. Callers running N verifications concurrently should pass ports spaced apart within this range (see app.verifyRealConnectivity).
Variables ¶
var IranDirectDomains = []string{
"domain:.ir",
"domain:.xn--mgba3a4f16a",
"geosite:ir",
"geosite:category-ir",
"geosite:category-ir-gov",
"geosite:category-ir-bank",
"geosite:category-ir-shopping",
"geosite:category-ir-education",
"geosite:category-ir-news",
"geosite:category-ir-media",
"geosite:category-ir-tech",
"domain:shaparak.ir",
"domain:divar.ir",
"domain:snapp.ir",
"domain:digikala.com",
"domain:torob.com",
"domain:aparat.com",
"domain:telewebion.com",
"domain:varzesh3.com",
"domain:filimo.com",
"domain:cafebazaar.ir",
"domain:myket.ir",
"domain:rubika.ir",
"domain:eitaa.com",
"domain:bale.ai",
"domain:splus.ir",
"domain:nobitex.ir",
"domain:wallex.ir",
"domain:abantether.com",
"domain:mci.ir",
"domain:irancell.ir",
"domain:rightel.ir",
"domain:tci.ir",
"domain:shatel.ir",
"domain:asiatech.ir",
"domain:parsonline.com",
"domain:hiweb.ir",
}
IranDirectDomains contains prominent Iranian domain suffixes and key domestic infrastructure domains
var IranDirectIPRanges = []string{
"geoip:ir",
"geoip:private",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
"127.0.0.0/8",
"100.64.0.0/10",
"169.254.0.0/16",
"::1/128",
"fc00::/7",
"fe80::/10",
}
IranDirectIPRanges contains private LAN ranges and Iran GeoIP
Functions ¶
func EnsureSingBoxBinary ¶
EnsureSingBoxBinary finds sing-box or automatically downloads it into ~/.vify/bin/sing-box
func FormatBytes ¶
FormatBytes formats byte counts into human-readable strings (KB, MB, GB)
func FormatSpeed ¶
FormatSpeed formats speed bytes/sec into human-readable string
func VerifyNodeReal ¶
func VerifyNodeReal(ctx context.Context, node *model.ProxyNode, testURL string, socksPort, httpPort int) (time.Duration, error)
VerifyNodeReal confirms a candidate node's proxy protocol actually works, not just that its TCP port is open. The initial benchmark (ping.DialTest) only dials a raw socket and, for TLS nodes, completes a generic TLS handshake with certificate verification disabled — that passes for any listening port, or any server willing to complete a TLS handshake, regardless of whether a real VLESS/VMess/Trojan/Shadowsocks proxy is actually behind it. This instead starts a short-lived, real sing-box process for the node and performs one genuine HTTP request through it. socksPort/httpPort must be unique per concurrently-running call.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine orchestrates the VPN / Proxy connection, sing-box runner, TUN and System Proxy modes
func (*Engine) FailoverToNext ¶
func (e *Engine) FailoverToNext()
FailoverToNext seamlessly switches outbound node to the next available healthy node
func (*Engine) GetCurrentNode ¶
GetCurrentNode returns currently connected node
func (*Engine) GetStats ¶
func (e *Engine) GetStats() *TrafficStats
GetStats returns current traffic statistics
type SingBoxConfig ¶
type SingBoxConfig struct {
Log map[string]interface{} `json:"log"`
DNS map[string]interface{} `json:"dns"`
Inbounds []map[string]interface{} `json:"inbounds"`
Outbounds []map[string]interface{} `json:"outbounds"`
Route map[string]interface{} `json:"route"`
Experimental map[string]interface{} `json:"experimental,omitempty"`
}
SingBoxConfig generates valid sing-box JSON configuration for TUN or System Proxy modes
func GenerateConfig ¶
func GenerateConfig(node *model.ProxyNode, mode model.ConnectionMode, socksPort, httpPort, clashAPIPort int, bypassIran bool) (*SingBoxConfig, error)
GenerateConfig generates a complete sing-box configuration struct. clashAPIPort enables sing-box's Clash-compatible API (used to read live traffic totals) on 127.0.0.1:clashAPIPort; pass 0 to omit it entirely — callers spinning up multiple concurrent short-lived instances (e.g. real connectivity verification) that don't need traffic stats MUST pass 0, since every instance would otherwise fight over the same hardcoded port and fail to start.
func (*SingBoxConfig) ToJSON ¶
func (c *SingBoxConfig) ToJSON() ([]byte, error)
ToJSON serializes SingBoxConfig to formatted JSON
type SystemProxyController ¶
type SystemProxyController struct {
// contains filtered or unexported fields
}
SystemProxyController manages enabling and disabling OS system proxy
func NewSystemProxyController ¶
func NewSystemProxyController(httpPort, socksPort int) *SystemProxyController
NewSystemProxyController creates a new controller
func (*SystemProxyController) Disable ¶
func (s *SystemProxyController) Disable() error
Disable turns off system proxy settings and restores original state
func (*SystemProxyController) Enable ¶
func (s *SystemProxyController) Enable() error
Enable sets the system proxy for the current OS
type TrafficStats ¶
type TrafficStats struct {
BytesUpload int64
BytesDownload int64
UploadSpeed int64 // bytes per second
DownloadSpeed int64 // bytes per second
// contains filtered or unexported fields
}
TrafficStats tracks bandwidth and upload/download rates
func NewTrafficStats ¶
func NewTrafficStats() *TrafficStats
NewTrafficStats initializes a new traffic monitor
func (*TrafficStats) AddDownload ¶
func (s *TrafficStats) AddDownload(n int64)
AddDownload records downloaded bytes
func (*TrafficStats) AddUpload ¶
func (s *TrafficStats) AddUpload(n int64)
AddUpload records uploaded bytes
func (*TrafficStats) SetTotals ¶
func (s *TrafficStats) SetTotals(download, upload int64)
SetTotals overwrites cumulative byte counters with absolute totals reported by an external source (e.g. sing-box's Clash API).
func (*TrafficStats) Snapshot ¶
func (s *TrafficStats) Snapshot() (uploadTotal, downloadTotal, upSpeed, downSpeed int64)
Snapshot returns a copy of current metrics
func (*TrafficStats) Tick ¶
func (s *TrafficStats) Tick()
Tick calculates current speed rates (should be called once per second)
type Watchdog ¶
type Watchdog struct {
Interval time.Duration
TestURL string
ProxyURL string
FailThreshold int
OnFailover func(reason string)
OnHealthUpdate func(latency time.Duration, ok bool)
// contains filtered or unexported fields
}
Watchdog monitors the active proxy connection and triggers failover when disconnected
func NewWatchdog ¶
NewWatchdog creates a new connection Watchdog