router

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWouldLoop is returned when a packet cannot be routed because it would
	// be sent back where it was received from.
	ErrWouldLoop = errors.New("not routing: would loop")

	// ErrTableEmpty is returned when a packet cannot be routed because the
	// routing table is empty.
	ErrTableEmpty = errors.New("not routing: table empty")
)
View Source
var (
	ErrAlreadyActive = errors.New("already active")
)

Errors.

Functions

This section is empty.

Types

type AnnouncePingAttachment

type AnnouncePingAttachment struct {
	Router       m.PublicAddress `cbor:"r"           json:"r"`
	Delay        uint16          `cbor:"d,omitempty" json:"d,omitempty"`
	ForwardLabel m.SwitchLabel   `cbor:"f,omitempty" json:"f,omitempty"`
	ReturnLabel  m.SwitchLabel   `cbor:"b,omitempty" json:"b,omitempty"`

	NextAttachment []byte `cbor:"n,omitempty" json:"n,omitempty"`
}

AnnouncePingAttachment is an announce ping attachment.

type AnnouncePingHandler

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

AnnouncePingHandler handles announce pings.

func NewAnnouncePingHandler

func NewAnnouncePingHandler(r *Router) *AnnouncePingHandler

NewAnnouncePingHandler returns a new announce ping handler.

func (*AnnouncePingHandler) Clean

func (h *AnnouncePingHandler) Clean(w *mgr.WorkerCtx) error

Clean cleans any internal state of the ping handler.

func (*AnnouncePingHandler) Handle

func (h *AnnouncePingHandler) Handle(w *mgr.WorkerCtx, f frame.Frame, hdr *PingHeader, data []byte) error

Handle handles incoming ping frames.

func (*AnnouncePingHandler) Send

func (h *AnnouncePingHandler) Send(peer netip.Addr) error

Send sends a hello message to the given destination.

func (*AnnouncePingHandler) Type

func (h *AnnouncePingHandler) Type() string

Type returns the ping type.

type AnnouncePingMsg

type AnnouncePingMsg struct {
	Info        *m.RouterInfo `cbor:"i,omitempty" json:"i,omitempty"`
	ReturnLabel m.SwitchLabel `cbor:"b,omitempty" json:"b,omitempty"`
	Expires     time.Time     `cbor:"e,omitempty" json:"e,omitempty"`
}

AnnouncePingMsg is an announce ping message.

type Config

type Config struct {
	Table m.RoutingTableConfig
}

Config configures the router.

type DisconnectPingHandler added in v0.4.0

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

DisconnectPingHandler handles announce pings.

func NewDisconnectPingHandler added in v0.4.0

func NewDisconnectPingHandler(r *Router) *DisconnectPingHandler

NewDisconnectPingHandler returns a new announce ping handler.

func (*DisconnectPingHandler) Clean added in v0.4.0

Clean cleans any internal state of the ping handler.

func (*DisconnectPingHandler) Handle added in v0.4.0

func (h *DisconnectPingHandler) Handle(w *mgr.WorkerCtx, f frame.Frame, hdr *PingHeader, data []byte) error

Handle handles incoming ping frames.

func (*DisconnectPingHandler) Send added in v0.4.0

func (h *DisconnectPingHandler) Send(goingDown bool, disconnected []netip.Addr) error

Send sends a hello message to the given destination.

func (*DisconnectPingHandler) Type added in v0.4.0

func (h *DisconnectPingHandler) Type() string

Type returns the ping type.

type DisconnectPingMsg added in v0.4.0

type DisconnectPingMsg struct {
	// GoingDown signifies that the router is about to go offline.
	GoingDown bool `cbor:"off,omitempty" json:"off,omitempty"`

	// Disconnected holds a list of routers that are no longer connected to the announcing router.
	// Ignored when GoingDown is set.
	Disconnected []netip.Addr `cbor:"d,omitempty" json:"d,omitempty"`
}

DisconnectPingMsg is a disconnect ping message.

type ErrorPingHandler added in v0.1.0

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

ErrorPingHandler handles announce pings.

