Versions in this module Expand all Collapse all v0 v0.0.2 Jun 19, 2021 Changes in this version + const DataSegmentOverhead + var ErrClosedConnection = newError("Connection closed.") + var ErrClosedListener = newError("Listener closed.") + var ErrIOTimeout = newError("Read/Write timeout") + func DialKCP(ctx context.Context, dest net.Destination, ...) (internet.Connection, error) + func ListenKCP(ctx context.Context, address net.Address, port net.Port, ...) (internet.Listener, error) + 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 + Tti *TTI + UplinkCapacity *UplinkCapacity + WriteBuffer *WriteBuffer + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*Config) Descriptor() ([]byte, []int) + func (*Config) GetSecurity() (cipher.AEAD, error) + 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) GetSendingBufferSize() uint32 + func (c *Config) GetSendingInFlightSize() uint32 + func (c *Config) GetTTIValue() uint32 + func (c *Config) GetUplinkCapacityValue() uint32 + func (c *Config) GetWriteBufferSize() uint32 + func (m *Config) GetCongestion() bool + func (m *Config) GetDownlinkCapacity() *DownlinkCapacity + func (m *Config) GetHeaderConfig() *serial.TypedMessage + func (m *Config) GetMtu() *MTU + func (m *Config) GetReadBuffer() *ReadBuffer + func (m *Config) GetTti() *TTI + func (m *Config) GetUplinkCapacity() *UplinkCapacity + func (m *Config) GetWriteBuffer() *WriteBuffer + func (m *Config) Reset() + func (m *Config) String() string + func (m *Config) XXX_DiscardUnknown() + func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *Config) XXX_Merge(src proto.Message) + func (m *Config) XXX_Size() int + func (m *Config) XXX_Unmarshal(b []byte) error + 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 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*ConnectionReuse) Descriptor() ([]byte, []int) + func (*ConnectionReuse) ProtoMessage() + func (m *ConnectionReuse) GetEnable() bool + func (m *ConnectionReuse) Reset() + func (m *ConnectionReuse) String() string + func (m *ConnectionReuse) XXX_DiscardUnknown() + func (m *ConnectionReuse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *ConnectionReuse) XXX_Merge(src proto.Message) + func (m *ConnectionReuse) XXX_Size() int + func (m *ConnectionReuse) XXX_Unmarshal(b []byte) error + 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 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*DownlinkCapacity) Descriptor() ([]byte, []int) + func (*DownlinkCapacity) ProtoMessage() + func (m *DownlinkCapacity) GetValue() uint32 + func (m *DownlinkCapacity) Reset() + func (m *DownlinkCapacity) String() string + func (m *DownlinkCapacity) XXX_DiscardUnknown() + func (m *DownlinkCapacity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *DownlinkCapacity) XXX_Merge(src proto.Message) + func (m *DownlinkCapacity) XXX_Size() int + func (m *DownlinkCapacity) XXX_Unmarshal(b []byte) error + 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 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*MTU) Descriptor() ([]byte, []int) + func (*MTU) ProtoMessage() + func (m *MTU) GetValue() uint32 + func (m *MTU) Reset() + func (m *MTU) String() string + func (m *MTU) XXX_DiscardUnknown() + func (m *MTU) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *MTU) XXX_Merge(src proto.Message) + func (m *MTU) XXX_Size() int + func (m *MTU) XXX_Unmarshal(b []byte) error + type PacketReader interface + Read func([]byte) []Segment + type PacketWriter interface + Overhead func() int + type ReadBuffer struct + Size uint32 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*ReadBuffer) Descriptor() ([]byte, []int) + func (*ReadBuffer) ProtoMessage() + func (m *ReadBuffer) GetSize() uint32 + func (m *ReadBuffer) Reset() + func (m *ReadBuffer) String() string + func (m *ReadBuffer) XXX_DiscardUnknown() + func (m *ReadBuffer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *ReadBuffer) XXX_Merge(src proto.Message) + func (m *ReadBuffer) XXX_Size() int + func (m *ReadBuffer) XXX_Unmarshal(b []byte) error + 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 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*TTI) Descriptor() ([]byte, []int) + func (*TTI) ProtoMessage() + func (m *TTI) GetValue() uint32 + func (m *TTI) Reset() + func (m *TTI) String() string + func (m *TTI) XXX_DiscardUnknown() + func (m *TTI) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *TTI) XXX_Merge(src proto.Message) + func (m *TTI) XXX_Size() int + func (m *TTI) XXX_Unmarshal(b []byte) error + 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 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*UplinkCapacity) Descriptor() ([]byte, []int) + func (*UplinkCapacity) ProtoMessage() + func (m *UplinkCapacity) GetValue() uint32 + func (m *UplinkCapacity) Reset() + func (m *UplinkCapacity) String() string + func (m *UplinkCapacity) XXX_DiscardUnknown() + func (m *UplinkCapacity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *UplinkCapacity) XXX_Merge(src proto.Message) + func (m *UplinkCapacity) XXX_Size() int + func (m *UplinkCapacity) XXX_Unmarshal(b []byte) error + type WriteBuffer struct + Size uint32 + XXX_NoUnkeyedLiteral struct{} + XXX_sizecache int32 + XXX_unrecognized []byte + func (*WriteBuffer) Descriptor() ([]byte, []int) + func (*WriteBuffer) ProtoMessage() + func (m *WriteBuffer) GetSize() uint32 + func (m *WriteBuffer) Reset() + func (m *WriteBuffer) String() string + func (m *WriteBuffer) XXX_DiscardUnknown() + func (m *WriteBuffer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) + func (m *WriteBuffer) XXX_Merge(src proto.Message) + func (m *WriteBuffer) XXX_Size() int + func (m *WriteBuffer) XXX_Unmarshal(b []byte) error + type Writer struct + func (w *Writer) Close() error + func (w *Writer) Write(payload []byte) (int, error)