peer

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnectionAlreadyClosed

func NewConnectionAlreadyClosed(peer string) error

NewConnectionAlreadyClosed creates a new ConnectionAlreadyClosedError error

func NewConnectionClosedError

func NewConnectionClosedError(peer string) error

NewConnectionClosedError creates a new ConnectionClosedError error

func NewConnectionDisconnectedError

func NewConnectionDisconnectedError(peer string) error

NewConnectionDisconnectedError creates a new ConnectionDisconnectedError error

func NewConnectionTimeoutError

func NewConnectionTimeoutError(peer string, timeout time.Duration) error

NewConnectionTimeoutError creates a new ConnectionTimeoutError error

Types

type AfterRemovePeerHookFunc

type AfterRemovePeerHookFunc func(connID nbnet.ConnectionID) error

type BeforeAddPeerHookFunc

type BeforeAddPeerHookFunc func(connID nbnet.ConnectionID, IP net.IP) error

type Conn

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

func NewConn

func NewConn(config ConnConfig, statusRecorder *Status, wgProxyFactory *wgproxy.Factory, adapter iface.TunAdapter, iFaceDiscover stdnet.ExternalIFaceDiscover) (*Conn, error)

NewConn creates a new not opened Conn to the remote peer. To establish a connection run Conn.Open

func (*Conn) AddAfterRemovePeerHook

func (conn *Conn) AddAfterRemovePeerHook(hook AfterRemovePeerHookFunc)

func (*Conn) AddBeforeAddPeerHook

func (conn *Conn) AddBeforeAddPeerHook(hook BeforeAddPeerHookFunc)

func (*Conn) Close

func (conn *Conn) Close() error

Close closes this peer Conn issuing a close event to the Conn closeCh

func (*Conn) GetConf

func (conn *Conn) GetConf() ConnConfig

GetConf returns the connection config

func (*Conn) GetKey

func (conn *Conn) GetKey() string

func (*Conn) OnRemoteAnswer

func (conn *Conn) OnRemoteAnswer(answer OfferAnswer) bool

OnRemoteAnswer handles an offer from the remote peer and returns true if the message was accepted, false otherwise doesn't block, discards the message if connection wasn't ready

func (*Conn) OnRemoteCandidate

func (conn *Conn) OnRemoteCandidate(candidate ice.Candidate, haRoutes route.HAMap)

OnRemoteCandidate Handles ICE connection Candidate provided by the remote peer.

func (*Conn) OnRemoteOffer

func (conn *Conn) OnRemoteOffer(offer OfferAnswer) bool

OnRemoteOffer handles an offer from the remote peer and returns true if the message was accepted, false otherwise doesn't block, discards the message if connection wasn't ready

func (*Conn) Open

func (conn *Conn) Open(ctx context.Context) error

Open opens connection to the remote peer starting ICE candidate gathering process. Blocks until connection has been closed or connection timeout. ConnStatus will be set accordingly

func (*Conn) RegisterProtoSupportMeta

func (conn *Conn) RegisterProtoSupportMeta(support []uint32)

RegisterProtoSupportMeta register supported proto message in the connection metadata

func (*Conn) SetOnConnected

func (conn *Conn) SetOnConnected(handler func(remoteWireGuardKey string, remoteRosenpassPubKey []byte, wireGuardIP string, remoteRosenpassAddr string))

SetOnConnected sets a handler function to be triggered by Conn when a new connection to a remote peer established

func (*Conn) SetOnDisconnected

func (conn *Conn) SetOnDisconnected(handler func(remotePeer string, wgIP string))

SetOnDisconnected sets a handler function to be triggered by Conn when a connection to a remote disconnected

func (*Conn) SetSendSignalMessage

func (conn *Conn) SetSendSignalMessage(handler func(message *sProto.Message) error)

SetSendSignalMessage sets a handler function to be triggered by Conn when there is new message to send via signal

func (*Conn) SetSignalAnswer

func (conn *Conn) SetSignalAnswer(handler func(answer OfferAnswer) error)

