kcp

package
v3.50.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package kcp - A Fast and Reliable ARQ Protocol

Acknowledgement:

skywind3000@github for inventing the KCP protocol
xtaci@github for translating to Golang

Index

Constants

View Source
const (
	DataSegmentOverhead = 18
)

Variables

View Source
var (
	ErrIOTimeout        = newError("Read/Write timeout")
	ErrClosedListener   = newError("Listener closed.")
	ErrClosedConnection = newError("Connection closed.")
)

Functions

func DialKCP

func DialKCP(ctx context.Context, dest net.Destination) (internet.Connection, error)

func ListenKCP

func ListenKCP(ctx context.Context, address net.Address, port net.Port, addConn internet.ConnHandler) (internet.Listener, error)

func NewSimpleAuthenticator

func NewSimpleAuthenticator() cipher.AEAD

NewSimpleAuthenticator creates a new SimpleAuthenticator

Types

type AckList

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

func NewAckList

func NewAckList(writer SegmentWriter) *AckList

func (*AckList) Add

func (l *AckList) Add(number uint32, timestamp uint32)

func (*AckList) Clear

func (l *AckList) Clear(una uint32)

func (*AckList) Flush

func (l *AckList) Flush(current uint32, rto uint32)

type AckSegment

type AckSegment struct {
	Conv            uint16
	Option          SegmentOption
	ReceivingWindow uint32
	ReceivingNext   uint32
	Timestamp       uint32
	NumberList      []uint32
}

func NewAckSegment added in v1.24.4

func NewAckSegment() *AckSegment

func (*AckSegment) ByteSize

func (s *AckSegment) ByteSize() int32

func (*AckSegment) Bytes

func (s *AckSegment) Bytes() buf.Supplier

func (*AckSegment) Command

func (*AckSegment) Command() Command

func (*AckSegment) Conversation

func (s *AckSegment) Conversation() uint16

func (*AckSegment) IsEmpty

func (s *AckSegment) IsEmpty() bool

func (*AckSegment) IsFull added in v1.24.4

func (s *AckSegment) IsFull() bool

func (*AckSegment) PutNumber added in v1.24.4

func (s *AckSegment) PutNumber(number uint32)

func (*AckSegment) PutTimestamp added in v1.24.4

func (s *AckSegment) PutTimestamp(timestamp uint32)

func (*AckSegment) Release

func (s *AckSegment) Release()

type CmdOnlySegment

type CmdOnlySegment struct {
	Conv          uint16
	Cmd           Command
	Option        SegmentOption
	SendingNext   uint32
	ReceivingNext uint32
	PeerRTO       uint32
}

func NewCmdOnlySegment added in v1.24.4

func NewCmdOnlySegment() *CmdOnlySegment

func (*CmdOnlySegment) ByteSize

func (*CmdOnlySegment) ByteSize() int32

func (*CmdOnlySegment) Bytes

func (s *CmdOnlySegment) Bytes() buf.Supplier

func (*CmdOnlySegment) Command added in v1.24.4

func (s *CmdOnlySegment) Command() Command

func (*CmdOnlySegment) Conversation

func (s *CmdOnlySegment) Conversation() uint16

func (*CmdOnlySegment) Release

func (*CmdOnlySegment) Release()

type Command added in v1.24.4

type Command byte

Command is a KCP command that indicate the purpose of a Segment.

const (
	// CommandACK indicates an AckSegment.
	CommandACK Command = 0
	// CommandData indicates a DataSegment.
	CommandData Command = 1
	// CommandTerminate indicates that peer terminates the connection.
	CommandTerminate Command = 2
	// CommandPing indicates a ping.
	CommandPing Command = 3
)

type Config

