node

package
v0.0.0-...-e221ce6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// Timers
	TimerHandshakeTimeout = time.Second * 5
	TimerRxTimeout        = time.Second * 15
	TimerKeepalive        = time.Second * 10
	// Counts
	CountHandshakeRetries = 10

	InboundChannelSize   = 1024
	OutboundChannelSize  = 1024
	HandshakeChannelSize = 3
)
View Source
const BufferSize = 1600

Variables

View Source
var (
	InboundBuffers  = sync.Pool{New: NewInboundBuffer}
	OutboundBuffers = sync.Pool{New: NewOutboundBuffer}
	IBuffersInUse   atomic.Uint64
	OBuffersInUse   atomic.Uint64
)

Functions

func AuthFlow

func AuthFlow(info *nodev1.LoginResponse) (string, error)

func CompareAddrPort

func CompareAddrPort(p1, p2 netip.AddrPort) int

func CreateHandshake

func CreateHandshake(initiator bool, keypair noise.DHKey, rs []byte) (*noise.HandshakeState, error)

func DecodeBase64Key

func DecodeBase64Key(key string) ([]byte, error)

func GenerateNewKeypair

func GenerateNewKeypair() (noise.DHKey, error)

func GetPreferredOutboundAddr

func GetPreferredOutboundAddr() (netip.Addr, error)

func LoadKeyFromDisk

func LoadKeyFromDisk() (noise.DHKey, error)

func NewInboundBuffer

func NewInboundBuffer() interface{}

func NewOutboundBuffer

func NewOutboundBuffer() interface{}

func ParseAddr

func ParseAddr(addr string) (netip.Addr, error)

func ParseAddrPort

func ParseAddrPort(ap string) (netip.AddrPort, error)

func PutInboundBuffer

func PutInboundBuffer(buffer *InboundBuffer)

func PutOutboundBuffer

func PutOutboundBuffer(buffer *OutboundBuffer)

func ReportBuffers

func ReportBuffers()

func StoreKeyToDisk

func StoreKeyToDisk(keyPair noise.DHKey) error

Types

type ControllerClient

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

func NewControllerClient

func NewControllerClient(address string) (*ControllerClient, error)

func (*ControllerClient) Close

func (c *ControllerClient) Close() error

func (*ControllerClient) UpdateEndpoint

func (c *ControllerClient) UpdateEndpoint(id string, endpoint string)

type InboundBuffer

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

func GetInboundBuffer

func GetInboundBuffer() *InboundBuffer

type Key

type Key struct {
	Public  string `yaml:"PublicKey"`
	Private string `yaml:"PrivateKey"`
}

type Node

type Node struct {
	nodev1.UnimplementedNodeServiceServer
	// contains filtered or unexported fields
}

TODO: Verify need for mutex for node properties like ip, prefix, id, etc TODO: Handle logged in state and when to refresh TODO: Handle logged in state after running 'down' command

func NewNode

func NewNode(controller string, port uint16) (*Node, error)

func (*Node) AddPeer

func (node *Node) AddPeer(peerInfo *proto.Peer) (*Peer, error)

TODO Proper error text for context around the issue

func (*Node) Down

func (n *Node) Down(ctx context.Context, req *nodev1.DownRequest) (*nodev1.DownResponse, error)

func (*Node) HandleUpdate

func (node *Node) HandleUpdate(update *controllerv1.UpdateResponse)

func (*Node) Login

func (n *Node) Login(ctx context.Context, req *nodev1.LoginRequest) (*nodev1.LoginResponse, error)

func (*Node) OnTunnelPacket

func (node *Node) OnTunnelPacket(buffer *OutboundBuffer)

func (*Node) OnUDPPacket

func (node *Node) OnUDPPacket(buffer *InboundBuffer, index int)

func (*Node) ReadTunPackets

func (node *Node) ReadTunPackets(callback OnTunnelPacket)

func (*Node) ReadUDPPackets

func (node *Node) ReadUDPPackets(callback OnUDPPacket, index int)

func (*Node) RequestPunch

func (node *Node) RequestPunch(id uint32)

func (*Node) Run

func (node *Node) Run() error

func (*Node) Start

func (n *Node) Start() error

func (*Node) StartUpdateStream

func (node *Node) StartUpdateStream(ctx context.Context)

TODO: Move some of the stream logic to ControllerClient

func (*Node) Stop

func (node *Node) Stop() error

func (*Node) StopAllPeers

func (node *Node) StopAllPeers()

func (*Node) Up

func (n *Node) Up(ctx context.Context, req *nodev1.UpRequest) (*nodev1.UpResponse, error)

type OnTunnelPacket

type OnTunnelPacket func(buffer *OutboundBuffer)

type OnUDPPacket

type OnUDPPacket func(buffer *InboundBuffer, index int)

type OutboundBuffer

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

func GetOutboundBuffer

func GetOutboundBuffer() *OutboundBuffer

type Peer

type Peer struct {
	Hostname string

	IP netip.Addr
	ID uint32
	// contains filtered or unexported fields
}

TODO proper self-contained state machine for noise handshakes

func NewPeer

func NewPeer() *Peer

func (*Peer) Handshake

func (peer *Peer) Handshake()

TODO completely rewrite this with proper state tracking and error handling

func (*Peer) HandshakeTimeout

func (peer *Peer) HandshakeTimeout()

func (*Peer) Inbound

func (peer *Peer) Inbound()

func (*Peer) InboundPacket

func (peer *Peer) InboundPacket(buffer *InboundBuffer)

func (*Peer) InitHandshake

func (peer *Peer) InitHandshake(initiator bool) error

TODO Not safe for concurrent use, possibly called from different goroutines. fix with lock inside noise struct

func (*Peer) Outbound

func (peer *Peer) Outbound()

func (*Peer) OutboundPacket

func (peer *Peer) OutboundPacket(buffer *OutboundBuffer)

func (*Peer) RXTimeout

func (peer *Peer) RXTimeout()

func (*Peer) RequestPunch

func (peer *Peer) RequestPunch()

func (*Peer) ResetState

func (peer *Peer) ResetState()

func (*Peer) Start

func (peer *Peer) Start() error

func (*Peer) Stop

func (peer *Peer) Stop()

func (*Peer) TXTimeout

func (peer *Peer) TXTimeout()

func (*Peer) TrySendHandshake

func (peer *Peer) TrySendHandshake(retry bool)

func (*Peer) Update

func (peer *Peer) Update(info *controllerv1.Peer) error

// TODO Fix variable naming and compares

func (*Peer) UpdateEndpoint

func (peer *Peer) UpdateEndpoint(addr *net.UDPAddr)

func (*Peer) UpdateEndpointLocked

func (peer *Peer) UpdateEndpointLocked(addr *net.UDPAddr)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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