kcp

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2016 License: MIT Imports: 15 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 (
	IKCP_RTO_NDL     = 30  // no delay min rto
	IKCP_RTO_MIN     = 100 // normal min rto
	IKCP_RTO_DEF     = 200
	IKCP_RTO_MAX     = 60000
	IKCP_CMD_PUSH    = 81 // cmd: push data
	IKCP_CMD_ACK     = 82 // cmd: ack
	IKCP_WND_SND     = 32
	IKCP_WND_RCV     = 32
	IKCP_MTU_DEF     = 1350
	IKCP_ACK_FAST    = 3
	IKCP_INTERVAL    = 100
	IKCP_OVERHEAD    = 24
	IKCP_DEADLINK    = 20
	IKCP_THRESH_INIT = 2
	IKCP_THRESH_MIN  = 2
	IKCP_PROBE_INIT  = 7000   // 7 secs to probe window size
	IKCP_PROBE_LIMIT = 120000 // up to 120 secs to probe window
)

Variables

This section is empty.

Functions

func DialKCP

func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error)

func ListenKCP

func ListenKCP(address v2net.Address, port v2net.Port) (internet.Listener, error)

Types

type Authenticator added in v1.17.1

type Authenticator interface {
	HeaderSize() int
	// Encrypt encrypts the whole block in src into dst.
	// Dst and src may point at the same memory.
	Seal(buffer *alloc.Buffer)

	// Decrypt decrypts the whole block in src into dst.
	// Dst and src may point at the same memory.
	Open(buffer *alloc.Buffer) bool
}

func NewSimpleAuthenticator

func NewSimpleAuthenticator() Authenticator

type Command

type Command byte
var (
	CommandData      Command = 0
	CommandTerminate Command = 1
)

type Config

type Config struct {
	Mtu              uint32 // Maximum transmission unit
	Tti              uint32
	UplinkCapacity   uint32
	DownlinkCapacity uint32
	Congestion       bool
	WriteBuffer      uint32
}

func DefaultConfig added in v1.17.1

func DefaultConfig() Config

func (*Config) Apply added in v1.17.1

func (this *Config) Apply()

func (*Config) GetReceivingWindowSize added in v1.17.1

func (this *Config) GetReceivingWindowSize() uint32

func (*Config) GetSendingWindowSize added in v1.17.1

func (this *Config) GetSendingWindowSize() uint32

type ConnState added in v1.17.1

type ConnState byte
var (
	ConnStateActive       ConnState = 0
	ConnStateReadyToClose ConnState = 1
	ConnStatePeerClosed   ConnState = 2
	ConnStateClosed       ConnState = 4
)

type Connection

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

Connection is a KCP connection over UDP.

func NewConnection

func NewConnection(conv uint32, writerCloser io.WriteCloser, local *net.UDPAddr, remote *net.UDPAddr, block Authenticator) *Connection

NewConnection create a new KCP connection between local and remote.

func (*Connection) Close

func (this *Connection) Close() error

Close closes the connection.

func (*Connection) Elapsed

func (this *Connection) Elapsed() uint32

func (*Connection) FetchInputFrom added in v1.17.1

func (this *Connection) FetchInputFrom(conn net.Conn)

func (*Connection) ForceTimeout added in v1.17.1

func (this *Connection) ForceTimeout()

func (*Connection) LocalAddr

func (this *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) MarkPeerClose added in v1.17.1

func (this *Connection) MarkPeerClose()

func (*Connection) NotifyTermination added in v1.17.1

func (this *Connection) NotifyTermination()

func (*Connection) Read

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

Read implements the Conn Read method.

func (*Connection) RemoteAddr

func (this *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) Reusable added in v1.17.1

func (this *Connection) Reusable() bool

func (*Connection) SetDeadline

func (this *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 (this *Connection) SetReadDeadline(t time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*Connection) SetReusable added in v1.17.1

func (this *Connection) SetReusable(b bool)

func (*Connection) SetWriteDeadline

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

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*Connection) Terminate

func (this *Connection) Terminate()

func (*Connection) Write

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

Write implements the Conn Write method.

type KCP added in v1.17.1

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

KCP defines a single KCP connection

func NewKCP added in v1.17.1

func NewKCP(conv uint32, mtu uint32, sendingWindowSize uint32, receivingWindowSize uint32, sendingQueueSize uint32, output Output) *KCP

NewKCP create a new kcp control object, 'conv' must equal in two endpoint from the same connection.

func (*KCP) Check added in v1.17.1

func (kcp *KCP) Check(current uint32) uint32

Check determines when should you invoke ikcp_update: returns when you should invoke ikcp_update in millisec, if there is no ikcp_input/_send calling. you can call ikcp_update in that time, instead of call update repeatly. Important to reduce unnacessary ikcp_update invoking. use it to schedule ikcp_update (eg. implementing an epoll-like mechanism, or optimize ikcp_update when handling massive kcp connections)