type Config struct {
	Mtu                  *MTU                 `protobuf:"bytes,1,opt,name=mtu,proto3" json:"mtu,omitempty"`
	Tti                  *TTI                 `protobuf:"bytes,2,opt,name=tti,proto3" json:"tti,omitempty"`
	UplinkCapacity       *UplinkCapacity      `protobuf:"bytes,3,opt,name=uplink_capacity,json=uplinkCapacity,proto3" json:"uplink_capacity,omitempty"`
	DownlinkCapacity     *DownlinkCapacity    `protobuf:"bytes,4,opt,name=downlink_capacity,json=downlinkCapacity,proto3" json:"downlink_capacity,omitempty"`
	Congestion           bool                 `protobuf:"varint,5,opt,name=congestion,proto3" json:"congestion,omitempty"`
	WriteBuffer          *WriteBuffer         `protobuf:"bytes,6,opt,name=write_buffer,json=writeBuffer,proto3" json:"write_buffer,omitempty"`
	ReadBuffer           *ReadBuffer          `protobuf:"bytes,7,opt,name=read_buffer,json=readBuffer,proto3" json:"read_buffer,omitempty"`
	HeaderConfig         *serial.TypedMessage `protobuf:"bytes,8,opt,name=header_config,json=headerConfig,proto3" json:"header_config,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func (*Config) Descriptor

func (*Config) Descriptor() ([]byte, []int)

func (*Config) GetCongestion

func (m *Config) GetCongestion() bool

func (*Config) GetDownlinkCapacity

func (m *Config) GetDownlinkCapacity() *DownlinkCapacity

func (*Config) GetDownlinkCapacityValue

func (c *Config) GetDownlinkCapacityValue() uint32

GetDownlinkCapacityValue returns the value of DownlinkCapacity settings.

func (*Config) GetHeaderConfig

func (m *Config) GetHeaderConfig() *serial.TypedMessage

func (*Config) GetMTUValue

func (c *Config) GetMTUValue() uint32

GetMTUValue returns the value of MTU settings.

func (*Config) GetMtu

func (m *Config) GetMtu() *MTU

func (*Config) GetPackerHeader

func (c *Config) GetPackerHeader() (internet.PacketHeader, error)

func (*Config) GetReadBuffer

func (m *Config) GetReadBuffer() *ReadBuffer

func (*Config) GetReadBufferSize

func (c *Config) GetReadBufferSize() uint32

GetReadBufferSize returns the size of ReadBuffer in bytes.

func (*Config) GetReceivingBufferSize

func (c *Config) GetReceivingBufferSize() uint32

func (*Config) GetReceivingInFlightSize

func (c *Config) GetReceivingInFlightSize() uint32

func (*Config) GetSecurity

func (*Config) GetSecurity() (cipher.AEAD, error)

GetSecurity returns the security settings.

func (*Config) GetSendingBufferSize

func (c *Config) GetSendingBufferSize() uint32

func (*Config) GetSendingInFlightSize added in v1.18.2

func (c *Config) GetSendingInFlightSize() uint32

func (*Config) GetTTIValue

func (c *Config) GetTTIValue() uint32

GetTTIValue returns the value of TTI settings.

func (*Config) GetTti

func (m *Config) GetTti() *TTI

func (*Config) GetUplinkCapacity

func (m *Config) GetUplinkCapacity() *UplinkCapacity

func (*Config) GetUplinkCapacityValue

func (c *Config) GetUplinkCapacityValue() uint32

GetUplinkCapacityValue returns the value of UplinkCapacity settings.

func (*Config) GetWriteBuffer

func (m *Config) GetWriteBuffer() *WriteBuffer

func (*Config) GetWriteBufferSize

func (c *Config) GetWriteBufferSize() uint32

GetWriteBufferSize returns the size of WriterBuffer in bytes.

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) Reset

func (m *Config) Reset()

func (*Config) String

func (m *Config) String() string

func (*Config) XXX_DiscardUnknown

func (m *Config) XXX_DiscardUnknown()

func (*Config) XXX_Marshal

func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Config) XXX_Merge

func (m *Config) XXX_Merge(src proto.Message)

func (*Config) XXX_Size

func (m *Config) XXX_Size() int

func (*Config) XXX_Unmarshal

func (m *Config) XXX_Unmarshal(b []byte) error

type ConnMetadata

type ConnMetadata struct {
	LocalAddr    net.Addr
	RemoteAddr   net.Addr
	Conversation uint16
}

type Connection

type Connection struct {
	Config *Config
	// contains filtered or unexported fields
}

Connection is a KCP connection over UDP.

func NewConnection

func NewConnection(meta ConnMetadata, writer PacketWriter, closer io.Closer, config *Config) *Connection

NewConnection create a new KCP connection between local and remote.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the connection.

func (*Connection) Elapsed

func (c *Connection) Elapsed() uint32

func (*Connection) HandleOption added in v1.24.4

func (c *Connection) HandleOption(opt SegmentOption)

func (*Connection) Input added in v1.24.4

func (c *Connection) Input(segments []Segment)

Input when you received a low level packet (eg. UDP packet), call it

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() net.Addr

LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.

func (*Connection) OnPeerClosed added in v1.24.4

func (c *Connection) OnPeerClosed()

func (*Connection) Ping

func (c *Connection) Ping(current uint32, cmd Command)

func (*Connection) Read

func (c *Connection) Read(b []byte) (int, error)

Read implements the Conn Read method.

func (*Connection) ReadMultiBuffer

func (c *Connection) ReadMultiBuffer() (buf.MultiBuffer, error)

ReadMultiBuffer implements buf.Reader.

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() net.Addr

RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.

func (*Connection) SetDeadline

func (c *Connection) SetDeadline(t time.Time) error

SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.

func (*Connection) SetReadDeadline

func (c *Connection) SetReadDeadline(t time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*Connection) SetState added in v1.24.4

func (c *Connection) SetState(state State)

func (*Connection) SetWriteDeadline

func (c *Connection) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*Connection) State added in v1.24.4

func (c *Connection) State() State

func (*Connection) Terminate

func (c *Connection) Terminate()

func (*Connection) Write

func (c *Connection) Write(b []byte) (int, error)

Write implements io.Writer.

func (*Connection) WriteMultiBuffer

func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error

WriteMultiBuffer implements buf.Writer.

type ConnectionID

type ConnectionID struct {
	Remote net.Address
	Port   net.Port
	Conv   uint16
}

type ConnectionReuse

type ConnectionReuse struct {
	Enable               bool     `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ConnectionReuse) Descriptor