func NewErrorPingHandler added in v0.1.0

func NewErrorPingHandler(r *Router) *ErrorPingHandler

NewErrorPingHandler returns a new announce ping handler.

func (*ErrorPingHandler) Clean added in v0.1.0

func (h *ErrorPingHandler) Clean(w *mgr.WorkerCtx) error

Clean cleans any internal state of the ping handler.

func (*ErrorPingHandler) Handle added in v0.1.0

func (h *ErrorPingHandler) Handle(w *mgr.WorkerCtx, f frame.Frame, hdr *PingHeader, data []byte) error

Handle handles incoming ping frames.

func (*ErrorPingHandler) SendAccessDenied added in v0.4.0

func (h *ErrorPingHandler) SendAccessDenied(to netip.Addr, dstIP netip.Addr, protocol uint8, dstPort uint16) error

SendAccessDenied sends an access denied error.

func (*ErrorPingHandler) SendGeneric added in v0.4.0

func (h *ErrorPingHandler) SendGeneric(to netip.Addr, text string) error

SendGeneric sends a generic error.

func (*ErrorPingHandler) SendNoEncryptionKeys added in v0.4.0

func (h *ErrorPingHandler) SendNoEncryptionKeys(to netip.Addr) error

SendNoEncryptionKeys sends a "no encryption keys" error.

func (*ErrorPingHandler) SendRejected added in v0.4.0

func (h *ErrorPingHandler) SendRejected(to netip.Addr, dstIP netip.Addr, protocol uint8, dstPort uint16) error

SendRejected sends a rejected error.

func (*ErrorPingHandler) SendUnreachable added in v0.4.0

func (h *ErrorPingHandler) SendUnreachable(to, unreachable netip.Addr) error

SendUnreachable sends an unreachable error.

func (*ErrorPingHandler) Type added in v0.1.0

func (h *ErrorPingHandler) Type() string

Type returns the ping type.

type ExportedConnection added in v0.4.0

type ExportedConnection struct {
	LocalIP    netip.Addr
	RemoteIP   netip.Addr
	Protocol   uint8
	LocalPort  uint16
	RemotePort uint16

	Inbound     bool
	StatusName  string
	StatusColor string
	FirstSeen   time.Time
	LastSeen    time.Time

	DataIn  uint64
	DataOut uint64
}

ExportedConnection is an exported version of a connection.

func (*ExportedConnection) HasPorts added in v0.4.0

func (e *ExportedConnection) HasPorts() bool

HasPorts returns whether the connection has ports.

func (*ExportedConnection) ProtocolName added in v0.4.0

func (e *ExportedConnection) ProtocolName() string

ProtocolName returns the protocol name, if available. Otherwise a string representation of the protocol number is returned.

func (*ExportedConnection) TimeDescription added in v0.4.0

func (e *ExportedConnection) TimeDescription() string

TimeDescription returns a simplified and readable description of the first and last seen timestamps.

type HelloPingHandler

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

HelloPingHandler handles hello pings.

func NewHelloPingHandler

func NewHelloPingHandler(r *Router) *HelloPingHandler

NewHelloPingHandler returns a new hello ping handler.

func (*HelloPingHandler) Clean

func (h *HelloPingHandler) Clean(w *mgr.WorkerCtx) error

Clean cleans any internal state of the ping handler.

func (*HelloPingHandler) Handle

func (h *HelloPingHandler) Handle(w *mgr.WorkerCtx, f frame.Frame, hdr *PingHeader, data []byte) error

Handle handles incoming ping frames.

func (*HelloPingHandler) Send

func (h *HelloPingHandler) Send(dstIP netip.Addr) (notify <-chan struct{}, err error)

Send sends a hello message to the given destination.

func (*HelloPingHandler) Type

func (h *HelloPingHandler) Type() string

Type returns the ping type.

type HelloPingRequest

type HelloPingRequest struct {
	KeyExchange     []byte `cbor:"kx,omitempty"  json:"kx,omitempty"`
	KeyExchangeType string `cbor:"kxt,omitempty" json:"kxt,omitempty"`

	MTU int `cbor:"mtu,omitempty" json:"mtu,omitempty"`
}