SetSignalAnswer sets a handler function to be triggered by Conn when a new connection answer has to be signalled to the remote peer

func (*Conn) SetSignalCandidate

func (conn *Conn) SetSignalCandidate(handler func(candidate ice.Candidate) error)

SetSignalCandidate sets a handler function to be triggered by Conn when a new ICE local connection candidate has to be signalled to the remote peer

func (*Conn) SetSignalOffer

func (conn *Conn) SetSignalOffer(handler func(offer OfferAnswer) error)

SetSignalOffer sets a handler function to be triggered by Conn when a new connection offer has to be signalled to the remote peer

func (*Conn) Status

func (conn *Conn) Status() ConnStatus

Status returns current status of the Conn

func (*Conn) UpdateStunTurn

func (conn *Conn) UpdateStunTurn(turnStun []*stun.URI)

UpdateStunTurn update the turn and stun addresses

func (*Conn) WgConfig

func (conn *Conn) WgConfig() WgConfig

WgConfig returns the WireGuard config

type ConnConfig

type ConnConfig struct {

	// Key is a public key of a remote peer
	Key string
	// LocalKey is a public key of a local peer
	LocalKey string

	// StunTurn is a list of STUN and TURN URLs
	StunTurn []*stun.URI

	// InterfaceBlackList is a list of machine interfaces that should be filtered out by ICE Candidate gathering
	// (e.g. if eth0 is in the list, host candidate of this interface won't be used)
	InterfaceBlackList   []string
	DisableIPv6Discovery bool

	Timeout time.Duration

	WgConfig WgConfig

	UDPMux      ice.UDPMux
	UDPMuxSrflx ice.UniversalUDPMux

	LocalWgPort int

	NATExternalIPs []string

	// UsesBind indicates whether the WireGuard interface is userspace and uses bind.ICEBind
	UserspaceBind bool

	// RosenpassPubKey is this peer's Rosenpass public key
	RosenpassPubKey []byte
	// RosenpassPubKey is this peer's RosenpassAddr server address (IP:port)
	RosenpassAddr string
}

ConnConfig is a peer Connection configuration

type ConnStatus

type ConnStatus int

ConnStatus describe the status of a peer's connection

const (
	// StatusConnected indicate the peer is in connected state
	StatusConnected ConnStatus = iota
	// StatusConnecting indicate the peer is in connecting state
	StatusConnecting
	// StatusDisconnected indicate the peer is in disconnected state
	StatusDisconnected
)

func (ConnStatus) String

func (s ConnStatus) String() string

type ConnectionAlreadyClosedError

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

ConnectionAlreadyClosedError is an error indicating that a peer Conn has been already closed and the invocation of the Close() method has been performed over a closed connection

func (*ConnectionAlreadyClosedError) Error

type ConnectionClosedError

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

ConnectionClosedError is an error indicating that a peer Conn has been forcefully closed

func (*ConnectionClosedError) Error

func (e *ConnectionClosedError) Error() string

type ConnectionDisconnectedError

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

ConnectionDisconnectedError is an error indicating that a peer Conn has ctx from the remote

func (*ConnectionDisconnectedError) Error

type ConnectionTimeoutError

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

ConnectionTimeoutError is an error indicating that a peer Conn has been timed out

func (*ConnectionTimeoutError) Error

func (e *ConnectionTimeoutError) Error() string

type FullStatus

type FullStatus struct {
	Peers           []State
	ManagementState ManagementState
	SignalState     SignalState
	LocalPeerState  LocalPeerState
	RosenpassState  RosenpassState
	Relays          []relay.ProbeResult
	NSGroupStates   []NSGroupState
}

FullStatus contains the full state held by the Status instance

type IceCredentials

type IceCredentials struct {
	UFrag string
	Pwd   string
}

IceCredentials ICE protocol credentials struct

type Listener

type Listener interface {
	OnConnected()
	OnDisconnected()
	OnConnecting()
	OnDisconnecting()
	OnAddressChanged(string, string)
	OnPeersListChanged(int)
}

Listener is a callback type about the NetBird network connection state

