networker

package
v0.0.0-...-851e5e8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package networker abstracts network configuration from the rest of the system.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMeshNotActive to report to outside
	ErrMeshNotActive = errors.New("mesh is not active")
	// ErrMeshPeerIsNotRoutable to report to outside
	ErrMeshPeerIsNotRoutable = errors.New("mesh peer is not routable")
	// ErrMeshPeerNotFound to report to outside
	ErrMeshPeerNotFound = errors.New("mesh peer not found")
)

Functions

This section is empty.

Types

type Combined

type Combined struct {
	// contains filtered or unexported fields
}

Combined configures networking for VPN connections.

It is implemented in such a way, that all public methods use sync.Mutex and all private ones don't.

func NewCombined

func NewCombined(
	vpnet vpn.VPN,
	mesh meshnet.Mesh,
	gateway routes.GatewayRetriever,
	publisher events.Publisher[string],
	allowlistRouter routes.Service,
	dnsSetter dns.Setter,
	ipv6 ipv6.Blocker,
	fw firewall.Service,
	allowlist allowlist.Routing,
	devices device.ListFunc,
	policyRouter routes.PolicyService,
	dnsHostSetter dns.HostnameSetter,
	router routes.Service,
	peerRouter routes.Service,
	exitNode exitnode.Node,
	fwmark uint32,
	lanDiscovery bool,
) *Combined

NewCombined returns a ready made version of Combined.

func (*Combined) AllowFileshare

func (netw *Combined) AllowFileshare(uniqueAddress meshnet.UniqueAddress) error

func (*Combined) AllowIncoming

func (netw *Combined) AllowIncoming(uniqueAddress meshnet.UniqueAddress, lanAllowed bool) error

AllowIncoming traffic from the uniqueAddress.

func (*Combined) BlockFileshare

func (netw *Combined) BlockFileshare(uniqueAddress meshnet.UniqueAddress) error

func (*Combined) BlockIncoming

func (netw *Combined) BlockIncoming(uniqueAddress meshnet.UniqueAddress) error

Unblock address.

func (*Combined) ConnectionStatus

func (netw *Combined) ConnectionStatus() (ConnectionStatus, error)

ConnectionStatus get connection information

func (*Combined) DenyIPv6

func (netw *Combined) DenyIPv6() error

func (*Combined) DisableFirewall

func (netw *Combined) DisableFirewall() error

DisableFirewall turns all firewall operations to noop.

func (*Combined) DisableRouting

func (netw *Combined) DisableRouting()

func (*Combined) EnableFirewall

func (netw *Combined) EnableFirewall() error

EnableFirewall activates the firewall and applies the rules according to the user's settings. (killswitch, allowlist)

func (*Combined) EnableRouting

func (netw *Combined) EnableRouting()

func (*Combined) IsMeshnetActive

func (netw *Combined) IsMeshnetActive() bool

IsMeshnetActive returns true when meshnet was activated. Otherwise false is returned.

Thread safe.

func (*Combined) IsNetworkSet

func (netw *Combined) IsNetworkSet() bool

func (*Combined) IsVPNActive

func (netw *Combined) IsVPNActive() bool

IsVPNActive returns true when connection to VPN server is established. Otherwise false is returned.

Thread safe.

func (*Combined) LastServerName

func (netw *Combined) LastServerName() string

LastServerName returns last used server hostname

func (*Combined) PermitIPv6

func (netw *Combined) PermitIPv6() error

func (*Combined) Reconnect

func (c *Combined) Reconnect(stateIsUp bool)

Reconnect refresh connectivity on network state change

func (*Combined) Refresh

func (netw *Combined) Refresh(c mesh.MachineMap) error

Refresh peer list.

func (*Combined) ResetRouting

func (netw *Combined) ResetRouting(peer mesh.MachinePeer, peers mesh.MachinePeers) error

func (*Combined) SetAllowlist

func (netw *Combined) SetAllowlist(allowlist config.Allowlist) error

func (*Combined) SetDNS

func (netw *Combined) SetDNS(nameservers []string) error

SetDNS to the given nameservers.

func (*Combined) SetKillSwitch

func (netw *Combined) SetKillSwitch(allowlist config.Allowlist) error

func (*Combined) SetLanDiscovery

func (netw *Combined) SetLanDiscovery(enabled bool)

func (*Combined) SetMesh

func (netw *Combined) SetMesh(
	cfg mesh.MachineMap,
	self netip.Addr,
	privateKey string,
) (err error)

func (*Combined) SetVPN

func (netw *Combined) SetVPN(v vpn.VPN)

func (*Combined) Start

func (netw *Combined) Start(
	creds vpn.Credentials,
	serverData vpn.ServerData,
	allowlist config.Allowlist,
	nameservers config.DNS,
	enableLocalTraffic bool,
) (err error)

Start VPN connection after preparing the network.

func (*Combined) StatusMap

func (netw *Combined) StatusMap() (map[string]string, error)

func (*Combined) Stop

func (netw *Combined) Stop() error

Stop VPN connection and clean up network after it stopped.

func (*Combined) UnSetMesh

func (netw *Combined) UnSetMesh() error

func (*Combined) UnsetDNS

func (netw *Combined) UnsetDNS() error

UnsetDNS to original settings.

func (*Combined) UnsetKillSwitch

func (netw *Combined) UnsetKillSwitch() error

type ConnectionStatus

type ConnectionStatus struct {
	// State of the vpn. OpenVPN specific.
	State vpn.State
	// Technology, which may or may not match what's in the config
	Technology config.Technology
	// Protocol, which may or may not match what's in the config
	Protocol config.Protocol
	// IP of the other end of the connection
	IP netip.Addr
	// Hostname of the other end of the connection
	Hostname string
	// Country of the other end of the connection
	Country string
	// City of the other end of the connection
	City string
	// Download is the amount of data received through the connection
	Download uint64
	// Upload is the amount of data sent through the connection
	Upload uint64
	// Uptime since the connection start
	Uptime *time.Duration
}

ConnectionStatus of a currently active connection

type Networker

type Networker interface {
	Start(
		vpn.Credentials,
		vpn.ServerData,
		config.Allowlist,
		config.DNS,
		bool,
	) error
	Stop() error      // stop vpn
	UnSetMesh() error // stop meshnet
	SetDNS(nameservers []string) error
	UnsetDNS() error
	IsVPNActive() bool
	IsMeshnetActive() bool
	ConnectionStatus() (ConnectionStatus, error)
	EnableFirewall() error
	DisableFirewall() error
	EnableRouting()
	DisableRouting()
	SetAllowlist(allowlist config.Allowlist) error
	IsNetworkSet() bool
	SetKillSwitch(config.Allowlist) error
	UnsetKillSwitch() error
	PermitIPv6() error
	DenyIPv6() error
	SetVPN(vpn.VPN)
	LastServerName() string
	SetLanDiscovery(bool)
}

Networker configures networking for connections.

At the moment interface is designed to support only VPN connections.

Jump to

Keyboard shortcuts

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