HelloPingRequest is a hello ping request.

type HelloPingResponse

type HelloPingResponse struct {
	KeyExchange     []byte `cbor:"kx,omitempty"  json:"kx,omitempty"`
	KeyExchangeType string `cbor:"kxt,omitempty" json:"kxt,omitempty"`

	MTU int `cbor:"mtu,omitempty" json:"mtu,omitempty"`

	Err string `cbor:"err,omitempty" json:"err,omitempty"`
}

HelloPingResponse is a hello ping response.

type PingHandler

type PingHandler interface {
	Type() string
	Handle(w *mgr.WorkerCtx, f frame.Frame, pingHdr *PingHeader, pingData []byte) error
	Clean(w *mgr.WorkerCtx) error
}

PingHandler handles ping messages of a type.

type PingHeader

type PingHeader struct {
	PingID    uint64            `cbor:"i,omitempty" json:"i,omitempty"`
	PingType  string            `cbor:"t,omitempty" json:"t,omitempty"`
	PingCode  uint8             `cbor:"c,omitempty" json:"c,omitempty"`
	FollowUp  bool              `cbor:"f,omitempty" json:"f,omitempty"`
	AddrHash  m.Hash            `cbor:"h,omitempty" json:"h,omitempty"`
	KeyType   string            `cbor:"a,omitempty" json:"a,omitempty"`
	PublicKey ed25519.PublicKey `cbor:"k,omitempty" json:"k,omitempty"`
}

PingHeader is the header used for every ping message.

type PingPongHandler

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

PingPongHandler handles pong pings.

func NewPingPongHandler

func NewPingPongHandler(r *Router) *PingPongHandler

NewPingPongHandler returns a new pong ping handler.

func (*PingPongHandler) Clean

func (h *PingPongHandler) Clean(w *mgr.WorkerCtx) error

Clean cleans any internal state of the ping handler.

func (*PingPongHandler) Handle

func (h *PingPongHandler) Handle(w *mgr.WorkerCtx, f frame.Frame, hdr *PingHeader, data []byte) error

Handle handles incoming ping frames.

func (*PingPongHandler) Send

func (h *PingPongHandler) Send(dstIP netip.Addr, peer bool, retryPingID uint64) (notify <-chan struct{}, pingID uint64, err error)

Send sends a pong message to the given destination.

func (*PingPongHandler) Type

func (h *PingPongHandler) Type() string

Type returns the ping type.

type Router

type Router struct {
	HelloPing      *HelloPingHandler
	PingPong       *PingPongHandler
	ErrorPing      *ErrorPingHandler
	AnnouncePing   *AnnouncePingHandler
	DisconnectPing *DisconnectPingHandler
	// contains filtered or unexported fields
}

Router is the primary handler for frames.

func New

func New(instance instance, routerConfig Config) (*Router, error)

New returns a new router.

func (*Router) ExportConnections added in v0.4.0

func (r *Router) ExportConnections(maxAge time.Duration) []ExportedConnection

ExportConnections returns an exported version of the connections.

func (*Router) GetPingHandler

func (r *Router) GetPingHandler(pingType string) PingHandler

GetPingHandler returns the ping handler of the given ping type.

func (*Router) Input

func (r *Router) Input() chan frame.Frame

Input returns the router input channel.

func (*Router) RegisterPingHandler

func (r *Router) RegisterPingHandler(handler PingHandler) error

RegisterPingHandler registers the given ping handler in the router.

func (*Router) RouteFrame

func (r *Router) RouteFrame(f frame.Frame) error

RouteFrame forwards the given frame to the next hop based on the destination IP.

func (*Router) Start

func (r *Router) Start(mgr *mgr.Manager) error

Start starts the router.

func (*Router) Stop

func (r *Router) Stop(mgr *mgr.Manager) error

Stop stops the router.

func (*Router) Table

func (r *Router) Table() *m.RoutingTable

Table returns the routing table.

Jump to

Keyboard shortcuts

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