Documentation
¶
Index ¶
- Constants
- Variables
- func NextKeyID(keyID uint8) uint8
- type IncomingReliableState
- type NegotiationState
- type Opcode
- type OutgoingReliableState
- func (s *OutgoingReliableState) HasInFlightPackets() bool
- func (s *OutgoingReliableState) InsertOutgoingPacket(maximumAcknowledgments int, ...) (*Packet, error)
- func (s *OutgoingReliableState) OnIncomingPacket(packet *Packet)
- func (s *OutgoingReliableState) PacketsReadyToSend(now time.Time) []*Packet
- func (s *OutgoingReliableState) PendingAcknowledgmentCount() int
- func (s *OutgoingReliableState) ReturnAcknowledgmentIDs(acknowledgmentIDs []PacketID)
- func (s *OutgoingReliableState) TakeAcknowledgmentIDs(maximumCount int) []PacketID
- type Packet
- type PacketConnection
- type PacketID
- type PeerID
- type SessionID
- type SessionManager
- func (m *SessionManager) CurrentKeyID() uint8
- func (m *SessionManager) LocalSessionID() SessionID
- func (m *SessionManager) NegotiationState() NegotiationState
- func (m *SessionManager) NewAcknowledgmentPacket(acknowledgmentIDs []PacketID) (*Packet, error)
- func (m *SessionManager) NewControlPacket(opcode Opcode, payload []byte) (*Packet, error)
- func (m *SessionManager) NewDataPacketIDs(opcode Opcode, count int) ([]PacketID, error)
- func (m *SessionManager) NewHardResetServerV2Packet(acknowledgmentIDs []PacketID) (*Packet, error)
- func (m *SessionManager) NewRenegotiationSessionManager(keyID uint8) *SessionManager
- func (m *SessionManager) NewSoftResetPacket() (*Packet, error)
- func (m *SessionManager) NextLocalControlPacketID() PacketID
- func (m *SessionManager) RemoteSessionID() (SessionID, bool)
- func (m *SessionManager) SetNegotiationState(state NegotiationState)
- func (m *SessionManager) SetRemoteSessionID(remoteSessionID SessionID)
- func (m *SessionManager) ValidateIncomingLocalSessionID(packet *Packet) bool
- func (m *SessionManager) ValidateIncomingRemoteSessionID(packet *Packet) bool
Constants ¶
const ( SessionIDLength = 8 PacketIDLength = 4 )
const ( ReliableSendBufferSize = 6 ReliableReceiveBufferSize = 12 MaximumAcknowledgmentsPerPacket = 4 AcknowledgmentSetCapacity = 8 InitialRetransmissionTimeout = 2 * time.Second MaximumRetransmissionTimeout = 60 * time.Second RecommendedSenderWakeupPeriod = 60 * time.Second FastRetransmissionACKThreshold = 3 )
const KeyIDMaxValue = 7
Variables ¶
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") )
Functions ¶
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 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 ParsePacket ¶
func ParsePacketView ¶
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 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.