meshnet

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: 25 Imported by: 0

Documentation

Overview

Package mesh provides data types and interfaces for implementing peer to peer communication.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTunnelClosed while enabling meshnet.
	ErrTunnelClosed = errors.New("tunnel was closed")
	// MsgMeshnetInviteSendSameAccountEmail is a string used to identify same account error
	// returned when invite destination address is the same as sender email address
	MsgMeshnetInviteSendSameAccountEmail = "Bad Request: Email should belong to a different user"
)
View Source
var (
	ErrNotLoggedIn         = fmt.Errorf("not logged in")
	ErrConfigLoad          = fmt.Errorf("problem loading config")
	ErrMeshnetNotEnabled   = fmt.Errorf("meshnet not enabled")
	ErrDeviceNotRegistered = fmt.Errorf("not registered")
)

Functions

func JobRefreshMeshnet

func JobRefreshMeshnet(s *Server) func() error

func MakePeerMaps

func MakePeerMaps(peers *pb.PeerList) (map[string]*pb.Peer, map[string]*pb.Peer)

Types

type Checker

type Checker interface {
	// IsRegistrationInfoCorrect returns true when device has been registered to meshnet.
	IsRegistrationInfoCorrect() bool
	// Register the device
	Register() error
}

Checker provides information about meshnet.

type Events

type Events struct {
	PeerUpdate  events.PublishSubcriber[[]string]
	SelfRemoved events.PublishSubcriber[any]
}

Events allow for publishing and subscribing to meshnet related notifications

func NewEvents

func NewEvents(
	peerUpdate events.PublishSubcriber[[]string],
	selfRemoved events.PublishSubcriber[any],
) *Events

func (*Events) Subscribe

func (e *Events) Subscribe(to Publisher)

Subscribe to PeerUpdated and SelfRemoved notifications

type KeyGenerator

type KeyGenerator interface {
	// Private returns base64 encoded private key
	Private() string
	// Public expects base64 encoded private key and returns base64 encoded public key
	Public(string) string
}

KeyGenerator for use in meshnet.

type Mesh

type Mesh interface {
	// Enable creates a tunnel interface with a given IP.
	Enable(netip.Addr, string) error
	// Disable removes a tunnel interface
	Disable() error
	// IsActive returns false when the tunnel is gone.
	IsActive() bool
	// Refresh peer list
	// Has to be called at least once after Enable
	Refresh(mesh.MachineMap) error
	// Tun retrieves a tunnel used for the meshnet
	Tun() tunnel.T
	// StatusMap retrieves the current status map for the related
	// meshnet peers
	StatusMap() (map[string]string, error)
	// NetworkChanged is called at network changes
	NetworkChanged() error
}

Mesh defines a set of operations that any type that wants to act as a mesh must implement.

type Networker

type Networker interface {
	// SetMesh sets the meshnet configuration up
	SetMesh(
		mesh.MachineMap,
		netip.Addr,
		string,
	) error
	Refresh(mesh.MachineMap) error // Remove
	// UnSetMesh unsets the meshnet configuration
	UnSetMesh() error
	// AllowIncoming creates an allowing fw rule for the given
	// address
	AllowIncoming(address UniqueAddress, lanAllowed bool) error
	// BlockIncoming creates a blocking fw rule for the given
	// address
	BlockIncoming(UniqueAddress) error
	// AllowFileshare creates a rule enabling fileshare port for the given address
	AllowFileshare(UniqueAddress) error
	//BlockFileshare removes a rule enabling fileshare port for the given address if it exists
	BlockFileshare(UniqueAddress) error
	// ResetRouting is used when there are routing setting changes,
	// except when routing is denied - then BlockRouting must be used. changedPeer is the peer whose routing settings
	// changed, peers is the map of all the machine peers(including the changed peer).
	ResetRouting(changedPeer mesh.MachinePeer, peers mesh.MachinePeers) error
	StatusMap() (map[string]string, error)
	LastServerName() string
	Start(
		vpn.Credentials,
		vpn.ServerData,
		config.Allowlist,
		config.DNS,
		bool,
	) error
	Stop() error
}

Networker defines functions responsible for network configuration

type Publisher

type Publisher interface {
	NotifyPeerUpdate([]string) error
	NotifySelfRemoved(any) error
}

Publisher defines receiver methods for meshnet related notifications

type RegisteringChecker

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

RegisteringChecker does both registration checks and registration, if it's not done.

func NewRegisteringChecker

func NewRegisteringChecker(
	cm config.Manager,
	gen KeyGenerator,
	reg cmesh.Registry,
) *RegisteringChecker

NewRegisteringChecker is a default constructor for RegisteringChecker.

func (*RegisteringChecker) IsRegistrationInfoCorrect

func (r *RegisteringChecker) IsRegistrationInfoCorrect() bool

IsRegistrationInfoCorrect reports meshnet device registration status.

Thread-safe.

func (*RegisteringChecker) Register

func (r *RegisteringChecker) Register() error

Register registers the device in API, even if it was already registered

type Server

type Server struct {
	pb.UnimplementedMeshnetServer
	// contains filtered or unexported fields
}

Server is an implementation of pb.MeshnetServer. It represents the part of meshnet in a daemon side

func NewServer

func NewServer(
	ac auth.Checker,
	cm config.Manager,
	mc Checker,
	invitationAPI mesh.Inviter,
	netw Networker,
	reg mesh.Registry,
	nameservers dns.Getter,
	pub events.Publisher[error],
	subjectPeerUpdate events.Publisher[[]string],
	subjectMeshSetting events.PublishSubcriber[bool],
	subjectConnect events.Publisher[events.DataConnect],
	norduser service.NorduserFileshareClient,
) *Server

