Documentation ¶
Overview ¶
Package kcp - A Fast and Reliable ARQ Protocol
Index ¶
- Constants
- Variables
- func GetUpdaterLen() int
- func SetLogger(l Logger)
- type Client
- type KCP
- func (kcp *KCP) Check() uint32
- func (kcp *KCP) Input(data []byte, regular, ackNoDelay 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
- type Logger
- type Session
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 ¶
var ( Pack_max_len int = 1024 // 单个udp包的最大包长,用于做缓存( 必须 >= kcp_mtu + fec_head_Len) Fec_len int = 6 // fec 冗余册数 3 => p1(x1, x2, x3) Fec_cacheLen uint32 = 256 // fec 序号收到的记录长度 需要大于 kcp的wnd_size Kcp_nodelay int = 1 // kcp的延迟发送 Kcp_interval int = 1 // kcp的刷新间隔 Kcp_resend int = 2 // kcP的重传次数 Kcp_nc int = 1 // kcp的流控 Kcp_mtu int = 256 // kcp输出的单个包的长度 Kcp_wnd_size int = 32 // kcp的窗口的大小 Kcp_update time.Duration = 10 // kcp的update调用时间间隔 Sess_ch_socket_size int = 64 // 会话接收socket数据的通道大小 Sess_ch_send_size int = 64 // 会话发送数据的通道大小 Sess_ch_logic_size int = 32 // 会话投递数据给logic的通道大小 )
Functions ¶
func GetUpdaterLen ¶
func GetUpdaterLen() int
Types ¶
type Client ¶
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) Input ¶
Input when you received a low level packet (eg. UDP packet), call it regular indicates a regular packet has received(not from FEC)
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
}
func Listen ¶
Listen 监听地址的udp包 addr: 监听地址 acceptorNum: 监听协程数(大于1表示启用reuseport) workerPoolNumPerReadConn: 每个监听协程配套的工作池数量
func (*Listener) GetSessionNum ¶
type Logger ¶
type Logger interface { Debugf(v ...interface{}) Infof(v ...interface{}) Warnf(v ...interface{}) Errorf(v ...interface{}) Critif(v ...interface{}) Fatalf(v ...interface{}) }
type Session ¶
type Session struct { ChLogic chan []byte // 抛出数据给逻辑层的通道 // contains filtered or unexported fields }
数据流 send2kcp: kcp=>fec=>socket recv2fec: socket=>fec=>kcp 缓存池流 recv: pop=>chSocket=>fec=>kcp=>push seg: pop=>new=>delete=>push unpack: pop=>unpack=>logic=>push