func (*ConnectionReuse) Descriptor() ([]byte, []int)

func (*ConnectionReuse) GetEnable

func (m *ConnectionReuse) GetEnable() bool

func (*ConnectionReuse) ProtoMessage

func (*ConnectionReuse) ProtoMessage()

func (*ConnectionReuse) Reset

func (m *ConnectionReuse) Reset()

func (*ConnectionReuse) String

func (m *ConnectionReuse) String() string

func (*ConnectionReuse) XXX_DiscardUnknown

func (m *ConnectionReuse) XXX_DiscardUnknown()

func (*ConnectionReuse) XXX_Marshal

func (m *ConnectionReuse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ConnectionReuse) XXX_Merge

func (m *ConnectionReuse) XXX_Merge(src proto.Message)

func (*ConnectionReuse) XXX_Size

func (m *ConnectionReuse) XXX_Size() int

func (*ConnectionReuse) XXX_Unmarshal

func (m *ConnectionReuse) XXX_Unmarshal(b []byte) error

type DataSegment

type DataSegment struct {
	Conv        uint16
	Option      SegmentOption
	Timestamp   uint32
	Number      uint32
	SendingNext uint32
	// contains filtered or unexported fields
}

func NewDataSegment added in v1.24.4

func NewDataSegment() *DataSegment

func (*DataSegment) ByteSize

func (s *DataSegment) ByteSize() int32

func (*DataSegment) Bytes

func (s *DataSegment) Bytes() buf.Supplier

func (*DataSegment) Command

func (*DataSegment) Command() Command

func (*DataSegment) Conversation

func (s *DataSegment) Conversation() uint16

func (*DataSegment) Data

func (s *DataSegment) Data() *buf.Buffer

func (*DataSegment) Detach