NewServer is a default constructor for a meshnet server

func (*Server) AcceptInvite

func (s *Server) AcceptInvite(
	ctx context.Context,
	req *pb.InviteRequest,
) (*pb.RespondToInviteResponse, error)

AcceptInvite from another peer

func (*Server) AllowFileshare

func (s *Server) AllowFileshare(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.AllowFileshareResponse, error)

AllowFileshare allows peer to send files to this device

func (*Server) AllowIncoming

func (s *Server) AllowIncoming(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.AllowIncomingResponse, error)

AllowIncoming traffic from peer

func (*Server) AllowLocalNetwork

func (s *Server) AllowLocalNetwork(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.AllowLocalNetworkResponse, error)

AllowLocalNetwork allows peer to access local network on this machine

func (*Server) AllowRouting

func (s *Server) AllowRouting(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.AllowRoutingResponse, error)

AllowRouting allows peer to route traffic through this machine

func (*Server) ChangeMachineNickname

func (s *Server) ChangeMachineNickname(
	ctx context.Context,
	req *pb.ChangeMachineNicknameRequest,
) (*pb.ChangeNicknameResponse, error)

func (*Server) ChangePeerNickname

func (s *Server) ChangePeerNickname(
	ctx context.Context,
	req *pb.ChangePeerNicknameRequest,
) (*pb.ChangeNicknameResponse, error)

func (*Server) Connect

func (s *Server) Connect(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.ConnectResponse, error)

Connect to peer as if it was a VPN server.

func (*Server) DenyFileshare

func (s *Server) DenyFileshare(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.DenyFileshareResponse, error)

DenyFileshare forbids peer to send files to this device

func (*Server) DenyIncoming

func (s *Server) DenyIncoming(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.DenyIncomingResponse, error)

DenyIncoming traffic from peer

func (*Server) DenyInvite

func (s *Server) DenyInvite(
	ctx context.Context,
	req *pb.DenyInviteRequest,
) (*pb.RespondToInviteResponse, error)

DenyInvite from another peer

func (*Server) DenyLocalNetwork

func (s *Server) DenyLocalNetwork(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.DenyLocalNetworkResponse, error)

DenyLocalNetwork denies peer from accessing local network on this machine

func (*Server) DenyRouting

func (s *Server) DenyRouting(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.DenyRoutingResponse, error)

DenyRouting denies peer from routing traffic through this machine

func (*Server) DisableAutomaticFileshare

func (s *Server) DisableAutomaticFileshare(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.DisableAutomaticFileshareResponse, error)

DisableAutomaticFileshare requests from the peer

func (*Server) DisableMeshnet

func (s *Server) DisableMeshnet(context.Context, *pb.Empty) (*pb.MeshnetResponse, error)

DisableMeshnet disconnects device from meshnet.

func (*Server) EnableAutomaticFileshare

func (s *Server) EnableAutomaticFileshare(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.EnableAutomaticFileshareResponse, error)

AllowFileshare requests from the peer

func (*Server) EnableMeshnet

func (s *Server) EnableMeshnet(ctx context.Context, _ *pb.Empty) (*pb.MeshnetResponse, error)

EnableMeshnet connects device to meshnet.

func (*Server) GetInvites

func (s *Server) GetInvites(context.Context, *pb.Empty) (*pb.GetInvitesResponse, error)

GetInvites from the API

func (*Server) GetPeers

func (s *Server) GetPeers(context.Context, *pb.Empty) (*pb.GetPeersResponse, error)

GetPeers returns a list of this machine meshnet peers

func (*Server) GetPrivateKey

func (s *Server) GetPrivateKey(ctx context.Context, _ *pb.Empty) (*pb.PrivateKeyResponse, error)

GetPrivateKey returns self private key

func (*Server) Invite

func (s *Server) Invite(
	ctx context.Context,
	req *pb.InviteRequest,
) (*pb.InviteResponse, error)

Invite another peer

func (*Server) IsEnabled

func (s *Server) IsEnabled(context.Context, *pb.Empty) (*pb.IsEnabledResponse, error)

IsEnabled checks if meshnet is enabled

func (*Server) NotifyNewTransfer

func (s *Server) NotifyNewTransfer(
	ctx context.Context,
	req *pb.NewTransferNotification,
) (*pb.NotifyNewTransferResponse, error)

NotifyNewTransfer notifies peer about new fileshare transfer

func (*Server) RefreshMeshnet

func (s *Server) RefreshMeshnet(context.Context, *pb.Empty) (*pb.MeshnetResponse, error)

RefreshMeshnet updates peer configuration.

func (*Server) RemovePeer

func (s *Server) RemovePeer(
	ctx context.Context,
	req *pb.UpdatePeerRequest,
) (*pb.RemovePeerResponse, error)

func (*Server) RevokeInvite

func (s *Server) RevokeInvite(
	ctx context.Context,
	req *pb.DenyInviteRequest,
) (*pb.RespondToInviteResponse, error)

RevokeInvite to another peer

func (*Server) StartJobs

func (s *Server) StartJobs()

func (*Server) StartMeshnet

func (s *Server) StartMeshnet() error

type UniqueAddress

type UniqueAddress struct {
	// UID is a base64 encoded unique string
	UID     string
	Address netip.Addr
}

UniqueAddress a member of mesh network.

Directories

Path Synopsis
Package exitnode provides meshnet-related firewall management functionality.
Package exitnode provides meshnet-related firewall management functionality.
Package registry implements extra error handling over MeshAPI request
Package registry implements extra error handling over MeshAPI request

Jump to

Keyboard shortcuts

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