meshnet

package
v0.15.13 Latest Latest
Warning

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

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

Documentation

Overview

Package meshnet provides the core networking functionality for WebMesh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterGraph added in v0.9.0

func FilterGraph(ctx context.Context, db storage.MeshDB, thisNodeID types.NodeID) (types.AdjacencyMap, error)

FilterGraph filters the adjacency map in the given graph for the given node name according to the current network ACLs. If the ACL list is nil, an empty adjacency map is returned. An error is returned on faiure building the initial map or any database error. This implementation needs improvement to be more efficient and to allow edges so long as one of the routes encountered is allowed. Currently if a single route provided by a destination node is not allowed, the entire node is filtered out.

func WireGuardPeersFor added in v0.9.0

func WireGuardPeersFor(ctx context.Context, st storage.MeshDB, peerID types.NodeID) ([]*v1.WireGuardPeer, error)

WireGuardPeersFor returns the WireGuard peers for the given peer ID. Peers are filtered by network ACLs.

Types

type DNSManager

type DNSManager interface {
	// Resolver returns a net.Resolver that can be used to resolve DNS names.
	Resolver() *net.Resolver
	// AddServers adds the given dns servers to the system configuration.
	AddServers(ctx context.Context, servers []netip.AddrPort) error
	// AddSearchDomains adds the given search domains to the system configuration.
	AddSearchDomains(ctx context.Context, domains []string) error
	// RefreshServers checks which peers in the database are offering DNS
	// and updates the system configuration accordingly.
	RefreshServers(ctx context.Context) error
}

DNSManager is an interface for managing DNS nameservers on the local system.

type GraphWalk added in v0.11.3

type GraphWalk struct {
	Graph        types.PeerGraph
	Networking   networking.Networking
	AdjacencyMap types.AdjacencyMap
	SourceNode   types.NodeID
	TargetNode   *types.MeshNode
	AllowedIPs   []string
	LocalRoutes  []netip.Prefix
	Routes       []Route
	Visited      map[types.NodeID]struct{}
	Depth        int
}

GraphWalk is the structure used to recursively walk the graph and build the adjacency map.

func (*GraphWalk) SkipNode added in v0.11.3

func (g *GraphWalk) SkipNode(id types.NodeID) bool

SkipNode reports if the given node ID should be skipped.

type Manager

type Manager interface {
	transport.Dialer

	// Start starts the network manager.
	Start(ctx context.Context, opts StartOptions) error
	// InNetwork returns true if the given address is in the network of this interface.
	InNetwork(addr netip.Addr) bool
	// NetworkV4 returns the current IPv4 network. The returned value may be invalid.
	NetworkV4() netip.Prefix
	// NetworkV6 returns the current IPv6 network, even if it is disabled.
	NetworkV6() netip.Prefix
	// StartMasquerade ensures that masquerading is enabled.
	StartMasquerade(ctx context.Context) error
	// DNS returns the DNS server manager. The DNS server manager is only
	// available after Start has been called.
	DNS() DNSManager
	// Peers return the peer manager.
	Peers() PeerManager
	// Firewall returns the firewall.
	// The firewall is only available after Start has been called.
	Firewall() firewall.Firewall
	// WireGuard returns the wireguard interface.
	// The wireguard interface is only available after Start has been called.
	WireGuard() wireguard.Interface
	// Close closes the network manager and cleans up any resources.
	Close(ctx context.Context) error
}

Manager is the interface for managing the network.

func New

func New(store storage.MeshDB, opts Options, nodeID types.NodeID) Manager

New creates a new network manager.

type Options

type Options struct {
	// NetNs is the network namespace to use for the wireguard interface.
	// This is only used on Linux.
	NetNs string
	// InterfaceName is the name of the wireguard interface.
	InterfaceName string
	// ForceReplace is whether to force replace the wireguard interface.
	ForceReplace bool
	// ListenPort is the port to use for wireguard.
	ListenPort int
	// Modprobe is whether to attempt to load the wireguard kernel module.
	Modprobe bool
	// PersistentKeepAlive is the persistent keepalive to use for wireguard.
	PersistentKeepAlive time.Duration
	// ForceTUN is whether to force the use of TUN.
	ForceTUN bool
	// MTU is the MTU to use for the wireguard interface.
	MTU int
	// RecordMetrics is whether to enable metrics recording.
	RecordMetrics bool
	// RecordMetricsInterval is the interval to use for recording metrics.
	RecordMetricsInterval time.Duration
	// StoragePort is the port being used for the storage provider.
	StoragePort int
	// GRPCPort is the port being used for gRPC.
	GRPCPort int
	// ZoneAwarenessID is the zone awareness ID.
	ZoneAwarenessID string
	// Credentials are the dial options to use when calling peer nodes.
	Credentials []grpc.DialOption
	// LocalDNSAddr is a local network address service MeshDNS.
	LocalDNSAddr netip.AddrPort
	// DisableIPv4 disables IPv4 on the interface.
	DisableIPv4 bool
	// DisableIPv6 disables IPv6 on the interface.
	DisableIPv6 bool
	// DisableFullTunnel will ignore routes for a default gateway.
	DisableFullTunnel bool
	// IgnoreRoutes are additional routes to ignore.
	IgnoreRoutes []netip.Prefix
	// Relays are options for when presented with the need to negotiate
	// p2p data channels.
	Relays RelayOptions
}

