Skip to content

KCP

KCP是GOST中的一种数据通道类型。KCP的实现依赖于xtaci/kcp-go库。

示例

gost -L kcp://:8443?kcp.configFile=/path/to/config/file
services:
- name: service-0
  addr: ":8443"
  handler:
    type: auto
  listener:
    type: kcp
    metadata:
      # config file
      kcp.configFile: /path/to/config/file
      # config map
      kcp.config:
        key: "it's a secrect"
        crypt: aes
        mode: fast
        mtu: 1350
        tcp: false
        # ...
      # single config option
      kcp.crypt: aes
      kcp.mode: fast

配置

GOST中内置了一套默认的KCP配置项,默认值与xtaci/kcptun一致。

可以通过kcp.config选项直接指定配置。也可以通过选项kcp.configFile指定外部配置文件,配置文件为JSON格式:

{
    "key": "it's a secrect",
    "crypt": "aes",
    "mode": "fast",
    "mtu" : 1350,
    "sndwnd": 1024,
    "rcvwnd": 1024,
    "datashard": 10,
    "parityshard": 3,
    "dscp": 0,
    "nocomp": false,
    "acknodelay": false,
    "nodelay": 0,
    "interval": 40,
    "resend": 0,
    "nc": 0,
    "smuxver": 1,
    "sockbuf": 4194304,
    "keepalive": 10,
    "snmplog": "",
    "snmpperiod": 60,
    "tcp": false
}

部分参数也可以直接通过选项指定:

kcp.tcp:
config.tcp
kcp.key:
config.key
kcp.crypt:
config.crypt
kcp.mode:
config.mode
kcp.keepalive:
config.keepalive
kcp.interval:
config.interval
kcp.mtu:
config.mtu
kcp.smuxver:
config.smuxver

配置文件中的参数说明请参考kcptun

代理协议

KCP数据通道可以与各种代理协议组合使用。

HTTP Over KCP

gost -L http+kcp://:8443
services:
- name: service-0
  addr: :8443
  handler:
    type: http
  listener:
    type: kcp

SOCKS5 Over KCP

gost -L socks5+kcp://:8443
services:
- name: service-0
  addr: :8443
  handler:
    type: socks5
  listener:
    type: kcp

Relay Over KCP

gost -L relay+kcp://:8443
services:
- name: service-0
  addr: :8443
  handler:
    type: relay
  listener:
    type: kcp

端口转发

KCP通道也可以用作端口转发,相当于在UDP端口转发服务基础上增加KCP传输协议。

服务端

gost -L kcp://:8443/:8080 -L ss://:8080
等同于
gost -L forward+kcp://:8443/:8080 -L ss://:8080

services:
- name: service-0
  addr: :8443
  handler:
    type: forward
  listener:
    type: kcp
  forwarder:
    nodes:
    - name: target-0
      addr: :8080
- name: service-1
  addr: :8080
  handler:
    type: http
  listener:
    type: tcp

通过使用KCP数据通道的端口转发,给8080端口的Shadowsocks代理服务增加了KCP数据通道。

此时8443端口等同于:

gost -L ss+kcp://:8443

Comments