Documentation ¶
Overview ¶
Package testutil contains testing utilities for networking and meshnet.
Index ¶
- func NewManager(opts meshnet.Options, nodeID types.NodeID) meshnet.Manager
- func NewManagerWithDB(db storage.MeshDB, opts meshnet.Options, nodeID types.NodeID) meshnet.Manager
- func NewSystemInterface(ctx context.Context, opts *system.Options) (system.Interface, error)
- func NewWireGuardInterface(ctx context.Context, opts *wireguard.Options) (wireguard.Interface, error)
- type DNSManager
- type Firewall
- type Manager
- func (c *Manager) Close(ctx context.Context) error
- func (c *Manager) DNS() meshnet.DNSManager
- func (c *Manager) Dial(ctx context.Context, network, address string) (net.Conn, error)
- func (c *Manager) Firewall() firewall.Firewall
- func (c *Manager) InNetwork(addr netip.Addr) bool
- func (c *Manager) NetworkV4() netip.Prefix
- func (c *Manager) NetworkV6() netip.Prefix
- func (c *Manager) Peers() meshnet.PeerManager
- func (c *Manager) Start(ctx context.Context, opts meshnet.StartOptions) error
- func (c *Manager) StartMasquerade(ctx context.Context) error
- func (c *Manager) WireGuard() wireguard.Interface
- type PeerManager
- type PeerResolver
- type SystemInterface
- func (t *SystemInterface) AddRoute(_ context.Context, route netip.Prefix) error
- func (t *SystemInterface) AddressV4() netip.Prefix
- func (t *SystemInterface) AddressV6() netip.Prefix
- func (t *SystemInterface) Destroy(context.Context) error
- func (t *SystemInterface) Down(context.Context) error
- func (t *SystemInterface) HardwareAddr() (net.HardwareAddr, error)
- func (t *SystemInterface) Link() (*net.Interface, error)
- func (t *SystemInterface) Name() string
- func (t *SystemInterface) RemoveRoute(_ context.Context, route netip.Prefix) error
- func (t *SystemInterface) Up(context.Context) error
- type WireGuardInterface
- func (wg *WireGuardInterface) Close(ctx context.Context) error
- func (wg *WireGuardInterface) Configure(ctx context.Context, key crypto.PrivateKey) error
- func (wg *WireGuardInterface) DeletePeer(ctx context.Context, id string) error
- func (wg *WireGuardInterface) ListenPort() (int, error)
- func (wg *WireGuardInterface) Metrics() (*v1.InterfaceMetrics, error)
- func (wg *WireGuardInterface) Peers() map[string]wireguard.Peer
- func (wg *WireGuardInterface) PutPeer(ctx context.Context, peer *wireguard.Peer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewManager ¶
NewManager creates a new test network manager with a new in-memory database.
func NewManagerWithDB ¶
NewManagerWithDB creates a new test network manager using the given storage.
func NewSystemInterface ¶
NewSystemInterface creates a new test system interface.
Types ¶
type DNSManager ¶
type DNSManager struct {
// contains filtered or unexported fields
}
DNSManager is a mock dns manager.
func (*DNSManager) AddSearchDomains ¶ added in v0.13.8
func (d *DNSManager) AddSearchDomains(ctx context.Context, domains []string) error
AddServers adds the given dns servers to the system configuration.
func (*DNSManager) AddServers ¶
AddServers adds the given dns servers to the system configuration.
func (*DNSManager) RefreshServers ¶
func (d *DNSManager) RefreshServers(ctx context.Context) error
RefreshServers checks which peers in the database are offering DNS and updates the system configuration accordingly.
func (*DNSManager) Resolver ¶
func (d *DNSManager) Resolver() *net.Resolver
Resolver returns a net.Resolver that can be used to resolve DNS names.
type Firewall ¶
type Firewall struct{}
Firewall is a mock firewall.
func (*Firewall) AddMasquerade ¶
AddMasquerade should configure the firewall to masquerade outbound traffic on the wireguard interface.
func (*Firewall) AddWireguardForwarding ¶
AddWireguardForwarding should configure the firewall to allow forwarding traffic on the wireguard interface.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a test meshnet manager that mocks out all underlying network interfaces and system calls.
func (*Manager) DNS ¶
func (c *Manager) DNS() meshnet.DNSManager
DNS returns the DNS server manager. The DNS server manager is only available after Start has been called.
func (*Manager) Firewall ¶
Firewall returns the firewall. The firewall is only available after Start has been called.
func (*Manager) InNetwork ¶
InNetwork returns true if the given address is in the network of this interface.
func (*Manager) NetworkV4 ¶
NetworkV4 returns the current IPv4 network. The returned value may be invalid.
func (*Manager) Peers ¶
func (c *Manager) Peers() meshnet.PeerManager
Peers return the peer manager.
func (*Manager) StartMasquerade ¶
StartMasquerade ensures that masquerading is enabled.
type PeerManager ¶
type PeerManager struct {
// contains filtered or unexported fields
}
PeerManager is a mock peer manager for wireguard.
func (*PeerManager) Add ¶
func (p *PeerManager) Add(ctx context.Context, peer *v1.WireGuardPeer, iceServers []string) error
AddPeer adds a peer to the wireguard interface. IceServers is optional and provides a hint of mesh nodes that provide WebRTC signaling if required.
func (*PeerManager) Refresh ¶
func (p *PeerManager) Refresh(ctx context.Context, peers []*v1.WireGuardPeer) error
RefreshPeers walks all peers against the provided list and makes sure they are up to date.
func (*PeerManager) Resolver ¶
func (p *PeerManager) Resolver() meshnet.PeerResolver
Resolver returns a resolver backed by the storage of this instance.
type PeerResolver ¶
type PeerResolver struct{}
PeerResolver is a mock peer resolver for wireguard.
func (*PeerResolver) FeatureResolver ¶
func (p *PeerResolver) FeatureResolver(filterFn ...meshnet.PeerFilterFunc) transport.FeatureResolver
FeatureResolver returns a resolver that resolves node addresses by feature.
func (*PeerResolver) NodeIDResolver ¶
func (p *PeerResolver) NodeIDResolver() transport.NodeIDResolver
NodeIDResolver returns a resolver that resolves node addresses by node ID.
type SystemInterface ¶
SystemInterface is a test interface for use with testing. It implements system.Interface but maintains state in-memory and does not make any modifications to the system.
func (*SystemInterface) AddressV4 ¶
func (t *SystemInterface) AddressV4() netip.Prefix
AddressV4 should return the current private IPv4 address of this interface.
func (*SystemInterface) AddressV6 ¶
func (t *SystemInterface) AddressV6() netip.Prefix
AddressV6 should return the current private IPv6 address of this interface.
func (*SystemInterface) Destroy ¶
func (t *SystemInterface) Destroy(context.Context) error
Destroy destroys the interface.
func (*SystemInterface) Down ¶
func (t *SystemInterface) Down(context.Context) error
Down deactivates the interface.
func (*SystemInterface) HardwareAddr ¶
func (t *SystemInterface) HardwareAddr() (net.HardwareAddr, error)
HardwareAddr returns the hardware address of the interface.
func (*SystemInterface) Link ¶
func (t *SystemInterface) Link() (*net.Interface, error)
Link returns the underlying net.Interface.
func (*SystemInterface) Name ¶
func (t *SystemInterface) Name() string
Name returns the real name of the interface.
func (*SystemInterface) RemoveRoute ¶
RemoveRoute removes the route for the given network.
type WireGuardInterface ¶
WireGuardInterface is a test interface for use with testing. It implements wireguard.Interface but maintains state in-memory and does not make any modifications to the system.
func (*WireGuardInterface) Close ¶
func (wg *WireGuardInterface) Close(ctx context.Context) error
Close closes the wireguard interface and all client connections.
func (*WireGuardInterface) Configure ¶
func (wg *WireGuardInterface) Configure(ctx context.Context, key crypto.PrivateKey) error
Configure configures the wireguard interface to use the given key and listen port.
func (*WireGuardInterface) DeletePeer ¶
func (wg *WireGuardInterface) DeletePeer(ctx context.Context, id string) error
DeletePeer removes a peer from the wireguard configuration.
func (*WireGuardInterface) ListenPort ¶
func (wg *WireGuardInterface) ListenPort() (int, error)
ListenPort returns the current listen port of the wireguard interface.
func (*WireGuardInterface) Metrics ¶
func (wg *WireGuardInterface) Metrics() (*v1.InterfaceMetrics, error)
Metrics returns the metrics for the wireguard interface and the host.