MCPcopy Create free account
hub / github.com/PasarGuard/node / NewConfig

Function NewConfig

backend/wireguard/config.go:56–82  ·  view source on GitHub ↗

NewConfig creates a new WireGuard configuration from JSON

(config string)

Source from the content-addressed store, hash-verified

54
55// NewConfig creates a new WireGuard configuration from JSON
56func NewConfig(config string) (*Config, error) {
57 var wgConfig Config
58 err := json.Unmarshal([]byte(config), &wgConfig)
59 if err != nil {
60 return nil, fmt.Errorf("failed to unmarshal config: %w", err)
61 }
62
63 // Validate configuration
64 if wgConfig.InterfaceName == "" {
65 wgConfig.InterfaceName = "wg0"
66 }
67
68 if wgConfig.ListenPort <= 0 {
69 wgConfig.ListenPort = 51820
70 }
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 }
80
81 return &wgConfig, nil
82}
83
84// InterfaceNetworks returns CIDR prefixes parsed from the node's core `address` list.
85// Used to restrict peer AllowedIPs to subnets this interface actually serves.

Calls

no outgoing calls