Browse by type
Anyone who has used home broadband from the three major telecom operators in China and needs to connect to other home networks will almost always experience UDP speed restrictions. In order to avoid the QoS targeting UDP by the three major telecom operators, I have developed a tool, named UDP Hop。The principle of this tool is to regularly re-establish a connection automatically, by change the port number and address.
However, UDP Hop can only forwards UDP traffic. In order to forward TCP traffic using UDP, KCP Tube is developed. The reliable retransmission of KCP ensures that the forwarded TCP packets will not be lost.
Another reason why I developed KCP Tube is that other KCP forwarding tools can only forward TCP traffic, but I need to forward UDP traffic as well. This is mainly for the convenience of playing games.
Of course, in fact, both udphop and kcptube were conceived at the same time. So for convenience, KCP Tube was first developed with a framework, and then trimmed into udphop based on KCP Tube. Then the patch code of udphop was merged back into KCP Tube in reverse.
In order to facilitate the use of Full Cone NAT users, when KCP Tube runs in server basic mode, it can use STUN to punch holes, and supports both IPv4 and IPv6.
Just like the purpose of KCP itself, the main goal of KCP Tube is to reduce latency, rather than focusing on transmitting large amounts of data. Can it transmit large amounts of data? Yes, but the effect may not be better than existing TCP forwarding tools.
Currently 3 modes are supported: - Client Mode - Servers Mode - Relay Mode
Reminder: The time of the client must be synchronized with the server and the time difference cannot exceed 255 seconds.
Please refer Wiki Page, or Document Page
You can generate a configuration file by using KCPTube Generator
kcptube config.conf
Example of client mode:
mode=client
kcp=regular3
inbound_bandwidth=500M
outbound_bandwidth=50M
listen_port=59000
destination_port=3000
destination_address=123.45.67.89
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
Example of server mode:
mode=server
kcp=regular3
inbound_bandwidth=1G
outbound_bandwidth=1G
listen_port=3000
destination_port=59000
destination_address=::1
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
stun_server=stun.qq.com
log_path=./
Note: When connecting for the first time, the server will inform the client of its port range. Therefore, the listen_port of the client mode does not necessarily have to be equal to the destination_port of the server mode. The port numbers on both sides can be inconsistent, but the port number range written by the client cannot exceed the port number range of the server to avoid the situation where the client selects the wrong port and cannot connect.
If you want to specify the NIC to listen to, then specify the IP address of the NIC and add a line
listen_on=192.168.1.1
If you want to listen to multiple ports and multiple NICs, just run kcptube with multiple configuration files
kcptube config1.conf config2.conf
If you want to test connectivity before establish connection, just add --try option
kcptube --try config1.conf
or
kcptube config1.conf --try
Use the --check-config option to check the configuration file for errors.
kcptube --check-config config1.conf
or
kcptube config1.conf --check-config
Example of client mode:
mode=client
kcp=regular3
inbound_bandwidth=500M
outbound_bandwidth=50M
listen_port=6000
destination_port=3000-4000
destination_address=123.45.67.89
dport_refresh=600
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
Example of server mode:
mode=server
kcp=regular3
inbound_bandwidth=1G
outbound_bandwidth=1G
listen_port=3000-4000
destination_port=6000
destination_address=::1
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
Example of client mode:
mode=client
kcp=manual
kcp_mtu=1400
kcp_sndwnd=512
kcp_rcvwnd=2048
kcp_nodelay=1
kcp_interval=10
kcp_resend=2
kcp_nc=true
udp_timeout=300
listen_port=6000
destination_port=3000-4000
destination_address=123.45.67.89
dport_refresh=600
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
Example of server mode:
mode=server
kcp=manual
kcp_mtu=1400
kcp_sndwnd=512
kcp_rcvwnd=2048
kcp_nodelay=1
kcp_interval=10
kcp_resend=2
kcp_nc=true
udp_timeout=300
listen_port=3000-4000
destination_port=6000
destination_address=::1
encryption_password=qwerty1234
encryption_algorithm=AES-GCM
| Name | Value | Require | Note |
|---|---|---|---|
| mode | client |
server
relay |Yes|Client Mode
Server Mode
Relay Node Mode| | listen_on | domain name or IP address |No|domain name / IP address only. Multiple addresses should be comma-separated.| | listen_port | 1 - 65535 |Yes|Port ranges can be specified when running as a server mode| | destination_port | 1 - 65535 |Yes|Port ranges can be specified when running as a client mode| | destination_address | IP address, domain name |Yes|Brackets are not required when filling in an IPv6 address. ultiple addresses should be comma-separated.| | destination_dnstxt | Domain name | No |Accepts a single domain name, for client use only. Retrieves the IP address and port from a DNS TXT record. When this parameter is used, destination_address and destination_port are not required.| | dport_refresh | 20 - 65535 |No|The unit is ‘second’. Not writting this option means using the default value of 60 seconds.
1 to 20 is treated as 20 seconds; greater than 32767 is treated as 32767 seconds.
Set to 0 means disable this option.| | encryption_algorithm | XOR
AES-GCM
AES-OCB
chacha20
xchacha20
none |No |XOR Only
AES-256-GCM-AEAD
AES-256-OCB-AEAD
ChaCha20-Poly1305
XChaCha20-Poly1305
No Encryption |
| encryption_password | Any character |Depends…|…on the setting of encryption_algorithm, if the value is set and it is neither none nor XOR, it is required|
| udp_timeout | 0 - 65535 |No|The unit is ‘second’. The default value is 180 seconds, set to 0 to use the default value
This option represents the timeout setting between UDP application ↔ kcptube| | keep_alive | 0 - 65535 |No | The unit is ‘second’. The default value is 0, which means that Keep Alive is disabled. This option refers to Keep Alive between two KCP endpoints.
Can be enabled on any side. If no response is received after 30 seconds, the channel will be closed.| | mux_tunnels | 0 - 65535 |No | The default value is 0, which means that multiplexing is disabled. This option means how many multiplexing tunnels between two KCP endpoints.
Client Mode only.|
| stun_server | STUN Server's address |No| Cannot be used if listen_port option is port range mode|
| update_ipv4 | Path to an executable file | No |Used for processing the public IPv4 address obtained from STUN. See documentation below for details.|
| update_ipv6 | Path to an executable file | No |Used for processing the public IPv6 address obtained from STUN. See documentation below for details.|
| log_path | The directory where the Logs are stored |No|Cannot point to the file itself|
| fec | uint8:uint8 |No|The format is fec=D:R, for example fec=20:4.
Note: The maximum total value of D + R is 255 and cannot exceed this number.
A value of 0 on either side of the colon indicates that the option is not used. Must be the same value on both side.
Please refer to The Usage of FEC|
| mtu | Positive Integer |No|MTU Value of current network, is to automatically calculate the value of kcp_mtu|
| kcp_mtu | Positive Integer |No|This option refers to the length of the data content within a UDP packet.
The value set for this option refers to the value set by calling ikcp_setmtu().
Default value is 1440.| | kcp | manual
fast1 - 6
regular1 - 5
|Yes|Setup Manually
Fast Modes
Regular Speeds
(the number at the end: the smaller the value, the faster the speed)| | kcp_sndwnd | Positive Integer |No|See the table below for default values, which can be overridden individually| | kcp_rcvwnd | Positive Integer |No|See the table below for default values, which can be overridden individually| | kcp_nodelay | Positive Integer |Depends…|…on the setting of ‘kcp=’, if if the value is set as ‘kcp==manual’, this option is required. See the table below for default values.| | kcp_interval | Positive Integer |Depends…|…on the setting of ‘kcp=’, if if the value is set as ‘kcp==manual’, this option is required. See the table below for default values.| | kcp_resend | Positive Integer |Depends…|…on the setting of ‘kcp=’, if if the value is set as ‘kcp==manual’, this option is required. See the table below for default values.| | kcp_nc | yes
true
1
no
false
0 |Depends…|…on the setting of ‘kcp=’, if if the value is set as ‘kcp==manual’, this option is required. See the table below for default values.| | outbound_bandwidth | Positive Integer |No|Outbound bandwidth, used to dynamically update the value of kcp_sndwnd during communication| | inbound_bandwidth | Positive Integer |No|Inbound bandwidth, used to dynamically update the value of kcp_rcvwnd during communication| | ipv4_only | yes
true
1
no
false
0 |No|If the system disables IPv6, this option must be enabled and set to yes or true or 1| | ipv6_only | yes
true
1
no
false
0 |No|Ignore IPv4 address| | blast | yes
true
1
no
false
0 |No|Packets are forwarded as quickly as possible regardless of KCP flow control settings. May lead to overload.| | [listener] | N/A |Yes
(Relay Mode only)|Section Name of Relay Mode, KCP settings for specifying the listening mode
This tag represents data exchanged with the client| | [forwarder] | N/A |Yes
(Relay Mode only)|Section Name of Relay Mode, KCP settings for specifying the forwarding mode
This tag represents data exchanged with the server| | [custom_input] | N/A |No| Section Name of Custom-IP-Mapping Mode, please refer to The Usage of Custom IP Mappings| | [custom_input_tcp] | N/A |No| Section Name of Custom-IP-Mapping Mode, please refer to The Usage of Custom IP Mappings| | [custom_input_udp] | N/A |No| Section Name of Custom-IP-Mapping Mode, please refer to The Usage of Custom IP Mappings|
Note: encryption_algorithm and encryption_password must be consistent at both ends of the communication.
| Name | Value | Require | Note |
|---|---|---|---|
| fib_ingress | 0 - 65535 | No | FIB for ingress connections |
| fib_egress | 0 - 65535 | No | FIB for egress connections |
Available suffixes: K / M / G
The suffix is case-sensitive, uppercase is calculated as binary (1024), lowercase is calculated as decimal (1000).
Entering 1000 represents a bandwidth of 1000 bps
Entering 100k represents a bandwidth of 100 kbps (100000 bps)
Entering 100K represents a bandwidth of 100 Kbps (102400 bps)
Entering 100M represents a bandwidth of 100 Mbps (102400 Kbps)
Entering 1G represents a bandwidth of 1 Gbps (1024 Mbps)
Please note that it is bps (Bits Per Second), not Bps (Bytes Per Second).
This bandwidth values should not larger than your actual bandwidth, otherwise this will cause the sending window to be congested and cause blocking.
Important Notice:
KCPTube will calculate and set the KCP sending window size based on the delay value of the handshake packet and the values of outbound_bandwidth and inbound_bandwidth about 5 seconds after the KCP link is established. Within a period of time after the setup is completed, there is a high chance that the traffic will fluctuate significantly, or even the traffic may suddenly drop to 0, and it will take several seconds to recover.
| Fast Mode | kcp_sndwnd | kcp_rcvwnd | kcp_nodelay | kcp_interval | kcp_resend | kcp_nc |
|---|---|---|---|---|---|---|
| fast1 | 2048 | 2048 | 1 | 1 | 2 | 1 |
| fast2 | 2048 | 2048 | 2 | 1 | 2 | 1 |
| fast3 | 2048 | 2048 | 1 | 1 | 3 | 1 |
| fast4 | 2048 | 2048 | 2 | 1 | 3 | 1 |
| fast5 | 2048 | 2048 | 1 | 1 | 4 | 1 |
| fast6 | 2048 | 2048 | 2 | 1 | 4 | 1 |
| Regular Mode | kcp_sndwnd | kcp_rcvwnd | kcp_nodelay | kcp_interval | kcp_resend | kcp_nc |
|---|---|---|---|---|---|---|
| regular1 | 1024 | 1024 | 1 | 1 | 5 | 1 |
| regular2 | 1024 | 1024 | 2 | 1 | 5 | 1 |
| regular3 | 1024 | 1024 | 0 | 1 | 2 | 1 |
| regular4 | 1024 | 1024 | 0 | 15 | 2 | 1 |
| regular5 | 1024 | 1024 | 0 | 30 | 2 | 1 |
Note: If the packet loss rate is high enough (higner than 10%), kcp_nodelay=1 may better than kcp_nodelay=2. If the packet loss rate is not too high, kcp_nodelay=2 can make the network latency smoother.
$ claude mcp add kcptube \
-- python -m otcore.mcp_server <graph>