Documentation ¶
Overview ¶
Package kcp - A Fast and Reliable ARQ Protocol
Index ¶
- Constants
- type ACK
- type ACKList
- type AESBlockCrypt
- type BlockCrypt
- func NewAESBlockCrypt(key []byte) (BlockCrypt, error)
- func NewBlowfishBlockCrypt(key []byte) (BlockCrypt, error)
- func NewCast5BlockCrypt(key []byte) (BlockCrypt, error)
- func NewNoneBlockCrypt(key []byte) (BlockCrypt, error)
- func NewSalsa20BlockCrypt(key []byte) (BlockCrypt, error)
- func NewSimpleXORBlockCrypt(key []byte) (BlockCrypt, error)
- func NewTEABlockCrypt(key []byte) (BlockCrypt, error)
- func NewTripleDESBlockCrypt(key []byte) (BlockCrypt, error)
- func NewTwofishBlockCrypt(key []byte) (BlockCrypt, error)
- func NewXTEABlockCrypt(key []byte) (BlockCrypt, error)
- type BlowfishBlockCrypt
- type Cast5BlockCrypt
- type FEC
- type KCP
- func (kcp *KCP) Check(current uint32) uint32
- func (kcp *KCP) Input(data []byte, update_ack bool) int
- func (kcp *KCP) NoDelay(nodelay, interval, resend, nc int) int
- func (kcp *KCP) PeekSize() (length int)
- func (kcp *KCP) Recv(buffer []byte) (n int)
- func (kcp *KCP) Send(buffer []byte) int
- func (kcp *KCP) SetMtu(mtu int) int
- func (kcp *KCP) Update(current uint32)
- func (kcp *KCP) WaitSnd() int
- func (kcp *KCP) WndSize(sndwnd, rcvwnd int) int
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) AcceptKCP() (*UDPSession, error)
- func (l *Listener) Addr() net.Addr
- func (l *Listener) Close() error
- func (l *Listener) SetDSCP(dscp int) error
- func (l *Listener) SetDeadline(t time.Time) error
- func (l *Listener) SetReadBuffer(bytes int) error
- func (l *Listener) SetReadDeadline(t time.Time) error
- func (l *Listener) SetWriteBuffer(bytes int) error
- func (l *Listener) SetWriteDeadline(t time.Time) error
- type NoneBlockCrypt
- type Option
- type OptionWithConvId
- type Output
- type Salsa20BlockCrypt
- type Segment
- type SimpleXORBlockCrypt
- type Snmp
- type TEABlockCrypt
- type TripleDESBlockCrypt
- type TwofishBlockCrypt
- type UDPSession
- func (s *UDPSession) Close() error
- func (s *UDPSession) GetConv() uint32
- func (s *UDPSession) LocalAddr() net.Addr
- func (s *UDPSession) Read(b []byte) (n int, err error)
- func (s *UDPSession) RemoteAddr() net.Addr
- func (s *UDPSession) SetACKNoDelay(nodelay bool)
- func (s *UDPSession) SetDSCP(dscp int) error
- func (s *UDPSession) SetDeadline(t time.Time) error
- func (s *UDPSession) SetKeepAlive(interval int)
- func (s *UDPSession) SetMtu(mtu int)
- func (s *UDPSession) SetNoDelay(nodelay, interval, resend, nc int)
- func (s *UDPSession) SetReadBuffer(bytes int) error
- func (s *UDPSession) SetReadDeadline(t time.Time) error
- func (s *UDPSession) SetStreamMode(enable bool)
- func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
- func (s *UDPSession) SetWriteBuffer(bytes int) error
- func (s *UDPSession) SetWriteDeadline(t time.Time) error
- func (s *UDPSession) Write(b []byte) (n int, err error)
- type XTEABlockCrypt
Constants ¶
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_CMD_WASK = 83 // cmd: window probe (ask) IKCP_CMD_WINS = 84 // cmd: window size (tell) IKCP_ASK_SEND = 1 // need to send IKCP_CMD_WASK IKCP_ASK_TELL = 2 // need to send IKCP_CMD_WINS IKCP_WND_SND = 32 IKCP_WND_RCV = 32 IKCP_MTU_DEF = 1400 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 ¶
This section is empty.
Types ¶
type ACK ¶ added in v1.0.1
type ACK struct {
// contains filtered or unexported fields
}
ACK packet to return
type AESBlockCrypt ¶
type AESBlockCrypt struct {
// contains filtered or unexported fields
}
AESBlockCrypt implements BlockCrypt
func (*AESBlockCrypt) Decrypt ¶
func (c *AESBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*AESBlockCrypt) Encrypt ¶
func (c *AESBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type BlockCrypt ¶
type BlockCrypt interface { // Encrypt encrypts the whole block in src into dst. // Dst and src may point at the same memory. Encrypt(dst, src []byte) // Decrypt decrypts the whole block in src into dst. // Dst and src may point at the same memory. Decrypt(dst, src []byte) }
BlockCrypt defines encryption/decryption methods for a given byte slice
func NewAESBlockCrypt ¶
func NewAESBlockCrypt(key []byte) (BlockCrypt, error)
NewAESBlockCrypt initates BlockCrypt by the given key
func NewBlowfishBlockCrypt ¶
func NewBlowfishBlockCrypt(key []byte) (BlockCrypt, error)
NewBlowfishBlockCrypt initates BlockCrypt by the given key
func NewCast5BlockCrypt ¶
func NewCast5BlockCrypt(key []byte) (BlockCrypt, error)
NewCast5BlockCrypt initates BlockCrypt by the given key
func NewNoneBlockCrypt ¶
func NewNoneBlockCrypt(key []byte) (BlockCrypt, error)
NewNoneBlockCrypt initate by the given key
func NewSalsa20BlockCrypt ¶
func NewSalsa20BlockCrypt(key []byte) (BlockCrypt, error)
NewSalsa20BlockCrypt initates BlockCrypt by the given key
func NewSimpleXORBlockCrypt ¶
func NewSimpleXORBlockCrypt(key []byte) (BlockCrypt, error)
NewSimpleXORBlockCrypt initate BlockCrypt by the given key
func NewTEABlockCrypt ¶
func NewTEABlockCrypt(key []byte) (BlockCrypt, error)
NewTEABlockCrypt initate BlockCrypt by the given key
func NewTripleDESBlockCrypt ¶
func NewTripleDESBlockCrypt(key []byte) (BlockCrypt, error)
NewTripleDESBlockCrypt initates BlockCrypt by the given key
func NewTwofishBlockCrypt ¶
func NewTwofishBlockCrypt(key []byte) (BlockCrypt, error)
NewTwofishBlockCrypt initates BlockCrypt by the given key
func NewXTEABlockCrypt ¶
func NewXTEABlockCrypt(key []byte) (BlockCrypt, error)
NewXTEABlockCrypt initate BlockCrypt by the given key
type BlowfishBlockCrypt ¶
type BlowfishBlockCrypt struct {
// contains filtered or unexported fields
}
BlowfishBlockCrypt implements BlockCrypt
func (*BlowfishBlockCrypt) Decrypt ¶
func (c *BlowfishBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*BlowfishBlockCrypt) Encrypt ¶
func (c *BlowfishBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type Cast5BlockCrypt ¶
type Cast5BlockCrypt struct {
// contains filtered or unexported fields
}
Cast5BlockCrypt implements BlockCrypt
func (*Cast5BlockCrypt) Decrypt ¶
func (c *Cast5BlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*Cast5BlockCrypt) Encrypt ¶
func (c *Cast5BlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type FEC ¶
type FEC struct {
// contains filtered or unexported fields
}
FEC defines forward error correction for packets
type KCP ¶
type KCP struct {
// contains filtered or unexported fields
}
KCP defines a single KCP connection
func NewKCP ¶
NewKCP create a new kcp control object, 'conv' must equal in two endpoint from the same connection.
func (*KCP) Check ¶
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) NoDelay ¶
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) Update ¶
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.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener defines a server listening for connections
func Listen ¶
Listen listens for incoming KCP packets addressed to the local address laddr on the network "udp",
func ListenWithOptions ¶
func ListenWithOptions(laddr string, block BlockCrypt, dataShards, parityShards int) (*Listener, error)
ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption, dataShards, parityShards defines Reed-Solomon Erasure Coding parameters
func (*Listener) Accept ¶
Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.
func (*Listener) AcceptKCP ¶
func (l *Listener) AcceptKCP() (*UDPSession, error)
AcceptKCP accepts a KCP connection
func (*Listener) 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 ¶
Close stops listening on the UDP address. Already Accepted connections are not closed.
func (*Listener) SetDeadline ¶
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
func (*Listener) SetReadBuffer ¶
SetReadBuffer sets the socket read buffer for the Listener
func (*Listener) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
func (*Listener) SetWriteBuffer ¶
SetWriteBuffer sets the socket write buffer for the Listener
type NoneBlockCrypt ¶
type NoneBlockCrypt struct{}
NoneBlockCrypt simple returns the plaintext
func (*NoneBlockCrypt) Decrypt ¶
func (c *NoneBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*NoneBlockCrypt) Encrypt ¶
func (c *NoneBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type OptionWithConvId ¶
type OptionWithConvId struct {
Id uint32
}
OptionWithConvId defines conversation id
type Salsa20BlockCrypt ¶
type Salsa20BlockCrypt struct {
// contains filtered or unexported fields
}
Salsa20BlockCrypt implements BlockCrypt
func (*Salsa20BlockCrypt) Decrypt ¶
func (c *Salsa20BlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*Salsa20BlockCrypt) Encrypt ¶
func (c *Salsa20BlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment defines a KCP segment
type SimpleXORBlockCrypt ¶
type SimpleXORBlockCrypt struct {
// contains filtered or unexported fields
}
SimpleXORBlockCrypt implements BlockCrypt
func (*SimpleXORBlockCrypt) Decrypt ¶
func (c *SimpleXORBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*SimpleXORBlockCrypt) Encrypt ¶
func (c *SimpleXORBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type Snmp ¶
type Snmp struct { BytesSent uint64 // payload bytes sent BytesReceived uint64 MaxConn uint64 ActiveOpens uint64 PassiveOpens uint64 CurrEstab uint64 InErrs uint64 InCsumErrors uint64 // checksum errors InSegs uint64 OutSegs uint64 OutBytes uint64 // udp bytes sent RetransSegs uint64 FastRetransSegs uint64 EarlyRetransSegs uint64 LostSegs uint64 RepeatSegs uint64 FECRecovered uint64 FECErrs uint64 FECSegs uint64 // fec segments received }
Snmp defines network statistics indicator
var DefaultSnmp *Snmp
DefaultSnmp is the global KCP connection statistics collector
type TEABlockCrypt ¶
type TEABlockCrypt struct {
// contains filtered or unexported fields
}
TEABlockCrypt implements BlockCrypt
func (*TEABlockCrypt) Decrypt ¶
func (c *TEABlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*TEABlockCrypt) Encrypt ¶
func (c *TEABlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type TripleDESBlockCrypt ¶
type TripleDESBlockCrypt struct {
// contains filtered or unexported fields
}
TripleDESBlockCrypt implements BlockCrypt
func (*TripleDESBlockCrypt) Decrypt ¶
func (c *TripleDESBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*TripleDESBlockCrypt) Encrypt ¶
func (c *TripleDESBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type TwofishBlockCrypt ¶
type TwofishBlockCrypt struct {
// contains filtered or unexported fields
}
TwofishBlockCrypt implements BlockCrypt
func (*TwofishBlockCrypt) Decrypt ¶
func (c *TwofishBlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*TwofishBlockCrypt) Encrypt ¶
func (c *TwofishBlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface
type UDPSession ¶
type UDPSession struct {
// contains filtered or unexported fields
}
UDPSession defines a KCP session implemented by UDP
func Dial ¶
func Dial(raddr string) (*UDPSession, error)
Dial connects to the remote address "raddr" on the network "udp"
func DialWithOptions ¶
func DialWithOptions(raddr string, block BlockCrypt, dataShards, parityShards int, opts ...Option) (*UDPSession, error)
DialWithOptions connects to the remote address "raddr" on the network "udp" with packet encryption
func (*UDPSession) GetConv ¶
func (s *UDPSession) GetConv() uint32
GetConv gets conversation id of a session
func (*UDPSession) LocalAddr ¶
func (s *UDPSession) 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 (*UDPSession) Read ¶
func (s *UDPSession) Read(b []byte) (n int, err error)
Read implements the Conn Read method.
func (*UDPSession) RemoteAddr ¶
func (s *UDPSession) 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 (*UDPSession) SetACKNoDelay ¶
func (s *UDPSession) SetACKNoDelay(nodelay bool)
SetACKNoDelay changes ack flush option, set true to flush ack immediately,
func (*UDPSession) SetDSCP ¶
func (s *UDPSession) SetDSCP(dscp int) error
SetDSCP sets the 6bit DSCP field of IP header, no effect if it's accepted from Listener
func (*UDPSession) SetDeadline ¶
func (s *UDPSession) SetDeadline(t time.Time) error
SetDeadline sets the deadline associated with the listener. A zero time value disables the deadline.
func (*UDPSession) SetKeepAlive ¶
func (s *UDPSession) SetKeepAlive(interval int)
SetKeepAlive changes per-connection NAT keepalive interval; 0 to disable, default to 10s
func (*UDPSession) SetMtu ¶
func (s *UDPSession) SetMtu(mtu int)
SetMtu sets the maximum transmission unit
func (*UDPSession) SetNoDelay ¶
func (s *UDPSession) SetNoDelay(nodelay, interval, resend, nc int)
SetNoDelay calls nodelay() of kcp
func (*UDPSession) SetReadBuffer ¶
func (s *UDPSession) SetReadBuffer(bytes int) error
SetReadBuffer sets the socket read buffer, no effect if it's accepted from Listener
func (*UDPSession) SetReadDeadline ¶
func (s *UDPSession) SetReadDeadline(t time.Time) error
SetReadDeadline implements the Conn SetReadDeadline method.
func (*UDPSession) SetStreamMode ¶
func (s *UDPSession) SetStreamMode(enable bool)
SetStreamMode toggles the stream mode on/off
func (*UDPSession) SetWindowSize ¶
func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
SetWindowSize set maximum window size
func (*UDPSession) SetWriteBuffer ¶
func (s *UDPSession) SetWriteBuffer(bytes int) error
SetWriteBuffer sets the socket write buffer, no effect if it's accepted from Listener
func (*UDPSession) SetWriteDeadline ¶
func (s *UDPSession) SetWriteDeadline(t time.Time) error
SetWriteDeadline implements the Conn SetWriteDeadline method.
type XTEABlockCrypt ¶
type XTEABlockCrypt struct {
// contains filtered or unexported fields
}
XTEABlockCrypt implements BlockCrypt
func (*XTEABlockCrypt) Decrypt ¶
func (c *XTEABlockCrypt) Decrypt(dst, src []byte)
Decrypt implements Decrypt interface
func (*XTEABlockCrypt) Encrypt ¶
func (c *XTEABlockCrypt) Encrypt(dst, src []byte)
Encrypt implements Encrypt interface