func (*KCP) ClearSendQueue added in v1.17.2

func (this *KCP) ClearSendQueue()

func (*KCP) DumpReceivingBuf added in v1.17.3

func (kcp *KCP) DumpReceivingBuf()

DumpReceivingBuf moves available data from rcv_buf -> rcv_queue @Private

func (*KCP) Input added in v1.17.1

func (kcp *KCP) Input(data []byte) int

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

func (*KCP) NoDelay added in v1.17.1

func (kcp *KCP) NoDelay(interval uint32, resend int, congestionControl bool) int

NoDelay options fastest: ikcp_nodelay(kcp, 1, 20, 2, 1) nodelay: 0:disable(default), 1:enable interval: internal update timer interval in millisec, default is 100ms resend: 0:disable fast resend(default), 1:enable fast resend nc: 0:normal congestion control(default), 1:disable congestion control

func (*KCP) Recv added in v1.17.1

func (kcp *KCP) Recv(buffer []byte) (n int)

Recv is user/upper level recv: returns size, returns below zero for EAGAIN

func (*KCP) Send added in v1.17.1

func (kcp *KCP) Send(buffer []byte) int

Send is user/upper level send, returns below zero for error

func (*KCP) Update added in v1.17.1

func (kcp *KCP) Update(current uint32)

Update updates state (call it repeatedly, every 10ms-100ms), or you can ask ikcp_check when to call it again (without ikcp_input/_send calling). 'current' - current timestamp in millisec.

func (*KCP) WaitSnd added in v1.17.1

func (kcp *KCP) WaitSnd() uint32

WaitSnd gets how many packet is waiting to be sent

type Listener

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

Listener defines a server listening for connections

func NewListener

func NewListener(address v2net.Address, port v2net.Port) (*Listener, error)

func (*Listener) Accept added in v1.17.1

func (this *Listener) Accept() (internet.Connection, error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

func (*Listener) Addr

func (this *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 (this *Listener) Close() error

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

func (*Listener) OnReceive

func (this *Listener) OnReceive(payload *alloc.Buffer, src v2net.Destination)

func (*Listener) Remove

func (this *Listener) Remove(dest string)

type Option added in v1.17.1

type Option byte
var (
	OptionClose Option = 1
)

type Output added in v1.17.1

type Output func(buf []byte)

Output is a closure which captures conn and calls conn.Write

type ReceivingWindow

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

func NewReceivingWindow

func NewReceivingWindow(size uint32) *ReceivingWindow

func (*ReceivingWindow) Advance added in v1.17.3

func (this *ReceivingWindow) Advance()

func (*ReceivingWindow) Position added in v1.17.3

func (this *ReceivingWindow) Position(idx uint32) uint32

func (*ReceivingWindow) Remove

func (this *ReceivingWindow) Remove(idx uint32) *Segment

func (*ReceivingWindow) RemoveFirst added in v1.17.3

func (this *ReceivingWindow) RemoveFirst() *Segment

func (*ReceivingWindow) Set

func (this *ReceivingWindow) Set(idx uint32, value *Segment) bool

func (*ReceivingWindow) Size added in v1.17.3

func (this *ReceivingWindow) Size() uint32

type Segment

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

Segment defines a KCP segment

func NewSegment added in v1.17.1

func NewSegment() *Segment

NewSegment creates a KCP segment

func (*Segment) Release

func (this *Segment) Release()

type SendingQueue added in v1.17.3

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

func NewSendingQueue added in v1.17.3

func NewSendingQueue(size uint32) *SendingQueue

func (*SendingQueue) Clear added in v1.17.3

func (this *SendingQueue) Clear()

func (*SendingQueue) IsEmpty added in v1.17.3

func (this *SendingQueue) IsEmpty() bool

func (*SendingQueue) IsFull added in v1.17.3

func (this *SendingQueue) IsFull() bool

func (*SendingQueue) Len added in v1.17.3

func (this *SendingQueue) Len() uint32

func (*SendingQueue) Pop added in v1.17.3

func (this *SendingQueue) Pop() *Segment

func (*SendingQueue) Push added in v1.17.3

func (this *SendingQueue) Push(seg *Segment)

type SimpleAuthenticator

type SimpleAuthenticator struct{}

func (*SimpleAuthenticator) HeaderSize added in v1.17.1

func (this *SimpleAuthenticator) HeaderSize() int

func (*SimpleAuthenticator) Open

func (this *SimpleAuthenticator) Open(buffer *alloc.Buffer) bool

func (*SimpleAuthenticator) Seal

func (this *SimpleAuthenticator) Seal(buffer *alloc.Buffer)

type Writer

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

func (*Writer) Close

func (this *Writer) Close() error

func (*Writer) Write

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

Jump to

Keyboard shortcuts

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