type LocalPeerState

type LocalPeerState struct {
	IP              string
	PubKey          string
	KernelInterface bool
	FQDN            string
	Routes          map[string]struct{}
}

LocalPeerState contains the latest state of the local peer

type ManagementState

type ManagementState struct {
	URL       string
	Connected bool
	Error     error
}

ManagementState contains the latest state of a management connection

type ModeMessage

type ModeMessage struct {
	// Direct indicates that it decided to use a direct connection
	Direct bool
}

ModeMessage represents a connection mode chosen by the peer

type NSGroupState

type NSGroupState struct {
	ID      string
	Servers []string
	Domains []string
	Enabled bool
	Error   error
}

NSGroupState represents the status of a DNS server group, including associated domains, whether it's enabled, and the last error message encountered during probing.

type OfferAnswer

type OfferAnswer struct {
	IceCredentials IceCredentials
	// WgListenPort is a remote WireGuard listen port.
	// This field is used when establishing a direct WireGuard connection without any proxy.
	// We can set the remote peer's endpoint with this port.
	WgListenPort int

	// Version of NetBird Agent
	Version string
	// RosenpassPubKey is the Rosenpass public key of the remote peer when receiving this message
	// This value is the local Rosenpass server public key when sending the message
	RosenpassPubKey []byte
	// RosenpassAddr is the Rosenpass server address (IP:port) of the remote peer when receiving this message
	// This value is the local Rosenpass server address when sending the message
	RosenpassAddr string
}

OfferAnswer represents a session establishment offer or answer

type RosenpassState

type RosenpassState struct {
	Enabled    bool
	Permissive bool
}

RosenpassState contains the latest state of the Rosenpass configuration

type SignalState

type SignalState struct {
	URL       string
	Connected bool
	Error     error
}

SignalState contains the latest state of a signal connection

type State

type State struct {
	Mux                        *sync.RWMutex
	IP                         string
	PubKey                     string
	FQDN                       string
	ConnStatus                 ConnStatus
	ConnStatusUpdate           time.Time
	Relayed                    bool
	Direct                     bool
	LocalIceCandidateType      string
	RemoteIceCandidateType     string
	LocalIceCandidateEndpoint  string
	RemoteIceCandidateEndpoint string
	LastWireguardHandshake     time.Time
	BytesTx                    int64
	BytesRx                    int64
	Latency                    time.Duration
	RosenpassEnabled           bool
	// contains filtered or unexported fields
}

State contains the latest state of a peer

func (*State) AddRoute

func (s *State) AddRoute(network string)

AddRoute add a single route to routes map

func (*State) DeleteRoute

func (s *State) DeleteRoute(network string)

DeleteRoute removes a route from the network amp

func (*State) GetRoutes

func (s *State) GetRoutes() map[string]struct{}

GetRoutes return routes map

func (*State) SetRoutes

func (s *State) SetRoutes(routes map[string]struct{})

SetRoutes set state routes

type Status

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

Status holds a state of peers, signal, management connections and relays

func NewRecorder

func NewRecorder(mgmAddress string) *Status

NewRecorder returns a new Status instance

func (*Status) AddPeer

func (d *Status) AddPeer(peerPubKey string, fqdn string) error

AddPeer adds peer to Daemon status map

func (*Status) CleanLocalPeerState

func (d *Status) CleanLocalPeerState()

CleanLocalPeerState cleans local peer status

func (*Status) ClientStart

func (d *Status) ClientStart()

ClientStart will notify all listeners about the new service state

func (*Status) ClientStop

func (d *Status) ClientStop()

ClientStop will notify all listeners about the new service state

func (*Status) ClientTeardown

func (d *Status) ClientTeardown()

ClientTeardown will notify all listeners about the service is under teardown

func (*Status) FinishPeerListModifications

func (d *Status) FinishPeerListModifications()

FinishPeerListModifications this event invoke the notification

func (*Status) GetDNSStates

func (d *Status) GetDNSStates() []NSGroupState

func (*Status) GetFullStatus

func (d *Status) GetFullStatus() FullStatus

