Documentation
¶
Index ¶
- func GenerateKeyPair() (privateKey, publicKey string, err error)
- type Config
- type DesiredPeer
- type LatencyConfig
- type Manager
- func (m *Manager) ApplyConfig(config wgtypes.Config) error
- func (m *Manager) ApplyPeers(peers []wgtypes.PeerConfig) error
- func (m *Manager) ApplyPeersReplaceAll(peers []wgtypes.PeerConfig) error
- func (m *Manager) Close() error
- func (m *Manager) GetDevice() (*wgtypes.Device, error)
- func (m *Manager) GetInterfaceStats() (rxBytes, txBytes int64, err error)
- func (m *Manager) InitializeWithPeers(privateKey wgtypes.Key, listenPort int, serverIPs []string, ...) error
- type PeerInfo
- type PeerStore
- func (ps *PeerStore) ApplyChanges(removeKeys []string, upsertPeers []*PeerInfo) []string
- func (ps *PeerStore) GetAll() []*PeerInfo
- func (ps *PeerStore) GetByEmail(email string) *PeerInfo
- func (ps *PeerStore) GetByKey(publicKey string) *PeerInfo
- func (ps *PeerStore) GetEmailMap() map[string]string
- func (ps *PeerStore) Init(peers []*PeerInfo)
- func (ps *PeerStore) ReplaceAll(peers []*PeerInfo) []string
- type SyncDiff
- type WireGuard
- func (wg *WireGuard) GetOutboundsLatency(ctx context.Context, request *common.LatencyRequest) (*common.LatencyResponse, error)
- func (wg *WireGuard) GetStats(ctx context.Context, request *common.StatRequest) (*common.StatResponse, error)
- func (wg *WireGuard) GetSysStats(ctx context.Context) (*common.BackendStatsResponse, error)
- func (wg *WireGuard) GetUserOnlineIpListStats(ctx context.Context, email string) (*common.StatsOnlineIpListResponse, error)
- func (wg *WireGuard) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error)
- func (wg *WireGuard) Logs() <-chan string
- func (wg *WireGuard) Restart() error
- func (wg *WireGuard) Shutdown()
- func (wg *WireGuard) Started() bool
- func (wg *WireGuard) SyncUser(_ context.Context, user *common.User) error
- func (wg *WireGuard) SyncUsers(_ context.Context, users []*common.User) error
- func (wg *WireGuard) UpdateUsers(_ context.Context, users []*common.User) error
- func (wg *WireGuard) UpdateUsersAndRestart(_ context.Context, users []*common.User) error
- func (wg *WireGuard) Version() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateKeyPair ¶
GenerateKeyPair generates a new WireGuard key pair
Types ¶
type Config ¶
type Config struct {
InterfaceName string `json:"interface_name"`
PrivateKey string `json:"private_key"`
ListenPort int `json:"listen_port"`
Address []string `json:"address"`
Latency *LatencyConfig `json:"latency,omitempty"`
// contains filtered or unexported fields
}
Config represents the WireGuard configuration
func (*Config) GetPreSharedKey ¶
GetPreSharedKey parses and caches the pre-shared key, optionally returning nil if not set.
func (*Config) GetPrivateKey ¶
GetPrivateKey returns the parsed WireGuard private key. The parsed key is stored in memory and reused after first successful parse.
func (*Config) InterfaceNetworks ¶ added in v0.3.1
InterfaceNetworks returns CIDR prefixes parsed from the node's core `address` list. Used to restrict peer AllowedIPs to subnets this interface actually serves.
type DesiredPeer ¶
type LatencyConfig ¶ added in v0.4.1
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles WireGuard interface management using wgctrl
func NewManager ¶
NewManager creates a new WireGuard manager
func (*Manager) ApplyConfig ¶
ApplyConfig safely configures the device with the given configuration under lock.
func (*Manager) ApplyPeers ¶
func (m *Manager) ApplyPeers(peers []wgtypes.PeerConfig) error
ApplyPeers applies a batch of peer configurations in a single kernel call.
func (*Manager) ApplyPeersReplaceAll ¶
func (m *Manager) ApplyPeersReplaceAll(peers []wgtypes.PeerConfig) error
ApplyPeersReplaceAll applies peers as an authoritative full snapshot in a single kernel call.
func (*Manager) GetInterfaceStats ¶
GetInterfaceStats returns RX/TX statistics for the interface
func (*Manager) InitializeWithPeers ¶
func (m *Manager) InitializeWithPeers(privateKey wgtypes.Key, listenPort int, serverIPs []string, peers []wgtypes.PeerConfig) error
InitializeWithPeers sets up the WireGuard interface with initial configuration and optional full peer snapshot.
type PeerInfo ¶
type PeerInfo struct {
Email string `json:"email"`
PublicKey wgtypes.Key `json:"public_key"`
AllowedIPs []net.IPNet `json:"allowed_ips"`
}
PeerInfo stores information about a WireGuard peer
type PeerStore ¶
type PeerStore struct {
// contains filtered or unexported fields
}
PeerStore manages the runtime state of WireGuard peers. It enforces a 1:1 mapping between User (Email) and WireGuard Public Key.
func (*PeerStore) ApplyChanges ¶
ApplyChanges commits removals and upserts in one lock scope. It returns the keys actually removed from the store.
func (*PeerStore) GetByEmail ¶
GetByEmail returns the peer for a given email if it exists.
func (*PeerStore) GetEmailMap ¶
GetEmailMap returns a completely decoupled, point-in-time map of publicKey -> email. Replaces the over-engineered emailByKeySnapshotCache.
func (*PeerStore) Init ¶
Init bulk initializes the peer store. Should ONLY be used during startup when the store is known to be empty.
func (*PeerStore) ReplaceAll ¶
ReplaceAll completely replaces the peer store contents with the given peers. It returns a list of public keys that were removed in the process.
type WireGuard ¶
type WireGuard struct {
// contains filtered or unexported fields
}
WireGuard locking hierarchy — must always be acquired in this order:
wg.syncMu serialises all peer sync/remove operations wg.mu guards lifecycle state (manager, state, config, version) m.mu guards Manager internals (client, configure, nl)
Never acquire an outer lock while holding an inner one.
func (*WireGuard) GetOutboundsLatency ¶ added in v0.4.1
func (wg *WireGuard) GetOutboundsLatency(ctx context.Context, request *common.LatencyRequest) (*common.LatencyResponse, error)
func (*WireGuard) GetStats ¶
func (wg *WireGuard) GetStats(ctx context.Context, request *common.StatRequest) (*common.StatResponse, error)
func (*WireGuard) GetSysStats ¶
GetSysStats returns system stats for the WireGuard backend
func (*WireGuard) GetUserOnlineIpListStats ¶
func (*WireGuard) GetUserOnlineStats ¶
func (*WireGuard) Logs ¶
Logs returns the log channel as a receive-only channel. The channel is closed when Shutdown is called; callers should use range so they naturally stop reading once it is closed.
func (*WireGuard) Restart ¶
Restart applies a new configuration dynamically to the WireGuard interface without tearing it down.
func (*WireGuard) SyncUser ¶
SyncUser synchronizes a single user to the WireGuard interface. Each user has a single key/IP pair (/32 for IPv4, /128 for IPv6).
func (*WireGuard) UpdateUsers ¶
UpdateUsers performs partial reconciliation for users provided in the request.
func (*WireGuard) UpdateUsersAndRestart ¶
UpdateUsersAndRestart applies targeted user updates, then rebuilds the full peer snapshot so interface-wide settings like keepalive are reapplied to all peers.