func (s *DataSegment) Detach() *buf.Buffer

func (*DataSegment) Release

func (s *DataSegment) Release()

type DownlinkCapacity

type DownlinkCapacity struct {
	Value                uint32   `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Downlink capacity, in MB.

func (*DownlinkCapacity) Descriptor

func (*DownlinkCapacity) Descriptor() ([]byte, []int)

func (*DownlinkCapacity) GetValue

func (m *DownlinkCapacity) GetValue() uint32

func (*DownlinkCapacity) ProtoMessage

func (*DownlinkCapacity) ProtoMessage()

func (*DownlinkCapacity) Reset

func (m *DownlinkCapacity) Reset()

func (*DownlinkCapacity) String

func (m *DownlinkCapacity) String() string

func (*DownlinkCapacity) XXX_DiscardUnknown

func (m *DownlinkCapacity) XXX_DiscardUnknown()

func (*DownlinkCapacity) XXX_Marshal

func (m *DownlinkCapacity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DownlinkCapacity) XXX_Merge

func (m *DownlinkCapacity) XXX_Merge(src proto.Message)

func (*DownlinkCapacity) XXX_Size

func (m *DownlinkCapacity) XXX_Size() int

func (*DownlinkCapacity) XXX_Unmarshal

func (m *DownlinkCapacity) XXX_Unmarshal(b []byte) error

type KCPPacketReader

type KCPPacketReader struct {
	Security cipher.AEAD
	Header   internet.PacketHeader
}

func (*KCPPacketReader) Read

func (r *KCPPacketReader) Read(b []byte) []Segment

type KCPPacketWriter

type KCPPacketWriter struct {
	Header   internet.PacketHeader
	Security cipher.AEAD
	Writer   io.Writer
}

func (*KCPPacketWriter) Overhead

func (w *KCPPacketWriter) Overhead() int

func (*KCPPacketWriter) Write

func (w *KCPPacketWriter) Write(b []byte) (int, error)

type Listener

type Listener struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Listener defines a server listening for connections

func NewListener

func NewListener(ctx context.Context, address net.Address, port net.Port, addConn internet.ConnHandler) (*Listener, error)

func (*Listener) ActiveConnections added in v1.24.4

func (l *Listener) ActiveConnections() int

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the listener's network address, The Addr returned is shared by all invocations of Addr, so do not modify it.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening on the UDP address. Already Accepted connections are not closed.

func (*Listener) OnReceive

func (l *Listener) OnReceive(payload *buf.Buffer, src net.Destination)

func (*Listener) Remove

func (l *Listener) Remove(id ConnectionID)

type MTU

type MTU struct {
	Value                uint32   `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Maximum Transmission Unit, in bytes.

func (*MTU) Descriptor

func (*MTU) Descriptor() ([]byte, []int)

func (*MTU) GetValue

func (m *MTU) GetValue() uint32

func (*MTU) ProtoMessage

func (*MTU) ProtoMessage()

func (*MTU) Reset

func (m *MTU) Reset()

func (*MTU) String

func (m *MTU) String() string

func (*MTU) XXX_DiscardUnknown

func (m *MTU) XXX_DiscardUnknown()

func (*MTU) XXX_Marshal

func (m *MTU) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*MTU) XXX_Merge

func (m *MTU) XXX_Merge(src proto.Message)

func (*MTU) XXX_Size

func (m *MTU) XXX_Size() int

func (*MTU) XXX_Unmarshal

func (m *MTU) XXX_Unmarshal(b []byte) error

type PacketReader

type PacketReader interface {
	Read([]byte) []Segment
}

type PacketWriter

type PacketWriter interface {
	Overhead() int
	io.Writer
}

type ReadBuffer

