testutil

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package testutil contains testing utilities for networking and meshnet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewManager

func NewManager(opts meshnet.Options, nodeID types.NodeID) meshnet.Manager

NewManager creates a new test network manager with a new in-memory database.

func NewManagerWithDB

func NewManagerWithDB(db storage.MeshDB, opts meshnet.Options, nodeID types.NodeID) meshnet.Manager

NewManagerWithDB creates a new test network manager using the given storage.

func NewSystemInterface

func NewSystemInterface(ctx context.Context, opts *system.Options) (system.Interface, error)

NewSystemInterface creates a new test system interface.

func NewWireGuardInterface

func NewWireGuardInterface(ctx context.Context, opts *wireguard.Options) (wireguard.Interface, error)

NewWireGuardInterface creates a new test wireguard 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

func (d *DNSManager) AddServers(ctx context.Context, servers []netip.AddrPort) error

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

func (fw *Firewall) AddMasquerade(ctx context.Context, ifaceName string) error

AddMasquerade should configure the firewall to masquerade outbound traffic on the wireguard interface.

func (*Firewall) AddWireguardForwarding

func (fw *Firewall) AddWireguardForwarding(ctx context.Context, ifaceName string) error

AddWireguardForwarding should configure the firewall to allow forwarding traffic on the wireguard interface.

func (*Firewall) Clear

func (fw *Firewall) Clear(ctx context.Context) error

Clear should clear any changes made to the firewall.

func (*Firewall) Close

func (fw *Firewall) Close(ctx context.Context) error

Close should close any resources used by the firewall. It should also perform a Clear.

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) Close

func (c *Manager) Close(ctx context.Context) error

Close closes the network manager and cleans up any resources.

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) Dial

func (c *Manager) Dial(ctx context.Context, network, address string) (net.Conn, error)

func (*Manager) Firewall

func (c *Manager) Firewall() firewall.Firewall

Firewall returns the firewall. The firewall is only available after Start has been called.

func (*Manager) InNetwork

func (c *Manager) InNetwork(addr netip.Addr) bool

InNetwork returns true if the given address is in the network of this interface.

func (*Manager) NetworkV4

func (c *Manager) NetworkV4() netip.Prefix

NetworkV4 returns the current IPv4 network. The returned value may be invalid.

func (*Manager) NetworkV6

func (c *Manager) NetworkV6() netip.Prefix

NetworkV6 returns the current IPv6 network, even if it is disabled.

func (*Manager) Peers

func (c *Manager) Peers() meshnet.PeerManager

Peers return the peer manager.

func (*Manager) Start

func (c *Manager) Start(ctx context.Context, opts meshnet.StartOptions) error

Start starts the network manager.

func (*Manager) StartMasquerade

func (c *Manager) StartMasquerade(ctx context.Context) error

StartMasquerade ensures that masquerading is enabled.

func (*Manager) WireGuard

func (c *Manager) WireGuard() wireguard.Interface

WireGuard returns the wireguard interface. The wireguard interface is only available after Start has been called.

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.

func (*PeerManager) Sync

func (p *PeerManager) Sync(ctx context.Context) error

Sync is like refresh but uses the storage to get the list of peers.

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

type SystemInterface struct {
	*system.Options
	// contains filtered or unexported fields
}

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) AddAddress added in v0.14.0

func (t *SystemInterface) AddAddress(_ context.Context, addr netip.Prefix) error

AddAddress adds an address to the interface.

func (*SystemInterface) AddRoute

func (t *SystemInterface) AddRoute(_ context.Context, route netip.Prefix) error

AddRoute adds a route for the given network.

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

Down deactivates the interface.

func (*SystemInterface) HardwareAddr

func (t *SystemInterface) HardwareAddr() (net.HardwareAddr, error)

HardwareAddr returns the hardware address of the interface.

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) RemoveAddress added in v0.14.0

func (t *SystemInterface) RemoveAddress(_ context.Context, addr netip.Prefix) error

RemoveAddress removes an address from the interface.

func (*SystemInterface) RemoveRoute

func (t *SystemInterface) RemoveRoute(_ context.Context, route netip.Prefix) error

RemoveRoute removes the route for the given network.

func (*SystemInterface) Up

Up activates the interface.

type WireGuardInterface

type WireGuardInterface struct {
	system.Interface
	// contains filtered or unexported fields
}

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.

func (*WireGuardInterface) Peers

func (wg *WireGuardInterface) Peers() map[string]wireguard.Peer

Peers returns the list of peers in the wireguard configuration.

func (*WireGuardInterface) PutPeer

func (wg *WireGuardInterface) PutPeer(ctx context.Context, peer *wireguard.Peer) error

PutPeer updates a peer in the wireguard configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL