@@ -13,11 +13,12 @@ import (
1313
1414// Config represents the WireGuard configuration
1515type Config struct {
16- InterfaceName string `json:"interface_name"`
17- PrivateKey string `json:"private_key"`
18- PreSharedKey string `json:"pre_shared_key,omitempty"`
19- ListenPort int `json:"listen_port"`
20- Address []string `json:"address"`
16+ InterfaceName string `json:"interface_name"`
17+ PrivateKey string `json:"private_key"`
18+ PreSharedKey string `json:"pre_shared_key,omitempty"`
19+ ListenPort int `json:"listen_port"`
20+ Address []string `json:"address"`
21+ Latency * LatencyConfig `json:"latency,omitempty"`
2122
2223 privateKeyValue wgtypes.Key
2324 privateKeySet bool
@@ -27,6 +28,11 @@ type Config struct {
2728 mu sync.RWMutex
2829}
2930
31+ type LatencyConfig struct {
32+ TestURL string `json:"test_url,omitempty"`
33+ TimeoutSeconds int `json:"timeout_seconds,omitempty"`
34+ }
35+
3036// PeerInfo stores information about a WireGuard peer
3137type PeerInfo struct {
3238 Email string `json:"email"`
@@ -62,6 +68,15 @@ func NewConfig(config string) (*Config, error) {
6268 if wgConfig .ListenPort <= 0 {
6369 wgConfig .ListenPort = 51820
6470 }
71+ if wgConfig .Latency == nil {
72+ wgConfig .Latency = & LatencyConfig {}
73+ }
74+ if strings .TrimSpace (wgConfig .Latency .TestURL ) == "" {
75+ wgConfig .Latency .TestURL = "https://www.gstatic.com/generate_204"
76+ }
77+ if wgConfig .Latency .TimeoutSeconds <= 0 {
78+ wgConfig .Latency .TimeoutSeconds = 5
79+ }
6580
6681 return & wgConfig , nil
6782}
0 commit comments