type ReadBuffer struct {
	// Buffer size in bytes.
	Size                 uint32   `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ReadBuffer) Descriptor

func (*ReadBuffer) Descriptor() ([]byte, []int)

func (*ReadBuffer) GetSize

func (m *ReadBuffer) GetSize() uint32

func (*ReadBuffer) ProtoMessage

func (*ReadBuffer) ProtoMessage()

func (*ReadBuffer) Reset

func (m *ReadBuffer) Reset()

func (*ReadBuffer) String

func (m *ReadBuffer) String() string

func (*ReadBuffer) XXX_DiscardUnknown

func (m *ReadBuffer) XXX_DiscardUnknown()

func (*ReadBuffer) XXX_Marshal

func (m *ReadBuffer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ReadBuffer) XXX_Merge

func (m *ReadBuffer) XXX_Merge(src proto.Message)

func (*ReadBuffer) XXX_Size

func (m *ReadBuffer) XXX_Size() int

func (*ReadBuffer) XXX_Unmarshal

func (m *ReadBuffer) XXX_Unmarshal(b []byte) error

type ReceivingWindow

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

func NewReceivingWindow

func NewReceivingWindow() *ReceivingWindow

func (*ReceivingWindow) Has

func (w *ReceivingWindow) Has(id uint32) bool

func (*ReceivingWindow) Remove

func (w *ReceivingWindow) Remove(id uint32) *DataSegment

func (*ReceivingWindow) Set

func (w *ReceivingWindow) Set(id uint32, value *DataSegment) bool

type ReceivingWorker

type ReceivingWorker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewReceivingWorker

func NewReceivingWorker(kcp *Connection) *ReceivingWorker

func (*ReceivingWorker) CloseRead

func (*ReceivingWorker) CloseRead()

func (*ReceivingWorker) Flush

func (w *ReceivingWorker) Flush(current uint32)

func (*ReceivingWorker) IsDataAvailable

func (w *ReceivingWorker) IsDataAvailable() bool

func (*ReceivingWorker) NextNumber

func (w *ReceivingWorker) NextNumber() uint32

func (*ReceivingWorker) ProcessSegment

func (w *ReceivingWorker) ProcessSegment(seg *DataSegment)

func (*ReceivingWorker) ProcessSendingNext

func (w *ReceivingWorker) ProcessSendingNext(number uint32)

func (*ReceivingWorker) Read

func (w *ReceivingWorker) Read(b []byte) int

func (*ReceivingWorker) ReadMultiBuffer

func (w *ReceivingWorker) ReadMultiBuffer() buf.MultiBuffer

func (*ReceivingWorker) Release

func (w *ReceivingWorker) Release()

func (*ReceivingWorker) UpdateNecessary

func (w *ReceivingWorker) UpdateNecessary() bool

func (*ReceivingWorker) Write

func (w *ReceivingWorker) Write(seg Segment) error

type RetryableWriter

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

func (*RetryableWriter) Write

func (w *RetryableWriter) Write(seg Segment) error

type RoundTripInfo added in v1.24.4

type RoundTripInfo struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*RoundTripInfo) SmoothedTime added in v1.24.4

func (info *RoundTripInfo) SmoothedTime() uint32

func (*RoundTripInfo) Timeout added in v1.24.4

func (info *RoundTripInfo) Timeout() uint32

func (*RoundTripInfo) Update added in v1.24.4

func (info *RoundTripInfo) Update(rtt uint32, current uint32)

func (*RoundTripInfo) UpdatePeerRTO added in v1.24.4

func (info *RoundTripInfo) UpdatePeerRTO(rto uint32, current uint32)

type Segment added in v1.18.2

type Segment interface {
	Release()
	Conversation() uint16
	Command() Command
	ByteSize() int32
	Bytes() buf.Supplier
	// contains filtered or unexported methods
}

func ReadSegment

func ReadSegment(buf []byte) (Segment, []byte)

type SegmentOption

type SegmentOption byte
const (
	SegmentOptionClose SegmentOption = 1
)

type SegmentWriter

type SegmentWriter interface {
	Write(seg Segment) error
}

func NewRetryableWriter

func NewRetryableWriter(writer SegmentWriter) SegmentWriter

func NewSegmentWriter

func NewSegmentWriter(writer io.Writer) SegmentWriter

type SendingWindow

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

func NewSendingWindow

func NewSendingWindow(writer SegmentWriter, onPacketLoss func(uint32)) *SendingWindow

func (*SendingWindow) Clear

func (sw *SendingWindow) Clear(una uint32)

func (*SendingWindow) FirstNumber

func (sw *SendingWindow) FirstNumber() uint32

func (*SendingWindow) Flush

func (sw *SendingWindow) Flush(current uint32, rto uint32, maxInFlightSize uint32)

func (*SendingWindow) HandleFastAck

func (sw *SendingWindow) HandleFastAck(number uint32, rto uint32)

func (*SendingWindow) IsEmpty added in v1.24.4

func (sw *SendingWindow) IsEmpty() bool

func (*SendingWindow) Len

func (sw *SendingWindow) Len() uint32

func (*SendingWindow) Push

func (sw *SendingWindow) Push(number uint32, b *buf.Buffer)

func (*SendingWindow) Release

func (sw *SendingWindow) Release()

func (*SendingWindow) Remove

func (sw *SendingWindow) Remove(number uint32) bool

func (*SendingWindow) Visit

func (sw *SendingWindow) Visit(visitor func(seg *DataSegment) bool)

type SendingWorker

type SendingWorker struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSendingWorker

func NewSendingWorker(kcp *Connection) *SendingWorker

func (*SendingWorker) CloseWrite

func (w *SendingWorker) CloseWrite()

func (*SendingWorker) FindFirstUnacknowledged

func (w *SendingWorker) FindFirstUnacknowledged()

func (*SendingWorker) FirstUnacknowledged

func (w *SendingWorker) FirstUnacknowledged() uint32

func (*SendingWorker) Flush

func (w *SendingWorker) Flush(current uint32)

func (*SendingWorker) IsEmpty added in v1.24.4

func (w *SendingWorker) IsEmpty() bool

func (*SendingWorker) OnPacketLoss

func (w *SendingWorker) OnPacketLoss(lossRate uint32)

func (*SendingWorker) ProcessReceivingNext

func (w *SendingWorker) ProcessReceivingNext(nextNumber uint32)

func (*SendingWorker) ProcessReceivingNextWithoutLock added in v1.24.4

func (w *SendingWorker) ProcessReceivingNextWithoutLock(nextNumber uint32)

func (*SendingWorker) ProcessSegment added in v1.18.2

func (w *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint32)

func (*SendingWorker) Push

func (w *SendingWorker) Push(mb *buf.MultiBuffer) bool

func (*SendingWorker) Release

func (w *SendingWorker) Release()

func (*SendingWorker) UpdateNecessary

func (w *SendingWorker) UpdateNecessary() bool

func (*SendingWorker) Write

func (w *SendingWorker) Write(seg Segment) error

type SimpleAuthenticator

type SimpleAuthenticator struct{}

SimpleAuthenticator is a legacy AEAD used for KCP encryption.

func (*SimpleAuthenticator) NonceSize

func (*SimpleAuthenticator) NonceSize() int

NonceSize implements cipher.AEAD.NonceSize().

func (*SimpleAuthenticator) Open

func (a *SimpleAuthenticator) Open(dst, nonce, cipherText, extra []byte) ([]byte, error)

Open implements cipher.AEAD.Open().

func (*SimpleAuthenticator) Overhead added in v1.24.4

func (*SimpleAuthenticator) Overhead() int

Overhead implements cipher.AEAD.NonceSize().

func (*SimpleAuthenticator) Seal

func (a *SimpleAuthenticator) Seal(dst, nonce, plain, extra []byte) []byte

Seal implements cipher.AEAD.Seal().

type SimpleSegmentWriter

type SimpleSegmentWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*SimpleSegmentWriter) Write

func (w *SimpleSegmentWriter) Write(seg Segment) error

type State

type State int32

State of the connection

const (
	StateActive          State = 0 // Connection is active
	StateReadyToClose    State = 1 // Connection is closed locally
	StatePeerClosed      State = 2 // Connection is closed on remote
	StateTerminating     State = 3 // Connection is ready to be destroyed locally
	StatePeerTerminating State = 4 // Connection is ready to be destroyed on remote
	StateTerminated      State = 5 // Connection is destroyed.
)

func (State) Is added in v1.24.4

func (s State) Is(states ...State) bool

Is returns true if current State is one of the candidates.

type TTI

type TTI struct {
	Value                uint32   `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Transmission Time Interview, in milli-sec.

func (*TTI) Descriptor

func (*TTI) Descriptor() ([]byte, []int)

func (*TTI) GetValue

func (m *TTI) GetValue() uint32

func (*TTI) ProtoMessage

func (*TTI) ProtoMessage()

func (*TTI) Reset

func (m *TTI) Reset()

func (*TTI) String

func (m *TTI) String() string

func (*TTI) XXX_DiscardUnknown

func (m *TTI) XXX_DiscardUnknown()

func (*TTI) XXX_Marshal

func (m *TTI) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*TTI) XXX_Merge