Options are the options for the network manager.

func (*Options) MarshalJSON added in v0.11.2

func (o *Options) MarshalJSON() ([]byte, error)

type PeerFilterFunc added in v0.9.0

type PeerFilterFunc func(types.MeshNode) bool

PeerFilterFunc is a function that can be used to filter responses returned by a resolver.

type PeerManager

type PeerManager interface {
	// AddPeer adds a peer to the wireguard interface. IceServers is optional
	// and provides a hint of mesh nodes that provide WebRTC signaling if
	// required.
	Add(ctx context.Context, peer *v1.WireGuardPeer, iceServers []string) error
	// RefreshPeers walks all peers against the provided list and makes sure
	// they are up to date.
	Refresh(ctx context.Context, peers []*v1.WireGuardPeer) error
	// Sync is like refresh but uses the storage to get the list of peers.
	Sync(ctx context.Context) error
	// Resolver returns a resolver backed by the storage
	// of this instance.
	Resolver() PeerResolver
}

PeerManager is the interface for tracking and managing WireGuard peers.

type PeerResolver added in v0.9.0

type PeerResolver interface {
	// NodeIDResolver returns a resolver that resolves node addresses by node ID.
	NodeIDResolver() transport.NodeIDResolver
	// FeatureResolver returns a resolver that resolves node addresses by feature.
	FeatureResolver(filterFn ...PeerFilterFunc) transport.FeatureResolver
}

PeerResolver provides facilities for creating various transport.Resolver instances.

func NewResolver added in v0.9.0

func NewResolver(st storage.MeshDB) PeerResolver

NewResolver returns a new Resolver instance.

type RelayOptions

type RelayOptions struct {
	// Host are the options for a libp2p host.
	Host libp2p.HostOptions
}

RelayOptions are options for when presented with the need to negotiate p2p wireguard connections. Empty values mean to use the defaults.

type Route added in v0.11.3

type Route struct {
	CIDR  netip.Prefix
	Depth int
}

Route tracks a route and the depth into the graph of the route. Smallest depth wins in the end.

type StartOptions

type StartOptions struct {
	// Key is the wireguard key to use for the node.
	Key crypto.PrivateKey
	// AddressV4 is the IPv4 address to use for the node.
	AddressV4 netip.Prefix
	// AddressV6 is the IPv6 address to use for the node.
	AddressV6 netip.Prefix
	// NetworkV4 is the IPv4 network to use for the node.
	NetworkV4 netip.Prefix
	// NetworkV6 is the IPv6 network to use for the node.
	NetworkV6 netip.Prefix
}

StartOptions are the options for starting the network manager and configuring the wireguard interface.

type WalkedPeer added in v0.11.3

type WalkedPeer struct {
	*v1.WireGuardPeer
	Routes []Route
}

WalkedPeer is a peer that has been walked. We track routes separately so we can do a final iteration to determine the smallest depth for each route.

Directories

Path Synopsis
Package nat64 provides a stateless bi-directional NAT64 implementation.
Package nat64 provides a stateless bi-directional NAT64 implementation.
package netutil provides common utility functions for networking.
package netutil provides common utility functions for networking.
Package relay holds low-level primitives for proxying streams to a WireGuard interface.
Package relay holds low-level primitives for proxying streams to a WireGuard interface.
Package system contains utilities for managing network interfaces on the system.
Package system contains utilities for managing network interfaces on the system.
buffers
Package buffers contains facilities for changing system buffer sizes.
Package buffers contains facilities for changing system buffer sizes.
dns
Package dns contains utility functions for DNS.
Package dns contains utility functions for DNS.
firewall
Package firewall contains an interface for interacting with the system firewall.
Package firewall contains an interface for interacting with the system firewall.
Package testutil contains testing utilities for networking and meshnet.
Package testutil contains testing utilities for networking and meshnet.
Package transport defines the interfaces needed for various mesh operations.
Package transport defines the interfaces needed for various mesh operations.
datachannels
Package datachannels provides a WebRTC data channel API for port forwarding.
Package datachannels provides a WebRTC data channel API for port forwarding.
libp2p
Package libp2p provides webmesh integration with libp2p.
Package libp2p provides webmesh integration with libp2p.
libp2p/embedded/protocol
Package protocol defines the libp2p webmesh protocol.
Package protocol defines the libp2p webmesh protocol.
libp2p/embedded/transport
Package transport defines the libp2p webmesh transport.
Package transport defines the libp2p webmesh transport.
libp2p/embedded/util
Package util provides utility functions for the webmesh libp2p integrations.
Package util provides utility functions for the webmesh libp2p integrations.
libp2p/embedded/wgtransport
Package wgtransport implements a Webmesh WireGuard transport for libp2p.
Package wgtransport implements a Webmesh WireGuard transport for libp2p.
tcp
Package tcp provides TCP based transports.
Package tcp provides TCP based transports.
webrtc
Package webrtc contains transports for WebRTC.
Package webrtc contains transports for WebRTC.
Package wireguard contains utilities for working with wireguard interfaces.
Package wireguard contains utilities for working with wireguard interfaces.

Jump to

Keyboard shortcuts

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