proto

package
v0.0.0-...-bd912fd Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionIDLength = 8
	PacketIDLength  = 4
)
View Source
const (
	ReliableSendBufferSize          = 6
	ReliableReceiveBufferSize       = 12
	MaximumAcknowledgmentsPerPacket = 4
	AcknowledgmentSetCapacity       = 8
	InitialRetransmissionTimeout    = 2 * time.Second
	MaximumRetransmissionTimeout    = 60 * time.Second
	RecommendedSenderWakeupPeriod   = 60 * time.Second
	FastRetransmissionACKThreshold  = 3
)
View Source
const KeyIDMaxValue = 7

Variables

View Source
var (
	ErrPacketTooLarge = E.New("packet too large")

	// stream_buf_added (socket.c) refuses an encapsulated length below 1 with a
	// link error that restarts the connection.
	ErrBadEncapsulatedPacketLength = E.New("bad encapsulated packet length from peer")
)
View Source
var (
	ErrPacketTooShort  = E.New("packet too short")
	ErrPacketParse     = E.New("packet parse error")
	ErrPacketSerialize = E.New("packet serialize error")
)
View Source
var (
	ErrMissingRemoteSessionID = E.New("missing remote session id")
	ErrPacketIDExpired        = E.New("packet id expired")
	ErrInvalidOpcode          = E.New("invalid opcode for packet creation")
)

Functions

func NextKeyID

func NextKeyID(keyID uint8) uint8

Types

type IncomingReliableState

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

func NewIncomingReliableState

func NewIncomingReliableState() *IncomingReliableState

func (*IncomingReliableState) NextOrderedSequence

func (s *IncomingReliableState) NextOrderedSequence() []*Packet

func (*IncomingReliableState) TryInsertIncomingPacket

func (s *IncomingReliableState) TryInsertIncomingPacket(packet *Packet) bool

type NegotiationState

type NegotiationState int
const (
	NegotiationStateInitial      NegotiationState = 1
	NegotiationStatePreStart     NegotiationState = 2
	NegotiationStateStart        NegotiationState = 3
	NegotiationStateControlReady NegotiationState = 6
)

type Opcode

type Opcode uint8
const (
	OpcodeControlHardResetClientV1 Opcode = iota + 1
	OpcodeControlHardResetServerV1
	OpcodeControlSoftResetV1
	OpcodeControlV1
	OpcodeAcknowledgmentV1
	OpcodeDataV1
	OpcodeControlHardResetClientV2
	OpcodeControlHardResetServerV2
	OpcodeDataV2
	OpcodeControlHardResetClientV3
	OpcodeControlWKCv1
)

func (Opcode) IsControl

func (o Opcode) IsControl() bool

func (Opcode) IsData

func (o Opcode) IsData() bool

func (Opcode) String

func (o Opcode) String() string

type OutgoingReliableState

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

func NewOutgoingReliableState

func NewOutgoingReliableState() *OutgoingReliableState

func (*OutgoingReliableState) HasInFlightPackets

func (s *OutgoingReliableState) HasInFlightPackets() bool

func (*OutgoingReliableState) InsertOutgoingPacket

func (s *OutgoingReliableState) InsertOutgoingPacket(
	maximumAcknowledgments int,
	newPacket func(acknowledgmentIDs []PacketID) (*Packet, error),
) (*Packet, error)

Upstream write_outgoing_tls_ciphertext takes the send buffer slot with reliable_get_buf_output_sequenced, reliable_mark_active_outgoing spends the control packet id on that slot and write_control_auth then moves the acknowledgment ids out of the pending list into the packet, all without releasing the reliable layer in between: no packet id is spent for a packet the send buffer cannot hold, and no acknowledgment id leaves the pending list for a packet which is never built. A full send buffer returns no packet and takes nothing.

func (*OutgoingReliableState) OnIncomingPacket

func (s *OutgoingReliableState) OnIncomingPacket(packet *Packet)

func (*OutgoingReliableState) PacketsReadyToSend

func (s *OutgoingReliableState) PacketsReadyToSend(now time.Time) []*Packet

func (*OutgoingReliableState) PendingAcknowledgmentCount

func (s *OutgoingReliableState) PendingAcknowledgmentCount() int

Upstream reliable_ack_outstanding, which calc_control_channel_frame_overhead reads to size a control packet without consuming anything.

func (*OutgoingReliableState) ReturnAcknowledgmentIDs

func (s *OutgoingReliableState) ReturnAcknowledgmentIDs(acknowledgmentIDs []PacketID)