func (m *TTI) XXX_Merge(src proto.Message)

func (*TTI) XXX_Size

func (m *TTI) XXX_Size() int

func (*TTI) XXX_Unmarshal

func (m *TTI) XXX_Unmarshal(b []byte) error

type Updater

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

func NewUpdater

func NewUpdater(interval uint32, shouldContinue func() bool, shouldTerminate func() bool, updateFunc func()) *Updater

func (*Updater) Interval

func (u *Updater) Interval() time.Duration

func (*Updater) SetInterval

func (u *Updater) SetInterval(d time.Duration)

func (*Updater) WakeUp

func (u *Updater) WakeUp()

type UplinkCapacity

type UplinkCapacity struct {
	Value                uint32   `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

Uplink capacity, in MB.

func (*UplinkCapacity) Descriptor

func (*UplinkCapacity) Descriptor() ([]byte, []int)

func (*UplinkCapacity) GetValue

func (m *UplinkCapacity) GetValue() uint32

func (*UplinkCapacity) ProtoMessage

func (*UplinkCapacity) ProtoMessage()

func (*UplinkCapacity) Reset

func (m *UplinkCapacity) Reset()

func (*UplinkCapacity) String

func (m *UplinkCapacity) String() string

func (*UplinkCapacity) XXX_DiscardUnknown

func (m *UplinkCapacity) XXX_DiscardUnknown()

func (*UplinkCapacity) XXX_Marshal

func (m *UplinkCapacity) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UplinkCapacity) XXX_Merge

func (m *UplinkCapacity) XXX_Merge(src proto.Message)

func (*UplinkCapacity) XXX_Size

func (m *UplinkCapacity) XXX_Size() int

func (*UplinkCapacity) XXX_Unmarshal

func (m *UplinkCapacity) XXX_Unmarshal(b []byte) error

type WriteBuffer

type WriteBuffer struct {
	// Buffer size in bytes.
	Size                 uint32   `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*WriteBuffer) Descriptor

func (*WriteBuffer) Descriptor() ([]byte, []int)

func (*WriteBuffer) GetSize

func (m *WriteBuffer) GetSize() uint32

func (*WriteBuffer) ProtoMessage

func (*WriteBuffer) ProtoMessage()

func (*WriteBuffer) Reset

func (m *WriteBuffer) Reset()

func (*WriteBuffer) String

func (m *WriteBuffer) String() string

func (*WriteBuffer) XXX_DiscardUnknown

func (m *WriteBuffer) XXX_DiscardUnknown()

func (*WriteBuffer) XXX_Marshal

func (m *WriteBuffer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*WriteBuffer) XXX_Merge

func (m *WriteBuffer) XXX_Merge(src proto.Message)

func (*WriteBuffer) XXX_Size

func (m *WriteBuffer) XXX_Size() int

func (*WriteBuffer) XXX_Unmarshal

func (m *WriteBuffer) XXX_Unmarshal(b []byte) error

type Writer

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

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Write

func (w *Writer) Write(payload []byte) (int, error)

Jump to

Keyboard shortcuts

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