Documentation ¶
Index ¶
- Constants
- Variables
- type Builder
- func (b *Builder) FrameMargins() (offset, overhead int)
- func (b *Builder) GetPooledSlice(minSize int) (pooledSlice []byte)
- func (b *Builder) NewFrameV1(src, dst netip.Addr, msgType MessageType, ...) (*FrameV1, error)
- func (b *Builder) ParseFrame(data, pooledSlice []byte, dataOffset int) (Frame, error)
- func (b *Builder) ParseFrameV1(data, pooledSlice []byte, dataOffset int) (*FrameV1, error)
- func (b *Builder) ReturnPooledSlice(pooledSlice []byte)
- func (b *Builder) SetFrameMargins(offset, overhead int)
- type FlowControlFlag
- type Frame
- type FrameV1
- func (f *FrameV1) AppendixData() []byte
- func (f *FrameV1) AuthData() []byte
- func (f *FrameV1) Clone() Frame
- func (f *FrameV1) DstIP() netip.Addr
- func (f *FrameV1) FlowControl() uint8
- func (f *FrameV1) FrameDataWithMargins(offset, overhead int) ([]byte, error)
- func (f *FrameV1) HasFlowFlag(flag FlowControlFlag) bool
- func (f *FrameV1) MessageData() []byte
- func (f *FrameV1) MessageDataWithAuth() []byte
- func (f *FrameV1) MessageDataWithOffset(offset int) ([]byte, error)
- func (f *FrameV1) MessageType() MessageType
- func (f *FrameV1) RecvLink() LinkAccessor
- func (f *FrameV1) RecvRate() uint8
- func (f *FrameV1) ReduceTTL(by uint8)
- func (f *FrameV1) Reply(switchLabels, data, appendixData []byte) error
- func (f *FrameV1) ReplyTo(src, dst netip.Addr, switchLabels, data, appendixData []byte) error
- func (f *FrameV1) ReturnToPool()
- func (f *FrameV1) Seal(s *state.Session) error
- func (f *FrameV1) SequenceAck() uint32
- func (f *FrameV1) SequenceNum() uint32
- func (f *FrameV1) SequenceTime() time.Time
- func (f *FrameV1) SetAppendixData(appendix []byte) error
- func (f *FrameV1) SetFlowControl(fc uint8)
- func (f *FrameV1) SetFlowFlag(flag FlowControlFlag)
- func (f *FrameV1) SetMessageType(msgType MessageType)
- func (f *FrameV1) SetRecvLink(link LinkAccessor)
- func (f *FrameV1) SetRecvRate(percent uint8)
- func (f *FrameV1) SetSequenceAck(n uint32)
- func (f *FrameV1) SetSequenceNum(n uint32)
- func (f *FrameV1) SetSequenceTime(t time.Time)
- func (f *FrameV1) SetSwitchBlock(update []byte) error
- func (f *FrameV1) SetTTL(ttl uint8)
- func (f *FrameV1) SignRaw(key ed25519.PrivateKey) error
- func (f *FrameV1) SrcIP() netip.Addr
- func (f *FrameV1) SwitchBlock() []byte
- func (f *FrameV1) TTL() uint8
- func (f *FrameV1) Unseal(s *state.Session) error
- func (f *FrameV1) VerifyRaw(key ed25519.PublicKey) error
- func (f *FrameV1) Version() uint8
- type LinkAccessor
- type MessageClass
- type MessageType
Constants ¶
const (
// V1 is frame version 1.
V1 = 1
)
Variables ¶
var ( ErrInsufficientFrameData = errors.New("insufficient frame data") ErrIncorrectLength = errors.New("incorrect length") ErrUnsupportedFrameVersion = errors.New("unsupported frame version") ErrVerificationFailed = errors.New("verification failed") )
Errors.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds and parses frames. It holds internal pools of frames and slices for efficiency.
func (*Builder) FrameMargins ¶
FrameMargins returns the currently required margins for frames.
func (*Builder) GetPooledSlice ¶
GetPooledSlice returns a slice from the pool (or creates one) that has at least the specified size.
func (*Builder) NewFrameV1 ¶
func (b *Builder) NewFrameV1( src, dst netip.Addr, msgType MessageType, switchLabels, data, appendixData []byte, ) (*FrameV1, error)
NewFrameV1 returns a new frame (v1) with the given data set.
func (*Builder) ParseFrame ¶
ParseFrame parses a frame.
func (*Builder) ParseFrameV1 ¶
ParseFrameV1 parses a version 1 frame.
func (*Builder) ReturnPooledSlice ¶
ReturnPooledSlice returns the give pooled slice to the pool. The provided slice must not be used anymore in any way.
func (*Builder) SetFrameMargins ¶
SetFrameMargins sets new required margins for new frames. Values must be between 0 and 100 (inclusive).
type FlowControlFlag ¶
type FlowControlFlag uint8
FlowControlFlag is a set of flow control flags.
const ( FlowControlFlagDecreaseFlow FlowControlFlag = iota + 1 FlowControlFlagHoldFlow FlowControlFlagIncreaseFlow )
Flow Control Flags.
type Frame ¶
type Frame interface { // Version returns the frame version. Version() uint8 // TTL returns the TTL. TTL() uint8 // SetTTL sets the TTL. SetTTL(ttl uint8) // ReduceTTL reduces the ttl by the given amount. // Will not drop below zero. ReduceTTL(by uint8) // HasFlowFlag returns whether the given flow control flag is set. HasFlowFlag(flag FlowControlFlag) bool // SetFlowFlag sets the given flow control flag. SetFlowFlag(flag FlowControlFlag) // RecvRate returns the recv rate. RecvRate() uint8 // SetRecvRate sets the recv rate. SetRecvRate(rate uint8) // MessageType returns the message type. MessageType() MessageType // SetMessageType sets the message type. SetMessageType(msgType MessageType) // SequenceNum returns the sequence number. SequenceNum() uint32 // SetSequenceNum sets the sequence number. SetSequenceNum(seq uint32) // SequenceAck returns the sequence ack number. SequenceAck() uint32 // SetSequenceAck sets the sequence ack number. SetSequenceAck(seq uint32) // SequenceTime returns the sequence time. SequenceTime() time.Time // SetSequenceTime sets the sequence time. SetSequenceTime(t time.Time) // SrcIP returns the frame source IP. SrcIP() netip.Addr // DstIP returns the frame destination IP. DstIP() netip.Addr // SwitchBlock returns the switch block. SwitchBlock() []byte // SetSwitchBlock sets the switch block. // It must be the same size as the existing block. SetSwitchBlock(update []byte) error // MessageData returns the message data. MessageData() []byte // MessageDataWithAuth returns the message data, including the auth data. MessageDataWithAuth() []byte // MessageDataWithOffset returns the message data with the given offset. // If you change any of the data, consider the frame invalid. MessageDataWithOffset(offset int) ([]byte, error) // AuthData returns the authentication data. AuthData() []byte // AppendixData returns the appendix data. AppendixData() []byte // SetAppendixData sets the appendix data. SetAppendixData(appendix []byte) error // FrameDataWithMargins returns the whole frame, including the given offset and overhead. FrameDataWithMargins(offset, overhead int) ([]byte, error) // Clone return an exact copy of the frame. Clone() Frame // Seal signs or encrypts the frame using the given session. Seal(s *state.Session) error // Unseal verifies or decrypts the frame using the given session. Unseal(s *state.Session) error // RecvLink returns the receive link. RecvLink() LinkAccessor // SetRecvLink sets the receive link. SetRecvLink(recvLink LinkAccessor) // Reply transforms the frame into a reply. Reply(switchLabels, data, appendixData []byte) error // ReplyTo transforms the frame into a reply with the given src and dst addresses. ReplyTo(src, dst netip.Addr, switchLabels, data, appendixData []byte) error // ReturnToPool returns the frame and the included pooled slice to the pool. ReturnToPool() }
Frame is a common interface to different frame versions.
type FrameV1 ¶
type FrameV1 struct {
// contains filtered or unexported fields
}
FrameV1 is a frame in version 1.
func (*FrameV1) AppendixData ¶
AppendixData returns the appendix data.
func (*FrameV1) FlowControl ¶
FlowControl returns the flow control flag set.
func (*FrameV1) FrameDataWithMargins ¶
FrameDataWithMargins returns the whole frame, including the given offset and overhead.
func (*FrameV1) HasFlowFlag ¶
func (f *FrameV1) HasFlowFlag(flag FlowControlFlag) bool
HasFlowFlag returns whether the given flow control flag is set.
func (*FrameV1) MessageData ¶
MessageData returns the message data.
func (*FrameV1) MessageDataWithAuth ¶
MessageDataWithAuth returns the message data, including the auth data.
func (*FrameV1) MessageDataWithOffset ¶
MessageDataWithOffset returns the message data with the given offset. If you change any of the data, consider the frame invalid.
func (*FrameV1) MessageType ¶
func (f *FrameV1) MessageType() MessageType
MessageType returns the message type.
func (*FrameV1) RecvLink ¶
func (f *FrameV1) RecvLink() LinkAccessor
RecvLink returns the receive link.
func (*FrameV1) ReduceTTL ¶
ReduceTTL reduces the ttl by the given amount. Will not drop below zero.
func (*FrameV1) ReplyTo ¶
ReplyTo transforms the frame into a reply with the given src and dst addresses.
func (*FrameV1) ReturnToPool ¶
func (f *FrameV1) ReturnToPool()
ReturnToPool returns the frame and the included pooled slice to the pool.
func (*FrameV1) SequenceAck ¶
SequenceAck returns the sequence ack number.
func (*FrameV1) SequenceNum ¶
SequenceNum returns the sequence number.
func (*FrameV1) SequenceTime ¶
SequenceTime returns the sequence time.
func (*FrameV1) SetAppendixData ¶
SetAppendixData sets the appendix data.
func (*FrameV1) SetFlowControl ¶
SetFlowControl sets the flow control flag set to the given value.
func (*FrameV1) SetFlowFlag ¶
func (f *FrameV1) SetFlowFlag(flag FlowControlFlag)
SetFlowFlag sets the given flow control flag.
func (*FrameV1) SetMessageType ¶
func (f *FrameV1) SetMessageType(msgType MessageType)
SetMessageType sets the message type.
func (*FrameV1) SetRecvLink ¶
func (f *FrameV1) SetRecvLink(link LinkAccessor)
SetRecvLink sets the receive link.
func (*FrameV1) SetRecvRate ¶
SetRecvRate sets the recv rate.
func (*FrameV1) SetSequenceAck ¶
SetSequenceAck sets the sequence ack number.
func (*FrameV1) SetSequenceNum ¶
SetSequenceNum sets the sequence number.
func (*FrameV1) SetSequenceTime ¶
SetSequenceTime sets the sequence time.
func (*FrameV1) SetSwitchBlock ¶
SetSwitchBlock sets the switch block. It must be the same size as the existing block.
func (*FrameV1) SignRaw ¶
func (f *FrameV1) SignRaw(key ed25519.PrivateKey) error
SignRaw signs the raw frame, with any special handling.
func (*FrameV1) SwitchBlock ¶
SwitchBlock returns the switch block.
type LinkAccessor ¶
type LinkAccessor interface { String() string // Peer returns the ID of the connected peer. Peer() netip.Addr // SwitchLabel returns the switch label of the link. SwitchLabel() m.SwitchLabel // PeeringURL returns the used peering URL. PeeringURL() *m.PeeringURL // Outgoing returns whether the connection was initiated by this router. Outgoing() bool // SendPriority sends a priority frame to the peer. SendPriority(f Frame) error // Send sends a frame to the peer. Send(f Frame) error // LocalAddr returns the underlying local net.Addr of the connection. LocalAddr() net.Addr // RemoteAddr returns the underlying remote net.Addr of the connection. RemoteAddr() net.Addr // Latency returns the latency of the link in milliseconds. Latency() uint16 // FlowControlIndicator returns a flow control flag that indicates the // pressure on the sending queue of this link. FlowControlIndicator() FlowControlFlag // IsClosing returns whether the link is closing or has closed. IsClosing() bool }
LinkAccessor is an interface to access links from a frame.
type MessageClass ¶
type MessageClass uint8
MessageClass is a class of messages with shared attributes.
const ( MessageClassUnknown MessageClass = iota MessageClassSigned MessageClass = iota MessageClassPriorityEncrypted MessageClassEncrypted )
Message Classes.
type MessageType ¶
type MessageType uint8
MessageType designates the message type of a frame.
const ( RouterHopPingDeprecated MessageType = 0 // multicast, priority, signed RouterPing MessageType = 1 // unicast, priority, signed RouterCtrl MessageType = 2 // unicast, priority, encrypted RouterHopPing MessageType = 3 // multicast, priority, signed NetworkTraffic MessageType = 8 // encrypted SessionCtrl MessageType = 16 // priority, encrypted SessionData MessageType = 17 // encrypted )
Message Types.
func (MessageType) Class ¶
func (mt MessageType) Class() MessageClass
Class returns whether the message class.
func (MessageType) IsEncrypted ¶
func (mt MessageType) IsEncrypted() bool
IsEncrypted returns whether the message type is encrypted (instead of signing).
func (MessageType) IsPriority ¶
func (mt MessageType) IsPriority() bool
IsPriority returns whether the message type is prioritized.
func (MessageType) String ¶
func (mt MessageType) String() string