GetFullStatus gets full status

func (*Status) GetLocalPeerState

func (d *Status) GetLocalPeerState() LocalPeerState

GetLocalPeerState returns the local peer state

func (*Status) GetManagementState

func (d *Status) GetManagementState() ManagementState

func (*Status) GetPeer

func (d *Status) GetPeer(peerPubKey string) (State, error)

GetPeer adds peer to Daemon status map

func (*Status) GetPeerStateChangeNotifier

func (d *Status) GetPeerStateChangeNotifier(peer string) <-chan struct{}

GetPeerStateChangeNotifier returns a change notifier channel for a peer

func (*Status) GetRelayStates

func (d *Status) GetRelayStates() []relay.ProbeResult

func (*Status) GetRosenpassState

func (d *Status) GetRosenpassState() RosenpassState

func (*Status) GetSignalState

func (d *Status) GetSignalState() SignalState

func (*Status) IsLoginRequired

func (d *Status) IsLoginRequired() bool

IsLoginRequired determines if a peer's login has expired.

func (*Status) MarkManagementConnected

func (d *Status) MarkManagementConnected()

MarkManagementConnected sets ManagementState to connected

func (*Status) MarkManagementDisconnected

func (d *Status) MarkManagementDisconnected(err error)

MarkManagementDisconnected sets ManagementState to disconnected

func (*Status) MarkSignalConnected

func (d *Status) MarkSignalConnected()

MarkSignalConnected sets SignalState to connected

func (*Status) MarkSignalDisconnected

func (d *Status) MarkSignalDisconnected(err error)

MarkSignalDisconnected sets SignalState to disconnected

func (*Status) RemoveConnectionListener

func (d *Status) RemoveConnectionListener()

RemoveConnectionListener remove the listener from the notifier

func (*Status) RemovePeer

func (d *Status) RemovePeer(peerPubKey string) error

RemovePeer removes peer from Daemon status map

func (*Status) ReplaceOfflinePeers

func (d *Status) ReplaceOfflinePeers(replacement []State)

ReplaceOfflinePeers replaces

func (*Status) SetConnectionListener

func (d *Status) SetConnectionListener(listener Listener)

SetConnectionListener set a listener to the notifier

func (*Status) UpdateDNSStates

func (d *Status) UpdateDNSStates(dnsStates []NSGroupState)

func (*Status) UpdateLatency

func (d *Status) UpdateLatency(pubKey string, latency time.Duration) error

func (*Status) UpdateLocalPeerState

func (d *Status) UpdateLocalPeerState(localPeerState LocalPeerState)

UpdateLocalPeerState updates local peer status

func (*Status) UpdateManagementAddress

func (d *Status) UpdateManagementAddress(mgmAddress string)

UpdateManagementAddress update the address of the management server

func (*Status) UpdatePeerFQDN

func (d *Status) UpdatePeerFQDN(peerPubKey, fqdn string) error

UpdatePeerFQDN update peer's state fqdn only

func (*Status) UpdatePeerState

func (d *Status) UpdatePeerState(receivedState State) error

UpdatePeerState updates peer status

func (*Status) UpdateRelayStates

func (d *Status) UpdateRelayStates(relayResults []relay.ProbeResult)

func (*Status) UpdateRosenpass

func (d *Status) UpdateRosenpass(rosenpassEnabled, rosenpassPermissive bool)

UpdateRosenpass update the Rosenpass configuration

func (*Status) UpdateSignalAddress

func (d *Status) UpdateSignalAddress(signalURL string)

UpdateSignalAddress update the address of the signal server

func (*Status) UpdateWireGuardPeerState

func (d *Status) UpdateWireGuardPeerState(pubKey string, wgStats iface.WGStats) error

UpdateWireGuardPeerState updates the WireGuard bits of the peer state

type WgConfig

type WgConfig struct {
	WgListenPort int
	RemoteKey    string
	WgInterface  *iface.WGIface
	AllowedIps   string
	PreSharedKey *wgtypes.Key
}

Jump to

Keyboard shortcuts

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