A packet which never reached the link acknowledges nothing, so the ids it took belong back on the pending list.

func (*OutgoingReliableState) TakeAcknowledgmentIDs

func (s *OutgoingReliableState) TakeAcknowledgmentIDs(maximumCount int) []PacketID

Upstream reliable_ack_write, which removes exactly the ids it wrote into the packet buffer write_control_auth hands to the link.

type Packet

type Packet struct {
	Opcode            Opcode
	KeyID             uint8
	PeerID            PeerID
	LocalSessionID    SessionID
	AcknowledgmentIDs []PacketID
	RemoteSessionID   SessionID
	ID                PacketID
	Payload           []byte
}

func NewPacket

func NewPacket(opcode Opcode, keyID uint8, payload []byte) *Packet

func ParsePacket

func ParsePacket(rawPacket []byte) (*Packet, error)

func ParsePacketView

func ParsePacketView(rawPacket []byte) (*Packet, error)

func (*Packet) Bytes

func (p *Packet) Bytes() ([]byte, error)

type PacketConnection

type PacketConnection interface {
	ReadPacket() ([]byte, error)
	ReadPackets() ([]*buf.Buffer, error)
	WritePacket(packet []byte) error
	WritePackets(packets [][]byte) (int, error)
	WritePacketBuffers(packetBuffers []*buf.Buffer) (int, error)
	SetReadDeadline(deadline time.Time) error
	ConnectionOriented() bool
	Close() error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
}

Upstream io_wait (forward.c) is the only thing that ever waits on the link: process_outgoing_link writes what the event loop already found writable and hands whatever the link refuses to check_status, so no caller of the link carries a write timeout of its own and the link exposes none.

func NewPacketConnection

func NewPacketConnection(connection net.Conn, protocol string) (PacketConnection, error)

type PacketID

type PacketID uint32

type PeerID

type PeerID [3]byte

type SessionID

type SessionID [SessionIDLength]byte

type SessionManager

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

func NewSessionManager

func NewSessionManager() (*SessionManager, error)

func NewSessionManagerWithLocalID

func NewSessionManagerWithLocalID(localSessionID SessionID) *SessionManager

func (*SessionManager) CurrentKeyID

func (m *SessionManager) CurrentKeyID() uint8

func (*SessionManager) LocalSessionID

func (m *SessionManager) LocalSessionID() SessionID

func (*SessionManager) NegotiationState

func (m *SessionManager) NegotiationState() NegotiationState

func (*SessionManager) NewAcknowledgmentPacket

func (m *SessionManager) NewAcknowledgmentPacket(acknowledgmentIDs []PacketID) (*Packet, error)

func (*SessionManager) NewControlPacket

func (m *SessionManager) NewControlPacket(opcode Opcode, payload []byte) (*Packet, error)

func (*SessionManager) NewDataPacketIDs

func (m *SessionManager) NewDataPacketIDs(opcode Opcode, count int) ([]PacketID, error)

func (*SessionManager) NewHardResetServerV2Packet

func (m *SessionManager) NewHardResetServerV2Packet(acknowledgmentIDs []PacketID) (*Packet, error)

func (*SessionManager) NewRenegotiationSessionManager

func (m *SessionManager) NewRenegotiationSessionManager(keyID uint8) *SessionManager

Upstream key_state_init gives each soft-reset key_state fresh packet IDs.

func (*SessionManager) NewSoftResetPacket

func (m *SessionManager) NewSoftResetPacket() (*Packet, error)

Upstream session_move_pre_start sends P_CONTROL_SOFT_RESET_V1 as the initial reliable packet for the new key_state.

func (*SessionManager) NextLocalControlPacketID

func (m *SessionManager) NextLocalControlPacketID() PacketID

func (*SessionManager) RemoteSessionID

func (m *SessionManager) RemoteSessionID() (SessionID, bool)

func (*SessionManager) SetNegotiationState

func (m *SessionManager) SetNegotiationState(state NegotiationState)

func (*SessionManager) SetRemoteSessionID

func (m *SessionManager) SetRemoteSessionID(remoteSessionID SessionID)

func (*SessionManager) ValidateIncomingLocalSessionID

func (m *SessionManager) ValidateIncomingLocalSessionID(packet *Packet) bool

func (*SessionManager) ValidateIncomingRemoteSessionID

func (m *SessionManager) ValidateIncomingRemoteSessionID(packet *Packet) bool

Upstream reliable_ack_read validates RemoteSessionID only when ACKs exist.

Jump to

Keyboard shortcuts

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