Versions in this module Expand all Collapse all v1 v1.8.7 Dec 27, 2023 v1.0.0 Dec 27, 2023 Changes in this version + const DataSegmentOverhead + var ErrClosedConnection = newError("Connection closed.") + var ErrClosedListener = newError("Listener closed.") + var ErrIOTimeout = newError("Read/Write timeout") + var File_transport_internet_kcp_config_proto protoreflect.FileDescriptor + func DialKCP(ctx context.Context, dest net.Destination, ...) (stat.Connection, error) + func ListenKCP(ctx context.Context, address net.Address, port net.Port, ...) (internet.Listener, error) + func NewAEADAESGCMBasedOnSeed(seed string) cipher.AEAD + func NewSimpleAuthenticator() cipher.AEAD + type AckList struct + func NewAckList(writer SegmentWriter) *AckList + func (l *AckList) Add(number uint32, timestamp uint32) + func (l *AckList) Clear(una uint32) + func (l *AckList) Flush(current uint32, rto uint32) + type AckSegment struct + Conv uint16 + NumberList []uint32 + Option SegmentOption + ReceivingNext uint32 + ReceivingWindow uint32 + Timestamp uint32 + func NewAckSegment() *AckSegment + func (*AckSegment) Command() Command + func (s *AckSegment) ByteSize() int32 + func (s *AckSegment) Conversation() uint16 + func (s *AckSegment) IsEmpty() bool + func (s *AckSegment) IsFull() bool + func (s *AckSegment) PutNumber(number uint32) + func (s *AckSegment) PutTimestamp(timestamp uint32) + func (s *AckSegment) Release() + func (s *AckSegment) Serialize(b []byte) + type CmdOnlySegment struct + Cmd Command + Conv uint16 + Option SegmentOption + PeerRTO uint32 + ReceivingNext uint32 + SendingNext uint32 + func NewCmdOnlySegment() *CmdOnlySegment + func (*CmdOnlySegment) ByteSize() int32 + func (*CmdOnlySegment) Release() + func (s *CmdOnlySegment) Command() Command + func (s *CmdOnlySegment) Conversation() uint16 + func (s *CmdOnlySegment) Serialize(b []byte) + type Command byte + const CommandACK + const CommandData + const CommandPing + const CommandTerminate + type Config struct + Congestion bool + DownlinkCapacity *DownlinkCapacity + HeaderConfig *serial.TypedMessage + Mtu *MTU + ReadBuffer *ReadBuffer + Seed *EncryptionSeed + Tti *TTI + UplinkCapacity *UplinkCapacity + WriteBuffer *WriteBuffer + func (*Config) Descriptor() ([]byte, []int) + func (*Config) ProtoMessage() + func (c *Config) GetDownlinkCapacityValue() uint32 + func (c *Config) GetMTUValue() uint32 + func (c *Config) GetPackerHeader() (internet.PacketHeader, error) + func (c *Config) GetReadBufferSize() uint32 + func (c *Config) GetReceivingBufferSize() uint32 + func (c *Config) GetReceivingInFlightSize() uint32 + func (c *Config) GetSecurity() (cipher.AEAD, error) + func (c *Config) GetSendingBufferSize() uint32 + func (c *Config) GetSendingInFlightSize() uint32 + func (c *Config) GetTTIValue() uint32 + func (c *Config) GetUplinkCapacityValue() uint32 + func (c *Config) GetWriteBufferSize() uint32 + func (x *Config) GetCongestion() bool + func (x *Config) GetDownlinkCapacity() *DownlinkCapacity + func (x *Config) GetHeaderConfig() *serial.TypedMessage + func (x *Config) GetMtu() *MTU + func (x *Config) GetReadBuffer() *ReadBuffer + func (x *Config) GetSeed() *EncryptionSeed + func (x *Config) GetTti() *TTI + func (x *Config) GetUplinkCapacity() *UplinkCapacity + func (x *Config) GetWriteBuffer() *WriteBuffer + func (x *Config) ProtoReflect() protoreflect.Message + func (x *Config) Reset() + func (x *Config) String() string + type ConnMetadata struct + Conversation uint16 + LocalAddr net.Addr + RemoteAddr net.Addr + type Connection struct + Config *Config + func NewConnection(meta ConnMetadata, writer PacketWriter, closer io.Closer, config *Config) *Connection + func (c *Connection) Close() error + func (c *Connection) Elapsed() uint32 + func (c *Connection) HandleOption(opt SegmentOption) + func (c *Connection) Input(segments []Segment) + func (c *Connection) LocalAddr() net.Addr + func (c *Connection) OnPeerClosed() + func (c *Connection) Ping(current uint32, cmd Command) + func (c *Connection) Read(b []byte) (int, error) + func (c *Connection) ReadMultiBuffer() (buf.MultiBuffer, error) + func (c *Connection) RemoteAddr() net.Addr + func (c *Connection) SetDeadline(t time.Time) error + func (c *Connection) SetReadDeadline(t time.Time) error + func (c *Connection) SetState(state State) + func (c *Connection) SetWriteDeadline(t time.Time) error + func (c *Connection) State() State + func (c *Connection) Terminate() + func (c *Connection) Write(b []byte) (int, error) + func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error + type ConnectionID struct + Conv uint16 + Port net.Port + Remote net.Address + type ConnectionReuse struct + Enable bool + func (*ConnectionReuse) Descriptor() ([]byte, []int) + func (*ConnectionReuse) ProtoMessage() + func (x *ConnectionReuse) GetEnable() bool + func (x *ConnectionReuse) ProtoReflect() protoreflect.Message + func (x *ConnectionReuse) Reset() + func (x *ConnectionReuse) String() string + type DataSegment struct + Conv uint16 + Number uint32 + Option SegmentOption + SendingNext uint32 + Timestamp uint32 + func NewDataSegment() *DataSegment + func (*DataSegment) Command() Command + func (s *DataSegment) ByteSize() int32 + func (s *DataSegment) Conversation() uint16 + func (s *DataSegment) Data() *buf.Buffer + func (s *DataSegment) Detach() *buf.Buffer + func (s *DataSegment) Release() + func (s *DataSegment) Serialize(b []byte) + type DownlinkCapacity struct + Value uint32 + func (*DownlinkCapacity) Descriptor() ([]byte, []int) + func (*DownlinkCapacity) ProtoMessage() + func (x *DownlinkCapacity) GetValue() uint32 + func (x *DownlinkCapacity) ProtoReflect() protoreflect.Message + func (x *DownlinkCapacity) Reset() + func (x *DownlinkCapacity) String() string + type EncryptionSeed struct + Seed string + func (*EncryptionSeed) Descriptor() ([]byte, []int) + func (*EncryptionSeed) ProtoMessage() + func (x *EncryptionSeed) GetSeed() string + func (x *EncryptionSeed) ProtoReflect() protoreflect.Message + func (x *EncryptionSeed) Reset() + func (x *EncryptionSeed) String() string + type KCPPacketReader struct + Header internet.PacketHeader + Security cipher.AEAD + func (r *KCPPacketReader) Read(b []byte) []Segment + type KCPPacketWriter struct + Header internet.PacketHeader + Security cipher.AEAD + Writer io.Writer + func (w *KCPPacketWriter) Overhead() int + func (w *KCPPacketWriter) Write(b []byte) (int, error) + type Listener struct + func NewListener(ctx context.Context, address net.Address, port net.Port, ...) (*Listener, error) + func (l *Listener) ActiveConnections() int + func (l *Listener) Addr() net.Addr + func (l *Listener) Close() error + func (l *Listener) OnReceive(payload *buf.Buffer, src net.Destination) + func (l *Listener) Remove(id ConnectionID) + type MTU struct + Value uint32 + func (*MTU) Descriptor() ([]byte, []int) + func (*MTU) ProtoMessage() + func (x *MTU) GetValue() uint32 + func (x *MTU) ProtoReflect() protoreflect.Message + func (x *MTU) Reset() + func (x *MTU) String() string + type PacketReader interface + Read func([]byte) []Segment + type PacketWriter interface + Overhead func() int + type ReadBuffer struct + Size uint32 + func (*ReadBuffer) Descriptor() ([]byte, []int) + func (*ReadBuffer) ProtoMessage() + func (x *ReadBuffer) GetSize() uint32 + func (x *ReadBuffer) ProtoReflect() protoreflect.Message + func (x *ReadBuffer) Reset() + func (x *ReadBuffer) String() string + type ReceivingWindow struct + func NewReceivingWindow() *ReceivingWindow + func (w *ReceivingWindow) Has(id uint32) bool + func (w *ReceivingWindow) Remove(id uint32) *DataSegment + func (w *ReceivingWindow) Set(id uint32, value *DataSegment) bool + type ReceivingWorker struct + func NewReceivingWorker(kcp *Connection) *ReceivingWorker + func (*ReceivingWorker) CloseRead() + func (w *ReceivingWorker) Flush(current uint32) + func (w *ReceivingWorker) IsDataAvailable() bool + func (w *ReceivingWorker) NextNumber() uint32 + func (w *ReceivingWorker) ProcessSegment(seg *DataSegment) + func (w *ReceivingWorker) ProcessSendingNext(number uint32) + func (w *ReceivingWorker) Read(b []byte) int + func (w *ReceivingWorker) ReadMultiBuffer() buf.MultiBuffer + func (w *ReceivingWorker) Release() + func (w *ReceivingWorker) UpdateNecessary() bool + func (w *ReceivingWorker) Write(seg Segment) error + type RetryableWriter struct + func (w *RetryableWriter) Write(seg Segment) error + type RoundTripInfo struct + func (info *RoundTripInfo) SmoothedTime() uint32 + func (info *RoundTripInfo) Timeout() uint32 + func (info *RoundTripInfo) Update(rtt uint32, current uint32) + func (info *RoundTripInfo) UpdatePeerRTO(rto uint32, current uint32) + type Segment interface + ByteSize func() int32 + Command func() Command + Conversation func() uint16 + Release func() + Serialize func([]byte) + func ReadSegment(buf []byte) (Segment, []byte) + type SegmentOption byte + const SegmentOptionClose + type SegmentWriter interface + Write func(seg Segment) error + func NewRetryableWriter(writer SegmentWriter) SegmentWriter + func NewSegmentWriter(writer io.Writer) SegmentWriter + type SendingWindow struct + func NewSendingWindow(writer SegmentWriter, onPacketLoss func(uint32)) *SendingWindow + func (sw *SendingWindow) Clear(una uint32) + func (sw *SendingWindow) FirstNumber() uint32 + func (sw *SendingWindow) Flush(current uint32, rto uint32, maxInFlightSize uint32) + func (sw *SendingWindow) HandleFastAck(number uint32, rto uint32) + func (sw *SendingWindow) IsEmpty() bool + func (sw *SendingWindow) Len() uint32 + func (sw *SendingWindow) Push(number uint32, b *buf.Buffer) + func (sw *SendingWindow) Release() + func (sw *SendingWindow) Remove(number uint32) bool + func (sw *SendingWindow) Visit(visitor func(seg *DataSegment) bool) + type SendingWorker struct + func NewSendingWorker(kcp *Connection) *SendingWorker + func (w *SendingWorker) CloseWrite() + func (w *SendingWorker) FindFirstUnacknowledged() + func (w *SendingWorker) FirstUnacknowledged() uint32 + func (w *SendingWorker) Flush(current uint32) + func (w *SendingWorker) IsEmpty() bool + func (w *SendingWorker) OnPacketLoss(lossRate uint32) + func (w *SendingWorker) ProcessReceivingNext(nextNumber uint32) + func (w *SendingWorker) ProcessReceivingNextWithoutLock(nextNumber uint32) + func (w *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint32) + func (w *SendingWorker) Push(b *buf.Buffer) bool + func (w *SendingWorker) Release() + func (w *SendingWorker) UpdateNecessary() bool + func (w *SendingWorker) Write(seg Segment) error + type SimpleAuthenticator struct + func (*SimpleAuthenticator) NonceSize() int + func (*SimpleAuthenticator) Overhead() int + func (a *SimpleAuthenticator) Open(dst, nonce, cipherText, extra []byte) ([]byte, error) + func (a *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte + type SimpleSegmentWriter struct + func (w *SimpleSegmentWriter) Write(seg Segment) error + type State int32 + const StateActive + const StatePeerClosed + const StatePeerTerminating + const StateReadyToClose + const StateTerminated + const StateTerminating + func (s State) Is(states ...State) bool + type TTI struct + Value uint32 + func (*TTI) Descriptor() ([]byte, []int) + func (*TTI) ProtoMessage() + func (x *TTI) GetValue() uint32 + func (x *TTI) ProtoReflect() protoreflect.Message + func (x *TTI) Reset() + func (x *TTI) String() string + type Updater struct + func NewUpdater(interval uint32, shouldContinue func() bool, shouldTerminate func() bool, ...) *Updater + func (u *Updater) Interval() time.Duration + func (u *Updater) SetInterval(d time.Duration) + func (u *Updater) WakeUp() + type UplinkCapacity struct + Value uint32 + func (*UplinkCapacity) Descriptor() ([]byte, []int) + func (*UplinkCapacity) ProtoMessage() + func (x *UplinkCapacity) GetValue() uint32 + func (x *UplinkCapacity) ProtoReflect() protoreflect.Message + func (x *UplinkCapacity) Reset() + func (x *UplinkCapacity) String() string + type WriteBuffer struct + Size uint32 + func (*WriteBuffer) Descriptor() ([]byte, []int) + func (*WriteBuffer) ProtoMessage() + func (x *WriteBuffer) GetSize() uint32 + func (x *WriteBuffer) ProtoReflect() protoreflect.Message + func (x *WriteBuffer) Reset() + func (x *WriteBuffer) String() string + type Writer struct + func (w *Writer) Close() error + func (w *Writer) Write(payload []byte) (int, error)