Documentation
¶
Overview ¶
Package qotp provides a linked hash map with O(1) operations and insertion order traversal. All exported methods are thread-safe.
Package qotp provides a sorted map with O(1) Next() traversal. All exported methods are thread-safe.
Index ¶
- Constants
- Variables
- func DecodeRcvWindow(encoded uint8) uint64
- func DecryptPcap(encData []byte, isSenderOnInit bool, epoch uint64, sharedSecret []byte, ...) ([]byte, error)
- func EncodePayload(p *PayloadHeader, userData []byte) (encoded []byte, offset int)
- func EncodeRcvWindow(actualBytes uint64) uint8
- func NestedIterator[K1, K2 comparable, V1, V2 any](outerMap *LinkedMap[K1, V1], getInnerMap func(V1) *LinkedMap[K2, V2], ...) iter.Seq2[V1, V2]
- func PutUint16(b []byte, v uint16) int
- func PutUint24(b []byte, v uint64) int
- func PutUint32(b []byte, v uint32) int
- func PutUint48(b []byte, v uint64) int
- func PutUint64(b []byte, v uint64) int
- func Uint16(b []byte) uint16
- func Uint24(b []byte) uint64
- func Uint32(b []byte) uint32
- func Uint48(b []byte) uint64
- func Uint64(b []byte) uint64
- type Ack
- type AckStatus
- type Conn
- type CryptoMsgType
- type InsertStatus
- type LinkedMap
- func (m *LinkedMap[K, V]) Contains(key K) bool
- func (m *LinkedMap[K, V]) First() (K, V, bool)
- func (m *LinkedMap[K, V]) Get(key K) V
- func (m *LinkedMap[K, V]) Iterator(startKey *K) iter.Seq2[K, V]
- func (m *LinkedMap[K, V]) Next(key K) (K, V, bool)
- func (m *LinkedMap[K, V]) Previous(key K) (K, V, bool)
- func (m *LinkedMap[K, V]) Put(key K, value V)
- func (m *LinkedMap[K, V]) Remove(key K) (V, bool)
- func (m *LinkedMap[K, V]) Replace(oldKey K, newKey K, value V) bool
- func (m *LinkedMap[K, V]) Size() int
- type ListenFunc
- func WithKeyLogWriter(w io.Writer) ListenFunc
- func WithListenAddr(addr string) ListenFunc
- func WithMtu(mtu int) ListenFunc
- func WithNetworkConn(localConn NetworkConn) ListenFunc
- func WithPrvKeyId(prvKeyId *ecdh.PrivateKey) ListenFunc
- func WithSeed(seed [32]byte) ListenFunc
- func WithSeedStr(seedStr string) ListenFunc
- func WithSeedStrHex(seedStrHex string) ListenFunc
- type ListenOption
- type Listener
- func (l *Listener) Close() error
- func (l *Listener) Dial(remoteAddr netip.AddrPort) (*Conn, error)
- func (l *Listener) DialString(remoteAddrString string) (*Conn, error)
- func (l *Listener) DialStringWithCrypto(remoteAddrString string, pubKeyIdRcv *ecdh.PublicKey) (*Conn, error)
- func (l *Listener) DialStringWithCryptoString(remoteAddrString string, pubKeyIdRcvHex string) (*Conn, error)
- func (l *Listener) DialWithCrypto(remoteAddr netip.AddrPort, pubKeyIdRcv *ecdh.PublicKey) (*Conn, error)
- func (l *Listener) Flush(nowNano uint64) (minPacing uint64)
- func (l *Listener) ForceClose(c *Conn)
- func (l *Listener) HasActiveStreams() bool
- func (l *Listener) Listen(timeoutNano uint64, nowNano uint64) (s *Stream, err error)
- func (l *Listener) Loop(callback func(s *Stream) (bool, error))
- func (l *Listener) PubKey() *ecdh.PublicKey
- type Measurements
- type Message
- type NetworkConn
- type PayloadHeader
- type RcvBuffer
- type RcvInsertStatus
- type RcvValue
- type ReceiveBuffer
- func (rb *ReceiveBuffer) Available() int
- func (rb *ReceiveBuffer) Close(streamID uint32, closeOffset uint64)
- func (rb *ReceiveBuffer) EmptyInsert(streamID uint32, offset uint64) RcvInsertStatus
- func (rb *ReceiveBuffer) GetOffsetClosedAt(streamID uint32) (offset *uint64)
- func (rb *ReceiveBuffer) GetSndAck() *Ack
- func (rb *ReceiveBuffer) Insert(streamID uint32, offset uint64, nowNano uint64, userData []byte) RcvInsertStatus
- func (rb *ReceiveBuffer) IsReadyToClose(streamID uint32) bool
- func (rb *ReceiveBuffer) RemoveOldestInOrder(streamID uint32) (data []byte)
- func (rb *ReceiveBuffer) Size() int
- type SendBuffer
- func (sb *SendBuffer) AcknowledgeRange(ack *Ack) (status AckStatus, sentTimeNano uint64)
- func (sb *SendBuffer) CheckStreamFullyAcked(streamID uint32) bool
- func (sb *SendBuffer) Close(streamID uint32)
- func (sb *SendBuffer) GetOffsetAcked(streamID uint32) (offset uint64)
- func (sb *SendBuffer) GetOffsetClosedAt(streamID uint32) (offset *uint64)
- func (sb *SendBuffer) QueueData(streamId uint32, userData []byte) (n int, status InsertStatus)
- func (sb *SendBuffer) QueuePing(streamId uint32)
- func (sb *SendBuffer) ReadyToRetransmit(streamID uint32, ack *Ack, mtu int, expectedRtoNano uint64, ...) (data []byte, offset uint64, isClose bool, err error)
- func (sb *SendBuffer) ReadyToSend(streamID uint32, msgType CryptoMsgType, ack *Ack, mtu int, nowNano uint64) (packetData []byte, offset uint64, isClose bool)
- type SendInfo
- type SortedMap
- func (m *SortedMap[K, V]) Contains(key K) bool
- func (m *SortedMap[K, V]) Get(key K) (V, bool)
- func (m *SortedMap[K, V]) Min() (K, V, bool)
- func (m *SortedMap[K, V]) Next(key K) (K, V, bool)
- func (m *SortedMap[K, V]) Prev(key K) (K, V, bool)
- func (m *SortedMap[K, V]) Put(key K, value V)
- func (m *SortedMap[K, V]) Remove(key K) (V, bool)
- func (m *SortedMap[K, V]) Size() int
- type Stream
- func (s *Stream) Close()
- func (s *Stream) IsCloseRequested() bool
- func (s *Stream) IsClosed() bool
- func (s *Stream) IsOpen() bool
- func (s *Stream) NotifyDataAvailable() error
- func (s *Stream) Ping()
- func (s *Stream) Read() (data []byte, err error)
- func (s *Stream) StreamID() uint32
- func (s *Stream) Write(userData []byte) (n int, err error)
- type StreamBuffer
- type UDPNetworkConn
- func (c *UDPNetworkConn) Close() error
- func (c *UDPNetworkConn) LocalAddrString() string
- func (c *UDPNetworkConn) ReadFromUDPAddrPort(p []byte, timeoutNano uint64, nowNano uint64) (n int, sourceAddress netip.AddrPort, err error)
- func (c *UDPNetworkConn) TimeoutReadNow() error
- func (c *UDPNetworkConn) WriteToUDPAddrPort(b []byte, remoteAddr netip.AddrPort, _ uint64) error
Constants ¶
const ( CryptoVersion = 0 MacSize = 16 SnSize = 6 // Sequence number Size is 48bit / 6 bytes PubKeySize = 32 HeaderSize = 1 ConnIdSize = 8 MsgInitFillLenSize = 2 //MinInitSndSize = minMtu MinInitRcvSizeHdr = HeaderSize + ConnIdSize + (2 * PubKeySize) MinInitCryptoSndSizeHdr = HeaderSize + (2 * PubKeySize) MinInitCryptoRcvSizeHdr = HeaderSize + ConnIdSize + PubKeySize MinDataSizeHdr = HeaderSize + ConnIdSize MinPacketSize = MinDataSizeHdr + FooterDataSize + MinProtoSize )
const ( ProtoVersion = 0 TypeFlag = 5 Offset24or48Flag = 7 MinProtoSize = 8 )
Variables ¶
var ( MinDeadLine = uint64(100 * msNano) ReadDeadLine = uint64(30 * secondNano) // 30 seconds )
Functions ¶
func DecodeRcvWindow ¶
func DecryptPcap ¶ added in v0.2.13
func DecryptPcap(encData []byte, isSenderOnInit bool, epoch uint64, sharedSecret []byte, sharedSecretId []byte) ([]byte, error)
DecryptPcap decrypts any QOTP packet type by auto-detecting the message type. Pass nil for unused secrets based on what you're decrypting.
func EncodePayload ¶
func EncodePayload(p *PayloadHeader, userData []byte) (encoded []byte, offset int)
func EncodeRcvWindow ¶
func NestedIterator ¶
Types ¶
type Conn ¶
type Conn struct {
Measurements
// contains filtered or unexported fields
}
func (*Conn) HasActiveStreams ¶ added in v0.2.17
type CryptoMsgType ¶
type CryptoMsgType int8
const ( InitSnd CryptoMsgType = iota InitRcv InitCryptoSnd InitCryptoRcv Data )
type InsertStatus ¶
type InsertStatus int
const ( InsertStatusOk InsertStatus = iota InsertStatusSndFull InsertStatusNoData )
type LinkedMap ¶
type LinkedMap[K comparable, V any] struct { // contains filtered or unexported fields }
LinkedMap implements a thread-safe hash map with insertion order preservation.
func NewLinkedMap ¶
func NewLinkedMap[K comparable, V any]() *LinkedMap[K, V]
NewLinkedMap creates a new linked hash map.
func (*LinkedMap[K, V]) First ¶
First returns the first inserted key and value in the map. Returns false if the map is empty.
func (*LinkedMap[K, V]) Get ¶
func (m *LinkedMap[K, V]) Get(key K) V
Get retrieves a value from the map. Returns zero value if not found.
func (*LinkedMap[K, V]) Iterator ¶
Iterator returns an iterator for traversing the map in insertion order. Uses Go 1.23+ iter.Seq2 pattern.
func (*LinkedMap[K, V]) Next ¶
Next finds the next key in insertion order after the given key. This is O(1) if the key exists in the map! Returns the next key, its value, and true if a next element exists.
func (*LinkedMap[K, V]) Previous ¶
Previous finds the previous key in insertion order before the given key. Returns the previous key, its value, and true if a previous element exists.
func (*LinkedMap[K, V]) Put ¶
func (m *LinkedMap[K, V]) Put(key K, value V)
Put adds or updates a key-value pair in the map. If key already exists, updates the value but keeps the insertion order position.
func (*LinkedMap[K, V]) Remove ¶
Remove removes a key-value pair from the map. Returns the removed value and true if found.
type ListenFunc ¶
type ListenFunc func(*ListenOption) error
func WithKeyLogWriter ¶ added in v0.2.7
func WithKeyLogWriter(w io.Writer) ListenFunc
WithKeyLogWriter sets a writer for logging session keys in SSLKEYLOGFILE format.
func WithListenAddr ¶
func WithListenAddr(addr string) ListenFunc
func WithMtu ¶
func WithMtu(mtu int) ListenFunc
func WithNetworkConn ¶
func WithNetworkConn(localConn NetworkConn) ListenFunc
func WithPrvKeyId ¶
func WithPrvKeyId(prvKeyId *ecdh.PrivateKey) ListenFunc
func WithSeed ¶
func WithSeed(seed [32]byte) ListenFunc
func WithSeedStr ¶
func WithSeedStr(seedStr string) ListenFunc
func WithSeedStrHex ¶
func WithSeedStrHex(seedStrHex string) ListenFunc
type ListenOption ¶
type ListenOption struct {
// contains filtered or unexported fields
}
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func Listen ¶
func Listen(options ...ListenFunc) (*Listener, error)
func (*Listener) DialStringWithCrypto ¶ added in v0.2.17
func (*Listener) DialStringWithCryptoString ¶ added in v0.2.17
func (*Listener) DialWithCrypto ¶
func (*Listener) ForceClose ¶
func (*Listener) HasActiveStreams ¶ added in v0.2.17
type Measurements ¶
type Measurements struct {
// contains filtered or unexported fields
}
Combined measurement state - both RTT and BBR in one struct
func NewMeasurements ¶
func NewMeasurements() Measurements
NewMeasurements creates a new instance with default values
type NetworkConn ¶
type NetworkConn interface {
ReadFromUDPAddrPort(p []byte, timeoutNano uint64, nowNano uint64) (n int, remoteAddr netip.AddrPort, err error)
TimeoutReadNow() error
WriteToUDPAddrPort(p []byte, remoteAddr netip.AddrPort, nowNano uint64) (err error)
Close() error
LocalAddrString() string
}
func NewUDPNetworkConn ¶
func NewUDPNetworkConn(conn *net.UDPConn) NetworkConn
type PayloadHeader ¶
func DecodePayload ¶
func DecodePayload(data []byte) (payload *PayloadHeader, userData []byte, err error)
type RcvBuffer ¶
type RcvBuffer struct {
// contains filtered or unexported fields
}
func NewRcvBuffer ¶
func NewRcvBuffer() *RcvBuffer
type RcvInsertStatus ¶
type RcvInsertStatus int
const ( RcvInsertOk RcvInsertStatus = iota RcvInsertDuplicate RcvInsertBufferFull )
type ReceiveBuffer ¶
type ReceiveBuffer struct {
// contains filtered or unexported fields
}
func NewReceiveBuffer ¶
func NewReceiveBuffer(capacity int) *ReceiveBuffer
func (*ReceiveBuffer) Available ¶
func (rb *ReceiveBuffer) Available() int
func (*ReceiveBuffer) Close ¶
func (rb *ReceiveBuffer) Close(streamID uint32, closeOffset uint64)
func (*ReceiveBuffer) EmptyInsert ¶
func (rb *ReceiveBuffer) EmptyInsert(streamID uint32, offset uint64) RcvInsertStatus
func (*ReceiveBuffer) GetOffsetClosedAt ¶
func (rb *ReceiveBuffer) GetOffsetClosedAt(streamID uint32) (offset *uint64)
func (*ReceiveBuffer) GetSndAck ¶
func (rb *ReceiveBuffer) GetSndAck() *Ack
func (*ReceiveBuffer) Insert ¶
func (rb *ReceiveBuffer) Insert(streamID uint32, offset uint64, nowNano uint64, userData []byte) RcvInsertStatus
func (*ReceiveBuffer) IsReadyToClose ¶ added in v0.2.17
func (rb *ReceiveBuffer) IsReadyToClose(streamID uint32) bool
func (*ReceiveBuffer) RemoveOldestInOrder ¶
func (rb *ReceiveBuffer) RemoveOldestInOrder(streamID uint32) (data []byte)
func (*ReceiveBuffer) Size ¶
func (rb *ReceiveBuffer) Size() int
type SendBuffer ¶
type SendBuffer struct {
// contains filtered or unexported fields
}
func NewSendBuffer ¶
func NewSendBuffer(capacity int) *SendBuffer
func (*SendBuffer) AcknowledgeRange ¶
func (sb *SendBuffer) AcknowledgeRange(ack *Ack) (status AckStatus, sentTimeNano uint64)
AcknowledgeRange handles acknowledgment of dataToSend
func (*SendBuffer) CheckStreamFullyAcked ¶ added in v0.2.19
func (sb *SendBuffer) CheckStreamFullyAcked(streamID uint32) bool
func (*SendBuffer) Close ¶
func (sb *SendBuffer) Close(streamID uint32)
func (*SendBuffer) GetOffsetAcked ¶
func (sb *SendBuffer) GetOffsetAcked(streamID uint32) (offset uint64)
func (*SendBuffer) GetOffsetClosedAt ¶
func (sb *SendBuffer) GetOffsetClosedAt(streamID uint32) (offset *uint64)
func (*SendBuffer) QueueData ¶
func (sb *SendBuffer) QueueData(streamId uint32, userData []byte) (n int, status InsertStatus)
QueueData stores the userData in the dataMap, does not send yet
func (*SendBuffer) QueuePing ¶
func (sb *SendBuffer) QueuePing(streamId uint32)
func (*SendBuffer) ReadyToRetransmit ¶
func (sb *SendBuffer) ReadyToRetransmit(streamID uint32, ack *Ack, mtu int, expectedRtoNano uint64, msgType CryptoMsgType, nowNano uint64) ( data []byte, offset uint64, isClose bool, err error)
ReadyToRetransmit finds expired dataInFlightMap that need to be resent
func (*SendBuffer) ReadyToSend ¶
func (sb *SendBuffer) ReadyToSend(streamID uint32, msgType CryptoMsgType, ack *Ack, mtu int, nowNano uint64) ( packetData []byte, offset uint64, isClose bool)
ReadyToSend gets data from dataToSend and creates an entry in dataInFlightMap
type SortedMap ¶
SortedMap implements a thread-safe skip list with O(1) lookups and O(1) Next() operations.
func NewSortedMap ¶
NewSortedMap creates a new sorted map with the given key comparison function.
func (*SortedMap[K, V]) Get ¶
Get retrieves a value from the map. Returns the value and a boolean indicating if the key was found.
func (*SortedMap[K, V]) Min ¶
Min returns the smallest key and value in the map. Returns the key, value, and a boolean indicating if the map is not empty.
func (*SortedMap[K, V]) Next ¶
Next finds the next key that is strictly greater than the given key. This is now O(1) if the key exists in the map! Returns the next key, its value, and a boolean indicating if a next element exists.
func (*SortedMap[K, V]) Prev ¶
Prev finds the previous key that is strictly smaller than the given key. This is O(1) if the key exists in the map! Returns the previous key, its value, and a boolean indicating if a previous element exists.
func (*SortedMap[K, V]) Put ¶
func (m *SortedMap[K, V]) Put(key K, value V)
Put adds or updates a key-value pair in the map.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func (*Stream) IsCloseRequested ¶
func (*Stream) NotifyDataAvailable ¶
type StreamBuffer ¶
type StreamBuffer struct {
// contains filtered or unexported fields
}
StreamBuffer represents a single stream's userData and metadata
func NewStreamBuffer ¶
func NewStreamBuffer() *StreamBuffer
type UDPNetworkConn ¶
type UDPNetworkConn struct {
// contains filtered or unexported fields
}
func (*UDPNetworkConn) Close ¶
func (c *UDPNetworkConn) Close() error
func (*UDPNetworkConn) LocalAddrString ¶
func (c *UDPNetworkConn) LocalAddrString() string
func (*UDPNetworkConn) ReadFromUDPAddrPort ¶
func (*UDPNetworkConn) TimeoutReadNow ¶
func (c *UDPNetworkConn) TimeoutReadNow() error
TimeoutReadNow cancels any pending Read operation by setting the read deadline to a past time, causing it to return immediately with a timeout error.
Call this when a write is ready in another goroutine to unblock the reader and allow the connection to switch from read mode to write mode.