Documentation
¶
Index ¶
- Constants
- type ControllerManager
- func (c *ControllerManager) GetAllControllers() []backendInstance
- func (c *ControllerManager) GetController(iface domain.Interface) domain.InterfaceController
- func (c *ControllerManager) GetControllerByName(backend domain.InterfaceBackend) domain.InterfaceController
- func (c *ControllerManager) GetControllerNames() []config.BackendBase
- type EventBus
- type InterfaceAndPeerDatabaseRepo
- type Manager
- func (m Manager) ApplyPeerDefaults(ctx context.Context, in *domain.Interface) error
- func (m Manager) BootstrapInterfacesFromConfig(ctx context.Context) (bool, error)
- func (m Manager) CreateDefaultPeer(ctx context.Context, userId domain.UserIdentifier) error
- func (m Manager) CreateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, error)
- func (m Manager) CreateMultiplePeers(ctx context.Context, interfaceId domain.InterfaceIdentifier, ...) ([]domain.Peer, error)
- func (m Manager) CreatePeer(ctx context.Context, peer *domain.Peer) (*domain.Peer, error)
- func (m Manager) CreateUserPeerOnInterface(ctx context.Context, userId domain.UserIdentifier, ...) (*domain.Peer, error)
- func (m Manager) DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error
- func (m Manager) DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
- func (m Manager) GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
- func (m Manager) GetAllInterfacesAndPeers(ctx context.Context) ([]domain.Interface, [][]domain.Peer, error)
- func (m Manager) GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, []domain.Peer, error)
- func (m Manager) GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
- func (m Manager) GetPeerInterfaces(ctx context.Context, userId domain.UserIdentifier) ([]domain.Interface, error)
- func (m Manager) GetPeerStats(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.PeerStatus, error)
- func (m Manager) GetUserInterfaces(ctx context.Context, _ domain.UserIdentifier) ([]domain.Interface, error)
- func (m Manager) GetUserPeerStats(ctx context.Context, id domain.UserIdentifier) ([]domain.PeerStatus, error)
- func (m Manager) GetUserPeers(ctx context.Context, id domain.UserIdentifier) ([]domain.Peer, error)
- func (m Manager) ImportNewInterfaces(ctx context.Context, filter ...domain.InterfaceIdentifier) (int, error)
- func (m Manager) PrepareInterface(ctx context.Context) (*domain.Interface, error)
- func (m Manager) PreparePeer(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Peer, error)
- func (m Manager) RestoreInterfaceState(ctx context.Context, updateDbOnError bool, ...) error
- func (m Manager) StartBackgroundJobs(ctx context.Context)
- func (m Manager) UpdateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, []domain.Peer, error)
- func (m Manager) UpdatePeer(ctx context.Context, peer *domain.Peer) (*domain.Peer, error)
- type StatisticsCollector
- type StatisticsDatabaseRepo
- type StatisticsEventBus
- type StatisticsMetricsServer
- type WgQuickController
Constants ¶
const ( DefaultMTU = 1420 DefaultPersistentKeepalive = 16 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ControllerManager ¶
type ControllerManager struct {
// contains filtered or unexported fields
}
func NewControllerManager ¶
func NewControllerManager(cfg *config.Config) (*ControllerManager, error)
func (*ControllerManager) GetAllControllers ¶
func (c *ControllerManager) GetAllControllers() []backendInstance
func (*ControllerManager) GetController ¶
func (c *ControllerManager) GetController(iface domain.Interface) domain.InterfaceController
func (*ControllerManager) GetControllerByName ¶
func (c *ControllerManager) GetControllerByName(backend domain.InterfaceBackend) domain.InterfaceController
func (*ControllerManager) GetControllerNames ¶
func (c *ControllerManager) GetControllerNames() []config.BackendBase
type InterfaceAndPeerDatabaseRepo ¶
type InterfaceAndPeerDatabaseRepo interface {
GetInterface(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, error)
GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Interface, []domain.Peer, error)
GetPeersStats(ctx context.Context, ids ...domain.PeerIdentifier) ([]domain.PeerStatus, error)
GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
GetInterfaceIps(ctx context.Context) (map[domain.InterfaceIdentifier][]domain.Cidr, error)
SaveInterface(
ctx context.Context,
id domain.InterfaceIdentifier,
updateFunc func(in *domain.Interface) (*domain.Interface, error),
) error
DeleteInterface(ctx context.Context, id domain.InterfaceIdentifier) error
GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
GetUserPeers(ctx context.Context, id domain.UserIdentifier) ([]domain.Peer, error)
SavePeer(
ctx context.Context,
id domain.PeerIdentifier,
updateFunc func(in *domain.Peer) (*domain.Peer, error),
) error
DeletePeer(ctx context.Context, id domain.PeerIdentifier) error
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
GetUsedIpsPerSubnet(ctx context.Context, subnets []domain.Cidr) (map[domain.Cidr][]domain.Cidr, error)
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewWireGuardManager ¶
func NewWireGuardManager( cfg *config.Config, bus EventBus, wg *ControllerManager, db InterfaceAndPeerDatabaseRepo, ) (*Manager, error)
func (Manager) ApplyPeerDefaults ¶
ApplyPeerDefaults applies the interface defaults to all peers of the given interface.
func (Manager) BootstrapInterfacesFromConfig ¶
BootstrapInterfacesFromConfig seeds the database with interfaces from config.Provisioning only if the database currently contains no interfaces.
It never applies changes to the host network stack; applying is handled by RestoreInterfaceState.
func (Manager) CreateDefaultPeer ¶
CreateDefaultPeer creates a default peer for the given user on all server interfaces.
func (Manager) CreateInterface ¶
func (m Manager) CreateInterface(ctx context.Context, in *domain.Interface) (*domain.Interface, error)
CreateInterface creates a new interface with the given configuration.
func (Manager) CreateMultiplePeers ¶
func (m Manager) CreateMultiplePeers( ctx context.Context, interfaceId domain.InterfaceIdentifier, r *domain.PeerCreationRequest, ) ([]domain.Peer, error)
CreateMultiplePeers creates multiple new peers for the given user identifiers. It calls PreparePeer for each user identifier in the request.
func (Manager) CreatePeer ¶
CreatePeer creates a new peer.
func (Manager) CreateUserPeerOnInterface ¶
func (m Manager) CreateUserPeerOnInterface( ctx context.Context, userId domain.UserIdentifier, interfaceId domain.InterfaceIdentifier, ) (*domain.Peer, error)
CreateUserPeerOnInterface creates a new peer for the given user on the given interface. Peer settings are derived from the interface defaults. The user is not allowed to override any settings.
func (Manager) DeleteInterface ¶
DeleteInterface deletes the given interface.
func (Manager) DeletePeer ¶
DeletePeer deletes the peer with the given identifier.
func (Manager) GetAllInterfaces ¶
GetAllInterfaces returns all interfaces that are available in the database.
func (Manager) GetAllInterfacesAndPeers ¶
func (m Manager) GetAllInterfacesAndPeers(ctx context.Context) ([]domain.Interface, [][]domain.Peer, error)
GetAllInterfacesAndPeers returns all interfaces and their peers.
func (Manager) GetInterfaceAndPeers ¶
func (m Manager) GetInterfaceAndPeers(ctx context.Context, id domain.InterfaceIdentifier) ( *domain.Interface, []domain.Peer, error, )
GetInterfaceAndPeers returns the interface and all peers for the given interface identifier.
func (Manager) GetPeerInterfaces ¶
func (m Manager) GetPeerInterfaces(ctx context.Context, userId domain.UserIdentifier) ([]domain.Interface, error)
GetPeerInterfaces returns the list of interfaces a normal user is allowed to select when creating a new peer via self-service.
func (Manager) GetPeerStats ¶
func (m Manager) GetPeerStats(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.PeerStatus, error)
GetPeerStats returns the status of the peer with the given identifier.
func (Manager) GetUserInterfaces ¶
func (m Manager) GetUserInterfaces(ctx context.Context, _ domain.UserIdentifier) ([]domain.Interface, error)
GetUserInterfaces is deprecated. Self-provisioning was removed.
func (Manager) GetUserPeerStats ¶
func (m Manager) GetUserPeerStats(ctx context.Context, id domain.UserIdentifier) ([]domain.PeerStatus, error)
GetUserPeerStats returns the status of all peers for the given user.
func (Manager) GetUserPeers ¶
GetUserPeers returns all peers for the given user.
func (Manager) ImportNewInterfaces ¶
func (m Manager) ImportNewInterfaces(ctx context.Context, filter ...domain.InterfaceIdentifier) (int, error)
ImportNewInterfaces imports all new physical interfaces that are available on the system. If a filter is set, only interfaces that match the filter will be imported.
func (Manager) PrepareInterface ¶
PrepareInterface generates a new interface with fresh keys, ip addresses and a listen port.
func (Manager) PreparePeer ¶
func (m Manager) PreparePeer(ctx context.Context, id domain.InterfaceIdentifier) (*domain.Peer, error)
PreparePeer prepares a new peer for the given interface with fresh keys and ip addresses.
func (Manager) RestoreInterfaceState ¶
func (m Manager) RestoreInterfaceState( ctx context.Context, updateDbOnError bool, filter ...domain.InterfaceIdentifier, ) error
RestoreInterfaceState restores the state of all physical interfaces and their peers. The final state of the interfaces and peers will be the same as stored in the database.
func (Manager) StartBackgroundJobs ¶
StartBackgroundJobs starts background jobs like the expired peers check. This method is non-blocking.
type StatisticsCollector ¶
type StatisticsCollector struct {
// contains filtered or unexported fields
}
func NewStatisticsCollector ¶
func NewStatisticsCollector( cfg *config.Config, bus StatisticsEventBus, db StatisticsDatabaseRepo, wg *ControllerManager, ms StatisticsMetricsServer, ) (*StatisticsCollector, error)
NewStatisticsCollector creates a new statistics collector.
func (*StatisticsCollector) StartBackgroundJobs ¶
func (c *StatisticsCollector) StartBackgroundJobs(ctx context.Context)
StartBackgroundJobs starts the background jobs for the statistics collector. This method is non-blocking and returns immediately.
type StatisticsDatabaseRepo ¶
type StatisticsDatabaseRepo interface {
GetAllInterfaces(ctx context.Context) ([]domain.Interface, error)
GetInterfacePeers(ctx context.Context, id domain.InterfaceIdentifier) ([]domain.Peer, error)
GetPeer(ctx context.Context, id domain.PeerIdentifier) (*domain.Peer, error)
UpdatePeerStatus(
ctx context.Context,
id domain.PeerIdentifier,
updateFunc func(in *domain.PeerStatus) (*domain.PeerStatus, error),
) error
UpdateInterfaceStatus(
ctx context.Context,
id domain.InterfaceIdentifier,
updateFunc func(in *domain.InterfaceStatus) (*domain.InterfaceStatus, error),
) error
DeletePeerStatus(ctx context.Context, id domain.PeerIdentifier) error
}
type StatisticsEventBus ¶
type StatisticsMetricsServer ¶
type StatisticsMetricsServer interface {
UpdateInterfaceMetrics(status domain.InterfaceStatus)
UpdatePeerMetrics(peer *domain.Peer, status domain.PeerStatus)
}
type WgQuickController ¶
type WgQuickController interface {
ExecuteInterfaceHook(ctx context.Context, id domain.InterfaceIdentifier, hookCmd string) error
SetDNS(ctx context.Context, id domain.InterfaceIdentifier, dnsStr, dnsSearchStr string) error
UnsetDNS(ctx context.Context, id domain.InterfaceIdentifier, dnsStr, dnsSearchStr string) error
}