mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-09-17 12:44:31 +08:00
Compare commits
45 Commits
v2@2017111
...
place_hold
Author | SHA1 | Date | |
---|---|---|---|
|
abe55c02d5 | ||
|
f96e8c9a94 | ||
|
4d3b713b05 | ||
|
5f0a16cd1f | ||
|
a8ed6c8b5e | ||
|
eaa0e2b54f | ||
|
6a069f7dc2 | ||
|
0348fcedf6 | ||
|
4a4b3dc693 | ||
|
9336246f00 | ||
|
a1d5a3805a | ||
|
baebad1e93 | ||
|
9a23775dfa | ||
|
daab328cf2 | ||
|
0e3dee9920 | ||
|
53e580b876 | ||
|
fd076e0a2e | ||
|
057d5262a4 | ||
|
214d3afa98 | ||
|
cb2e337c94 | ||
|
cf24f76bf8 | ||
|
ec63c61e09 | ||
|
d83ae88716 | ||
|
e5548693df | ||
|
feeb0f1e45 | ||
|
5e6890a52c | ||
|
db7b726987 | ||
|
b0614beffa | ||
|
2dbb26e394 | ||
|
d166432f37 | ||
|
bcdb08691b | ||
|
f6dba6da1f | ||
|
2419801654 | ||
|
5672891485 | ||
|
7f18ccee94 | ||
|
2f0cfe41b1 | ||
|
7081c02171 | ||
|
1c03463a82 | ||
|
b0476f5a3a | ||
|
96fd058985 | ||
|
12c65a4564 | ||
|
36c8a36976 | ||
|
7de806f57a | ||
|
a3b5187b1f | ||
|
ba81aa14d4 |
6
ISSUE_TEMPLATE.md
Normal file
6
ISSUE_TEMPLATE.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
For English speaking user:
|
||||||
|
https://github.com/wangyu-/UDPspeeder/wiki/Issue-Guide
|
||||||
|
|
||||||
|
中文用户请看:
|
||||||
|
https://github.com/wangyu-/UDPspeeder/wiki/发Issue前请看
|
||||||
|
(否则Issue可能被忽略,或被直接关掉)
|
83
README.md
83
README.md
@@ -10,11 +10,22 @@ or
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
Assume your local network to your server is lossy. Just establish a VPN connection to your server with UDPspeeder + any UDP-based VPN, access your server via this VPN connection, then your connection quality will be significantly improved. With well-tuned parameters , you can easily reduce IP or UDP/ICMP packet-loss-rate to less than 0.01% . Besides reducing packet-loss-rate, UDPspeeder can also significantly improve your TCP latency and TCP single-thread download speed.
|
||||||
|
|
||||||
[简体中文](/doc/README.zh-cn.md)(内容更丰富)
|
[简体中文](/doc/README.zh-cn.md)(内容更丰富)
|
||||||
|
|
||||||
###### Note
|
###### Note
|
||||||
You can use udp2raw with UDPspeeder together to bypass UDP firewalls.
|
You can use udp2raw with UDPspeeder together to get better speed on some ISP with UDP QoS(UDP throttling).
|
||||||
udp2raw:https://github.com/wangyu-/udp2raw-tunnel
|
|
||||||
|
udp2raw's repo:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/udp2raw-tunnel
|
||||||
|
|
||||||
|
You can also try tinyFecVPN, a lightweight high-performance VPN with build-in FEC support:
|
||||||
|
|
||||||
|
tinyFecVPN's repo:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN
|
||||||
|
|
||||||
|
|
||||||
# Efficacy
|
# Efficacy
|
||||||
@@ -29,7 +40,7 @@ tested on a link with 100ms latency and 10% packet loss at both direction
|
|||||||
# Supported Platforms
|
# Supported Platforms
|
||||||
Linux host (including desktop Linux,Android phone/tablet, OpenWRT router, or Raspberry PI).
|
Linux host (including desktop Linux,Android phone/tablet, OpenWRT router, or Raspberry PI).
|
||||||
|
|
||||||
For Windows and MacOS You can run UDPspeeder inside [this](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20170918.0/lede-17.01.2-x86_virtual_machine_image_with_udp2raw_pre_installed.zip) 7.5mb virtual machine image.
|
For Windows and MacOS You can run UDPspeeder inside [this](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip) 7.5mb virtual machine image.
|
||||||
|
|
||||||
# How does it work
|
# How does it work
|
||||||
|
|
||||||
@@ -67,60 +78,60 @@ Assume your server ip is 44.55.66.77, you have a service listening on udp port 7
|
|||||||
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd"
|
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd"
|
||||||
```
|
```
|
||||||
|
|
||||||
Now connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side, and the connection is boosted by UDPspeeder.
|
Now connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side, and the connection has been boosted by UDPspeeder.
|
||||||
|
|
||||||
##### Note
|
##### Note
|
||||||
|
|
||||||
`-f20:10` means sending 10 redundant packets for every 20 original packets.
|
`-f20:10` means sending 10 redundant packets for every 20 original packets.
|
||||||
|
|
||||||
`-k` enables simple XOR encryption to confuse DPI(Deep Packet Inspection)
|
`-k` enables simple XOR encryption
|
||||||
|
|
||||||
To run stably, pay attention to MTU.
|
|
||||||
|
|
||||||
# Advanced Topic
|
# Advanced Topic
|
||||||
### Full Options
|
### Full Options
|
||||||
```
|
```
|
||||||
UDPspeeder V2
|
UDPspeeder V2
|
||||||
git version:8e7a8aed92 build date:Oct 25 2017 02:00:54
|
git version: 6f55b8a2fc build date: Nov 19 2017 06:11:23
|
||||||
repository: https://github.com/wangyu-/UDPspeeder
|
repository: https://github.com/wangyu-/UDPspeeder
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
run as client: ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
||||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
run as server: ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
||||||
|
|
||||||
common option,must be same on both sides:
|
common options, must be same on both sides:
|
||||||
-k,--key <string> key for simple xor encryption. if not set,xor is disabled
|
-k,--key <string> key for simple xor encryption. if not set, xor is disabled
|
||||||
main options:
|
main options:
|
||||||
-f,--fec x:y forward error correction,send y redundant packets for every x packets
|
-f,--fec x:y forward error correction, send y redundant packets for every x packets
|
||||||
--timeout <number> how long could a packet be held in queue before doing fec,unit: ms,default :8ms
|
--timeout <number> how long could a packet be held in queue before doing fec, unit: ms, default: 8ms
|
||||||
--mode <number> fec-mode,available values: 0,1 ; 0 cost less bandwidth,1 cost less latency(default)
|
--report <number> turn on send/recv report, and set a period for reporting, unit: s
|
||||||
--report <number> turn on send/recv report,and set a period for reporting,unit:s
|
|
||||||
advanced options:
|
advanced options:
|
||||||
--mtu <number> mtu. for mode 0,the program will split packet to segment smaller than mtu_value.
|
--mode <number> fec-mode,available values: 0,1; mode 0(default) costs less bandwidth,no mtu problem.
|
||||||
for mode 1,no packet will be split,the program just check if the mtu is exceed.
|
mode 1 usually introduces less latency, but you have to care about mtu.
|
||||||
default value:1250
|
--mtu <number> mtu. for mode 0, the program will split packet to segment smaller than mtu value.
|
||||||
-j,--jitter <number> simulated jitter.randomly delay first packet for 0~<number> ms,default value:0.
|
for mode 1, no packet will be split, the program just check if the mtu is exceed.
|
||||||
|
default value: 1250. you typically shouldnt change this value.
|
||||||
|
-q,--queue-len <number> fec queue len, only for mode 0, fec will be performed immediately after queue is full.
|
||||||
|
default value: 200.
|
||||||
|
-j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.
|
||||||
do not use if you dont know what it means.
|
do not use if you dont know what it means.
|
||||||
-i,--interval <number> scatter each fec group to a interval of <number> ms,to protect burst packet loss.
|
-i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.
|
||||||
default value:0.do not use if you dont know what it means.
|
default value: 0. do not use if you dont know what it means.
|
||||||
--random-drop <number> simulate packet loss ,unit:0.01%. default value: 0
|
--random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
|
||||||
--disable-obscure <number> disable obscure,to save a bit bandwidth and cpu
|
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
|
||||||
developer options:
|
developer options:
|
||||||
--fifo <string> use a fifo(named pipe) for sending commands to the running program,so that you
|
--fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you
|
||||||
can change fec encode parameters dynamically,check readme.md in repository for
|
can change fec encode parameters dynamically, check readme.md in repository for
|
||||||
supported commands.
|
supported commands.
|
||||||
-j ,--jitter jmin:jmax similiar to -j above,but create jitter randomly between jmin and jmax
|
-j ,--jitter jmin:jmax similiar to -j above, but create jitter randomly between jmin and jmax
|
||||||
-i,--interval imin:imax similiar to -i above,but scatter randomly between imin and imax
|
-i,--interval imin:imax similiar to -i above, but scatter randomly between imin and imax
|
||||||
-q,--queue-len <number> max fec queue len,only for mode 0
|
--decode-buf <number> size of buffer of fec decoder,u nit: packet, default: 2000
|
||||||
--decode-buf <number> size of buffer of fec decoder,unit:packet,default:2000
|
--fix-latency <number> try to stabilize latency, only for mode 0
|
||||||
--fix-latency <number> try to stabilize latency,only for mode 0
|
|
||||||
--delay-capacity <number> max number of delayed packets
|
--delay-capacity <number> max number of delayed packets
|
||||||
--disable-fec <number> completely disable fec,turn the program into a normal udp tunnel
|
--disable-fec <number> completely disable fec, turn the program into a normal udp tunnel
|
||||||
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
|
--sock-buf <number> buf size for socket, >=10 and <=10240, unit: kbyte, default: 1024
|
||||||
log and help options:
|
log and help options:
|
||||||
--log-level <number> 0:never 1:fatal 2:error 3:warn
|
--log-level <number> 0: never 1: fatal 2: error 3: warn
|
||||||
4:info (default) 5:debug 6:trace
|
4: info (default) 5: debug 6: trace
|
||||||
--log-position enable file name,function name,line number in log
|
--log-position enable file name, function name, line number in log
|
||||||
--disable-color disable log color
|
--disable-color disable log color
|
||||||
-h,--help print this help message
|
-h,--help print this help message
|
||||||
|
|
||||||
|
35
common.cpp
35
common.cpp
@@ -52,7 +52,7 @@ u64_t get_current_time()//ms
|
|||||||
{
|
{
|
||||||
timespec tmp_time;
|
timespec tmp_time;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||||
return tmp_time.tv_sec*1000+tmp_time.tv_nsec/(1000*1000l);
|
return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64_t get_current_time_us()
|
u64_t get_current_time_us()
|
||||||
@@ -260,6 +260,39 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {
|
|||||||
|
|
||||||
return(answer);
|
return(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes) {//works both for big and little endian
|
||||||
|
|
||||||
|
register long sum;
|
||||||
|
unsigned short oddbyte;
|
||||||
|
register short answer;
|
||||||
|
|
||||||
|
sum=0;
|
||||||
|
unsigned short * tmp= (unsigned short *)&ph;
|
||||||
|
for(int i=0;i<6;i++)
|
||||||
|
{
|
||||||
|
sum+=*tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while(nbytes>1) {
|
||||||
|
sum+=*ptr++;
|
||||||
|
nbytes-=2;
|
||||||
|
}
|
||||||
|
if(nbytes==1) {
|
||||||
|
oddbyte=0;
|
||||||
|
*((u_char*)&oddbyte)=*(u_char*)ptr;
|
||||||
|
sum+=oddbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum = (sum>>16)+(sum & 0xffff);
|
||||||
|
sum = sum + (sum>>16);
|
||||||
|
answer=(short)~sum;
|
||||||
|
|
||||||
|
return(answer);
|
||||||
|
}
|
||||||
|
|
||||||
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
||||||
{
|
{
|
||||||
if(force_socket_buf)
|
if(force_socket_buf)
|
||||||
|
25
common.h
25
common.h
@@ -67,10 +67,11 @@ typedef u64_t my_time_t;
|
|||||||
const int max_data_len=2200;
|
const int max_data_len=2200;
|
||||||
const int buf_len=max_data_len+200;
|
const int buf_len=max_data_len+200;
|
||||||
|
|
||||||
const u32_t conv_clear_interval=200;
|
|
||||||
//const u32_t timer_interval=400;
|
//const u32_t timer_interval=400;
|
||||||
////const u32_t conv_timeout=180000;
|
////const u32_t conv_timeout=180000;
|
||||||
const u32_t conv_timeout=40000;//for test
|
//const u32_t conv_timeout=40000;//for test
|
||||||
|
const u32_t conv_timeout=180000;
|
||||||
const int max_conv_num=10000;
|
const int max_conv_num=10000;
|
||||||
const int max_conn_num=200;
|
const int max_conn_num=200;
|
||||||
|
|
||||||
@@ -85,12 +86,12 @@ const u32_t client_retry_interval=1000;
|
|||||||
|
|
||||||
const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively*/
|
const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively*/
|
||||||
|
|
||||||
const int conv_clear_ratio=10; //conv grabage collecter check 1/10 of all conv one time
|
const int conv_clear_ratio=30; //conv grabage collecter check 1/30 of all conv one time
|
||||||
const int conn_clear_ratio=10;
|
const int conn_clear_ratio=50;
|
||||||
const int conv_clear_min=5;
|
const int conv_clear_min=1;
|
||||||
const int conn_clear_min=1;
|
const int conn_clear_min=1;
|
||||||
|
|
||||||
|
const u32_t conv_clear_interval=1000;
|
||||||
const u32_t conn_clear_interval=1000;
|
const u32_t conn_clear_interval=1000;
|
||||||
|
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ const i32_t max_fail_time=0;//disable
|
|||||||
|
|
||||||
const u32_t heartbeat_interval=1000;
|
const u32_t heartbeat_interval=1000;
|
||||||
|
|
||||||
const u32_t timer_interval=500;//this should be smaller than heartbeat_interval and retry interval;
|
const u32_t timer_interval=400;//this should be smaller than heartbeat_interval and retry interval;
|
||||||
|
|
||||||
//const uint32_t conv_timeout=120000; //120 second
|
//const uint32_t conv_timeout=120000; //120 second
|
||||||
//const u32_t conv_timeout=120000; //for test
|
//const u32_t conv_timeout=120000; //for test
|
||||||
@@ -135,7 +136,7 @@ typedef u64_t anti_replay_seq_t;
|
|||||||
typedef u64_t fd64_t;
|
typedef u64_t fd64_t;
|
||||||
|
|
||||||
//enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd64_ip_port_conv,type_fd64_conv/*,type_fd*/};
|
//enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd64_ip_port_conv,type_fd64_conv/*,type_fd*/};
|
||||||
enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd,type_fd_ip_port/*,type_fd*/};
|
enum dest_type{none=0,type_fd64_ip_port,type_fd64,type_fd,type_write_fd,type_fd_ip_port/*,type_fd*/};
|
||||||
|
|
||||||
struct ip_port_t
|
struct ip_port_t
|
||||||
{
|
{
|
||||||
@@ -176,6 +177,13 @@ struct fd_info_t
|
|||||||
ip_port_t ip_port;
|
ip_port_t ip_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct pseudo_header {
|
||||||
|
u_int32_t source_address;
|
||||||
|
u_int32_t dest_address;
|
||||||
|
u_int8_t placeholder;
|
||||||
|
u_int8_t protocol;
|
||||||
|
u_int16_t tcp_length;
|
||||||
|
};
|
||||||
|
|
||||||
u64_t get_current_time();
|
u64_t get_current_time();
|
||||||
u64_t get_current_time_us();
|
u64_t get_current_time_us();
|
||||||
@@ -209,6 +217,7 @@ void setnonblocking(int sock);
|
|||||||
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
|
||||||
|
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes);
|
unsigned short csum(const unsigned short *ptr,int nbytes);
|
||||||
|
unsigned short tcp_csum(const pseudo_header & ph,const unsigned short *ptr,int nbytes);
|
||||||
|
|
||||||
void signal_handler(int sig);
|
void signal_handler(int sig);
|
||||||
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
|
int numbers_to_char(id_t id1,id_t id2,id_t id3,char * &data,int &len);
|
||||||
|
@@ -107,7 +107,7 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
|
|||||||
fec_encode_manager_t fec_encode_manager;
|
fec_encode_manager_t fec_encode_manager;
|
||||||
fec_decode_manager_t fec_decode_manager;
|
fec_decode_manager_t fec_decode_manager;
|
||||||
my_timer_t timer;
|
my_timer_t timer;
|
||||||
ip_port_t ip_port;
|
//ip_port_t ip_port;
|
||||||
u64_t last_active_time;
|
u64_t last_active_time;
|
||||||
stat_t stat;
|
stat_t stat;
|
||||||
conn_info_t()
|
conn_info_t()
|
||||||
|
@@ -11,9 +11,21 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
另外,可以和udp2raw串联使用,在加速的同时把UDP伪装成TCP,防止UDP被运营商QOS或屏蔽。udp2raw: https://github.com/wangyu-/udp2raw-tunnel
|
对于某些运营商,UDPspeeder跟udp2raw配合可以达到更好的速度,udp2raw负责把UDP伪装成TCP,来绕过运营商的UDP限速。
|
||||||
|
|
||||||
|
udp2raw的repo:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/udp2raw-tunnel
|
||||||
|
|
||||||
|
如果你嫌UDPspeeder+OpenVPN麻烦,你可以尝试tinyFecVPN,一个集成了UDPspeeder功能的VPN:
|
||||||
|
|
||||||
|
tinyFecVPN的repo:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN
|
||||||
|
|
||||||
|
|
||||||
#### 效果
|
#### 效果
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
#### 原理简介
|
#### 原理简介
|
||||||
@@ -39,11 +51,13 @@ client支持多个udp连接,server也支持多个client
|
|||||||
# 简明操作说明
|
# 简明操作说明
|
||||||
|
|
||||||
### 环境要求
|
### 环境要求
|
||||||
Linux主机,可以是桌面版,可以是android手机/平板,可以是openwrt路由器,也可以是树莓派。在windows和mac上配合虚拟机可以稳定使用(speeder跑在Linux里,其他应用照常跑在window里,桥接模式测试可用),可以使用[这个](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20170918.0/lede-17.01.2-x86_virtual_machine_image_with_udp2raw_pre_installed.zip)虚拟机镜像,大小只有7.5mb,免去在虚拟机里装系统的麻烦;虚拟机自带ssh server,可以scp拷贝文件,可以ssh进去,可以复制粘贴,root密码123456。
|
Linux主机,可以是桌面版,可以是android手机/平板,可以是openwrt路由器,也可以是树莓派。Release中提供了`amd64`、`x86`、`arm`、`mips_be`、`mips_le`的预编译binary.
|
||||||
|
|
||||||
|
对于windows和mac用户,在虚拟机中可以稳定使用(speeder跑在Linux里,其他应用照常跑在window里,桥接模式测试可用)。可以使用[这个](https://github.com/wangyu-/udp2raw-tunnel/releases/download/20171108.0/lede-17.01.2-x86_virtual_machine_image.zip)虚拟机镜像,大小只有7.5mb,免去在虚拟机里装系统的麻烦;虚拟机自带ssh server,可以scp拷贝文件,可以ssh进去,可以复制粘贴,root密码123456。
|
||||||
|
|
||||||
android版需要通过terminal运行。
|
android版需要通过terminal运行。
|
||||||
|
|
||||||
###### 注意
|
##### 注意
|
||||||
在使用虚拟机时,建议手动指定桥接到哪个网卡,不要设置成自动。否则可能会桥接到错误的网卡。
|
在使用虚拟机时,建议手动指定桥接到哪个网卡,不要设置成自动。否则可能会桥接到错误的网卡。
|
||||||
|
|
||||||
### 安装
|
### 安装
|
||||||
@@ -55,101 +69,97 @@ https://github.com/wangyu-/UDPspeeder/releases
|
|||||||
假设你有一个server,ip为44.55.66.77,有一个服务监听在udp 7777端口。 假设你需要加速本地到44.55.66.77:7777的流量。
|
假设你有一个server,ip为44.55.66.77,有一个服务监听在udp 7777端口。 假设你需要加速本地到44.55.66.77:7777的流量。
|
||||||
```
|
```
|
||||||
在server端运行:
|
在server端运行:
|
||||||
./speederv2 -s -l0.0.0.0:4096 -r127.0.0.1:7777 -f20:10 -k "passwd"
|
./speederv2 -s -l0.0.0.0:4096 -r127.0.0.1:7777 -f20:10 -k "passwd" --mode 0
|
||||||
|
|
||||||
在client端运行:
|
在client端运行:
|
||||||
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd"
|
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f20:10 -k "passwd" --mode 0
|
||||||
```
|
```
|
||||||
|
|
||||||
现在client和server之间建立起了tunnel。想要连接44.55.66.77:7777,只需要连接 127.0.0.1:3333。来回的所有的udp流量会被加速。
|
现在client和server之间建立起了tunnel。想要连接44.55.66.77:7777,只需要连接 127.0.0.1:3333。来回的所有的udp流量会被加速。
|
||||||
|
|
||||||
###### 备注:
|
##### 备注:
|
||||||
|
|
||||||
`-f20:10` 表示对每20个原始数据发送10个冗余包。`-f20:10` 和`-f 20:10`都是可以的,空格可以省略,对于所有的单字节option都是如此。对于双字节option,例如后面的`--mode 0`和`--mtu 1200`,空格不可以省略。
|
`-f20:10`表示对每20个原始数据发送10个冗余包。`-f20:10` 和`-f 20:10`都是可以的,空格可以省略,对于所有的单字节option都是如此。对于双字节option,例如后面会提到的`--mode 0`,空格不可以省略。
|
||||||
|
|
||||||
`-k` 指定一个字符串,server/client间所有收发的包都会被异或,改变协议特征,防止UDPspeeder的协议被运营商针对。
|
`-k` 指定一个字符串,开启简单的异或加密
|
||||||
|
|
||||||
|
推荐使用`--mode 0`选项,否则你可能需要考虑MTU问题。
|
||||||
|
|
||||||
###### 注意
|
##### 注意
|
||||||
|
|
||||||
要为UDPspeeder加速的应用设置好MTU(不是在UDPspeeder中,是在被加速的应用中),建议设置为1200。
|
这里推荐的参数是给日常/非游戏情况下使用的;玩游戏请用 [使用经验](https://github.com/wangyu-/UDPspeeder/wiki/使用经验) 里推荐的参数。
|
||||||
|
|
||||||
另外,如果被加速的应用不能调整MTU,也可以在UDPspeeder中通过`--mode 0 --mtu 1200`设置MTU。关于`--mode 0`和`--mtu`的具体含义请看下文。
|
|
||||||
|
|
||||||
# 进阶操作说明
|
# 进阶操作说明
|
||||||
|
|
||||||
### 命令选项
|
### 命令选项
|
||||||
```
|
```
|
||||||
UDPspeeder V2
|
UDPspeeder V2
|
||||||
git version:8e7a8aed92 build date:Oct 25 2017 02:00:54
|
git version: 6f55b8a2fc build date: Nov 19 2017 06:11:23
|
||||||
repository: https://github.com/wangyu-/UDPspeeder
|
repository: https://github.com/wangyu-/UDPspeeder
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
run as client: ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
|
||||||
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
run as server: ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
|
||||||
|
|
||||||
common option,must be same on both sides:
|
common options, must be same on both sides:
|
||||||
-k,--key <string> key for simple xor encryption. if not set,xor is disabled
|
-k,--key <string> key for simple xor encryption. if not set, xor is disabled
|
||||||
main options:
|
main options:
|
||||||
-f,--fec x:y forward error correction,send y redundant packets for every x packets
|
-f,--fec x:y forward error correction, send y redundant packets for every x packets
|
||||||
--timeout <number> how long could a packet be held in queue before doing fec,unit: ms,default :8ms
|
--timeout <number> how long could a packet be held in queue before doing fec, unit: ms, default: 8ms
|
||||||
--mode <number> fec-mode,available values: 0,1 ; 0 cost less bandwidth,1 cost less latency(default)
|
--report <number> turn on send/recv report, and set a period for reporting, unit: s
|
||||||
--report <number> turn on send/recv report,and set a period for reporting,unit:s
|
|
||||||
advanced options:
|
advanced options:
|
||||||
--mtu <number> mtu. for mode 0,the program will split packet to segment smaller than mtu_value.
|
--mode <number> fec-mode,available values: 0,1; mode 0(default) costs less bandwidth,no mtu problem.
|
||||||
for mode 1,no packet will be split,the program just check if the mtu is exceed.
|
mode 1 usually introduces less latency, but you have to care about mtu.
|
||||||
default value:1250
|
--mtu <number> mtu. for mode 0, the program will split packet to segment smaller than mtu value.
|
||||||
-j,--jitter <number> simulated jitter.randomly delay first packet for 0~<number> ms,default value:0.
|
for mode 1, no packet will be split, the program just check if the mtu is exceed.
|
||||||
|
default value: 1250. you typically shouldnt change this value.
|
||||||
|
-q,--queue-len <number> fec queue len, only for mode 0, fec will be performed immediately after queue is full.
|
||||||
|
default value: 200.
|
||||||
|
-j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.
|
||||||
do not use if you dont know what it means.
|
do not use if you dont know what it means.
|
||||||
-i,--interval <number> scatter each fec group to a interval of <number> ms,to protect burst packet loss.
|
-i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.
|
||||||
default value:0.do not use if you dont know what it means.
|
default value: 0. do not use if you dont know what it means.
|
||||||
--random-drop <number> simulate packet loss ,unit:0.01%. default value: 0
|
--random-drop <number> simulate packet loss, unit: 0.01%. default value: 0.
|
||||||
--disable-obscure <number> disable obscure,to save a bit bandwidth and cpu
|
--disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.
|
||||||
developer options:
|
developer options:
|
||||||
--fifo <string> use a fifo(named pipe) for sending commands to the running program,so that you
|
--fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you
|
||||||
can change fec encode parameters dynamically,check readme.md in repository for
|
can change fec encode parameters dynamically, check readme.md in repository for
|
||||||
supported commands.
|
supported commands.
|
||||||
-j ,--jitter jmin:jmax similiar to -j above,but create jitter randomly between jmin and jmax
|
-j ,--jitter jmin:jmax similiar to -j above, but create jitter randomly between jmin and jmax
|
||||||
-i,--interval imin:imax similiar to -i above,but scatter randomly between imin and imax
|
-i,--interval imin:imax similiar to -i above, but scatter randomly between imin and imax
|
||||||
-q,--queue-len <number> max fec queue len,only for mode 0
|
--decode-buf <number> size of buffer of fec decoder,u nit: packet, default: 2000
|
||||||
--decode-buf <number> size of buffer of fec decoder,unit:packet,default:2000
|
--fix-latency <number> try to stabilize latency, only for mode 0
|
||||||
--fix-latency <number> try to stabilize latency,only for mode 0
|
|
||||||
--delay-capacity <number> max number of delayed packets
|
--delay-capacity <number> max number of delayed packets
|
||||||
--disable-fec <number> completely disable fec,turn the program into a normal udp tunnel
|
--disable-fec <number> completely disable fec, turn the program into a normal udp tunnel
|
||||||
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
|
--sock-buf <number> buf size for socket, >=10 and <=10240, unit: kbyte, default: 1024
|
||||||
log and help options:
|
log and help options:
|
||||||
--log-level <number> 0:never 1:fatal 2:error 3:warn
|
--log-level <number> 0: never 1: fatal 2: error 3: warn
|
||||||
4:info (default) 5:debug 6:trace
|
4: info (default) 5: debug 6: trace
|
||||||
--log-position enable file name,function name,line number in log
|
--log-position enable file name, function name, line number in log
|
||||||
--disable-color disable log color
|
--disable-color disable log color
|
||||||
-h,--help print this help message
|
-h,--help print this help message
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
### 包发送选项,两端设置可以不同。 只影响本地包发送。
|
### 包发送选项,两端设置可以不同。 只影响本地包发送。
|
||||||
##### `-f` 选项
|
##### `-f` 选项
|
||||||
设置fec参数,影响数据的冗余度。
|
设置fec参数,影响数据的冗余度。
|
||||||
##### `--timeout` 选项
|
##### `--timeout` 选项
|
||||||
指定fec编码器在编码时候最多可以引入多大的延迟。越高fec越有效率,加速游戏时调低可以降低延迟。
|
指定fec编码器在编码时候最多可以引入多大的延迟。越高fec越有效率,调低可以降低延迟,但是会牺牲效率。
|
||||||
|
|
||||||
##### `--mode` 选项 和 `--mtu`选项
|
##### `--mode` 选项 和 `--mtu`选项
|
||||||
fec编码器的工作模式。对于mode 0,编码器会积攒一定数量的packet,然后把他们合并再切成等长的片段(切分长度由--mtu指定)。对于mode 1,编码器不会做任何切分,而是会把packet按最大长度对齐,fec冗余包的长度为对齐后的长度(最大长度)。
|
|
||||||
|
|
||||||
mode 0更省流量,在丢包率正常的情况下效果和mode 1是一样的;mode 1延迟更低,在极高丢包的情况下表现更好。
|
简单来说`--mode 0`更省流量,没有mtu问题;`--mode 1`可以稍微降低一点延迟,需要考虑mtu;另外还有个`--mode 0 -q1`模式,多倍发包专用,没有延迟,也没有mtu问题,适合游戏,但是最耗流量。
|
||||||
|
|
||||||
mode 0使用起来可以不用关注mtu,因为fec编码器会帮你把包切分到合理的大小;用mode 1时必须合理设置上层应用的mtu。mode 0模式中--mtu选项决定切分的片段的长度,mode 1模式中--mtu选项只起检查作用,如果超过了--mtu指定的值,数据包会被丢弃。
|
具体见,https://github.com/wangyu-/UDPspeeder/wiki/mode和mtu选项
|
||||||
|
|
||||||
mode 0模式的流量消耗基本完全透明。mode 1因为涉及到数据按最大长度对齐,所以流量消耗不是完全可预期。不过就实际使用来看,mode 1消耗的额外流量不多。
|
对于新手,建议不要纠结这些参数的具体含义,就用我在`使用经验`里推荐的设置,不要乱改参数,尤其是不要改`--mtu`。
|
||||||
|
|
||||||
mode 0模式数据包一般不会乱序,除非网络本身有严重乱序;mode 1模式被恢复的数据包可能会乱序,不过UDP本来就允许乱序,对绝大多数应用没有影响。mode 0模式反而可以纠正一些乱序情况。
|
|
||||||
|
|
||||||
mode 0模式允许你发送的数据包大小超过物理接口的MTU而几乎不引起性能损失(而普通的ip分片做不到这点),目前最高支持到2000字节,2000字节已经可以应对任何应用了,因为一般网络的MTU只有1400多。之所以支持到2000字节是为了省程序内部开的静态buff(静态buff避免malloc提高性能),如果你是开发者,通过重新编译,支持到UDP协议的极限(
|
|
||||||
65507字节)也没问题。
|
|
||||||
|
|
||||||
##### `--report` 选项
|
##### `--report` 选项
|
||||||
数据发送和接受报告。开启后可以根据此数据推测出包速和丢包率等特征。
|
数据发送和接受报告。开启后可以根据此数据推测出包速和丢包率等特征。`--report 10`表示每10秒生成一次报告。
|
||||||
|
|
||||||
##### `-i` 选项
|
##### `-i` 选项
|
||||||
指定一个时间窗口,长度为n毫秒。同一个fec分组的数据在发送时候会被均匀分散到这n毫秒中。可以对抗突发性的丢包。默认值是0,因为这个功能需要用到时钟,在某些虚拟机里时钟不稳定,可能会导致个别包出现非常大的延迟,所以默认关掉了。这个功能很有用,默认参数效果不理想时可以尝试打开。这个选项的跟通信原理上常说的`交错fec` `交织fec`的原理是差不多的。
|
指定一个时间窗口,长度为n毫秒。同一个fec分组的数据在发送时候会被均匀分散到这n毫秒中。可以对抗突发性的丢包。默认值是0,因为这个功能需要用到时钟,在某些虚拟机里时钟不稳定,可能会导致个别包出现非常大的延迟,所以默认关掉了。这个功能很有用,默认参数效果不理想时可以尝试打开,比如用`-i 10`。这个选项的跟通信原理上常说的`交错fec` `交织fec`的原理是差不多的。
|
||||||
|
|
||||||
##### `-j` 选项
|
##### `-j` 选项
|
||||||
为原始数据的发送,增加一个延迟抖动值。这样上层应用计算出来的RTT方差会更大,以等待后续冗余包的到达,不至于发生在冗余包到达之前就触发重传的尴尬。配合-t选项使用。正常情况下跨国网络本身的延迟抖动就很大,可以不用设-j。这个功能也需要时钟,默认关掉了,不过一般情况应该不需要这个功能。
|
为原始数据的发送,增加一个延迟抖动值。这样上层应用计算出来的RTT方差会更大,以等待后续冗余包的到达,不至于发生在冗余包到达之前就触发重传的尴尬。配合-t选项使用。正常情况下跨国网络本身的延迟抖动就很大,可以不用设-j。这个功能也需要时钟,默认关掉了,不过一般情况应该不需要这个功能。
|
||||||
@@ -159,14 +169,15 @@ mode 0模式允许你发送的数据包大小超过物理接口的MTU而几乎
|
|||||||
##### `--random-drop` 选项
|
##### `--random-drop` 选项
|
||||||
随机丢包。模拟高丢包的网络环境时使用。 `--random-drop`和`-j`选项一起用,可以模拟高延迟(或者高延迟抖动)高丢包的网络,可用于测试FEC参数在各种网络环境下的表现。
|
随机丢包。模拟高丢包的网络环境时使用。 `--random-drop`和`-j`选项一起用,可以模拟高延迟(或者高延迟抖动)高丢包的网络,可用于测试FEC参数在各种网络环境下的表现。
|
||||||
|
|
||||||
##### `-k`选项
|
##### `-q` 选项
|
||||||
指定一个字符串,server/client间所有收发的包都会被异或,改变协议特征,防止UDPspeeder的协议被运营商针对。
|
仅对mode 0模式有用。设置fec编码器的最大队列长度。 比如`-q5`的意思是,在编码器积攒了5个数据包后,就立即发送。合理使用可以改善延迟。在下文的`使用经验`里有提到用`--mode 0 -q1` 来多倍发包。
|
||||||
|
|
||||||
##### `--disable-obscure`
|
`-q`和 `--timeout`的作用类似。`-q`决定fec编码器积攒了多少个数据包之后,立即发送。`--timeout`决定编码器收到第一个数据包以后,最多延迟多少毫秒后发送。
|
||||||
UDPspeeder默认情况下会对每个发出的数据包随机填充和异或一些字节(4~32字节),这样通过抓包难以发现你发了冗余数据,防止VPS被封。这个功能只是为了小心谨慎,即使你关掉这个功能,基本上也没问题,关掉可以省一些带宽和CPU。
|
|
||||||
|
默认值是200,也就是尽可能多得积攒数据。
|
||||||
|
|
||||||
|
建议不要自己调整这个参数,除非是用我在`使用经验`里推荐给你的形式。
|
||||||
|
|
||||||
##### `-q,--queue-len`
|
|
||||||
编码器在做FEC前最多积攒多少个数据包,只对mode 0有效。除非是使用下文`V2版如何多倍发包`里面提到的用法,不建议改动。
|
|
||||||
#### `--fifo` option
|
#### `--fifo` option
|
||||||
用fifo(命名管道)向运行中的程序发送command。例如`--fifo fifo.file`,可用的command有:
|
用fifo(命名管道)向运行中的程序发送command。例如`--fifo fifo.file`,可用的command有:
|
||||||
```
|
```
|
||||||
@@ -178,89 +189,35 @@ echo mode 0 > fifo.file
|
|||||||
```
|
```
|
||||||
可以动态改变fec编码器参数。可以从程序的log里看到command是否发送成功。
|
可以动态改变fec编码器参数。可以从程序的log里看到command是否发送成功。
|
||||||
|
|
||||||
|
### 以下设置两端必须相同。
|
||||||
|
|
||||||
|
##### `-k`选项
|
||||||
|
指定一个字符串,server/client间所有收发的包都会被异或,改变协议特征,防止UDPspeeder的协议被运营商针对。
|
||||||
|
|
||||||
|
##### `--disable-obscure`
|
||||||
|
UDPspeeder默认情况下会对每个发出的数据包随机填充和异或一些字节(4~32字节),这样通过抓包难以发现你发了冗余数据,防止VPS被封。这个功能只是为了小心谨慎,即使你关掉这个功能,基本上也没问题,关掉可以省一些带宽和CPU。`--disable-obscure`可以关掉这个功能。
|
||||||
|
|
||||||
# 使用经验
|
# 使用经验
|
||||||
|
|
||||||
### 在FEC和多倍发包之间如何选择
|
https://github.com/wangyu-/UDPspeeder/wiki/使用经验
|
||||||
|
|
||||||
对于游戏,游戏的流量本身不大,延迟很重要,多倍发包是最佳解决方案,多倍发包不会引入额外的延迟。FEC编码器需要先积攒一些数据,才可以做FEC,延迟无法避免;对于多倍发包,没有这个问题,所以没有延迟。
|
|
||||||
|
|
||||||
对于其他日常应用(延迟要求一般),在合理配置的情况下,FEC的效果肯定好过多倍发包。不过需要根据网络的最大丢包来配置FEC参数,才能有稳定的效果。如果配置不当,对于--mode 1可能会完全没有效果;对于--mode 0,可能效果会比不用UDPspeeder还差。
|
|
||||||
|
|
||||||
对于游戏以外的应用,推荐使用FEC。但是,如果FEC版的默认参数在你那边效果很差,而你又不会调,可以先用多倍发包。
|
|
||||||
|
|
||||||
### V2版如何多倍发包
|
|
||||||
|
|
||||||
只要在设置-f参数时把x设置为1,fec算法就退化为多倍发包了。例如-f1:1,表示2倍发包,-f1:2表示3倍发包,以此类推。另外可以加上`--mode 0 -q1`参数,防止fec编码器试图积攒和合并数据,获得最低的延迟。
|
|
||||||
|
|
||||||
2倍发包的完整参数:
|
|
||||||
|
|
||||||
```
|
|
||||||
./speederv2 -s -l0.0.0.0:4096 -r127.0.0.1:7777 -f1:1 -k "passwd" --mode 0 -q1
|
|
||||||
./speederv2 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -f1:1 -k "passwd" --mode 0 -q1
|
|
||||||
```
|
|
||||||
|
|
||||||
使用了`--mode 0 -q1`以后,`--timeout`选项不起作用,所以不用调。
|
|
||||||
|
|
||||||
如果你只需要多倍发包,可以直接用回V1版,V1版配置更简单,占用内存更小,而且经过了几个月的考验,很稳定。
|
|
||||||
|
|
||||||
### 根据网络丢包合理设置FEC参数
|
|
||||||
|
|
||||||
默认的FEC参数为-f20:10,对每20个包,额外发送10个冗余包,也就是1.5倍发包。已经可以适应绝大多数的网络情况了,对于10%的网络丢包,可以降低到0.01%以下;对于20%的网络丢包,可以降低到2.5%。
|
|
||||||
|
|
||||||
如果你的网络丢包很低,比如在3%以下,可以尝试调低参数。比如-f20:5,也就是1.2倍发包,这个参数已经足够把3%的丢包降低到0.01%以下了。
|
|
||||||
|
|
||||||
如果网络丢包超过20%,需要把-f20:10调大。
|
|
||||||
|
|
||||||
如果你实在不会配,那么也可以用回V1版。
|
|
||||||
|
|
||||||
### 根据CPU处理能力来调整FEC参数
|
|
||||||
|
|
||||||
FEC算法很吃CPU,初次使用建议关注UDPspeeder的CPU占用。如果CPU被打满,可以在冗余度不变的情况下把FEC分组大小调小,否则的话效果可能很差。
|
|
||||||
|
|
||||||
比如-f20:10和-f10:5,都是1.5倍的冗余度,而-f20:10的FEC分组大小是30个包,-f10:5的FEC分组大小是15个包。-f20:10更费CPU,但是在一般情况下效果更稳定。把分组调小可以节省CPU。
|
|
||||||
|
|
||||||
另外,fec分组大小不宜过大,否则不但很耗CPU,还有其他副作用,建议x+y<50。
|
|
||||||
|
|
||||||
### 改变FEC参数而不断线
|
|
||||||
|
|
||||||
`--fifo`选项可以在运行时改变FEC参数,无需重启程序,也不会断线。如果你在使用过程中发现网络丢包突然变高,可以动态地把冗余度调大;反之也一样,如果网络变好了,把冗余度调小节省流量。一切都是无缝进行,不会断线,也不会因为改FEC参数导致额外的丢包。
|
|
||||||
|
|
||||||
### 为什么使用之后效果反而变差了?
|
|
||||||
|
|
||||||
有可能是你用了mode 0参数,而又没调好参数。
|
|
||||||
|
|
||||||
如果你没有使用mode 0,而确实效果变差了,那很可能是因为你的运营商对UDP有限制。一般看视频和下载都是TCP流量,而用UDPspeeder中转后流量变成了UDP流量,如果运营商对UDP做了限制,就可能导致效果比不用还差。用udp2raw可以解决,udp2raw: https://github.com/wangyu-/udp2raw-tunnel
|
|
||||||
|
|
||||||
|
|
||||||
### UDPspeeder和BBR/锐速配合
|
|
||||||
|
|
||||||
UDPspeeder和BBR/锐速可以配合使用,UDPspeeder工作在IP层负责降低丢包率,BBR/锐速工作在TCP层负责优化拥塞和重传。这种情况下,可以调低UDPspeeder的冗余度,能把丢包率降低到5%以内就可以了,剩下的交给BBR/锐速解决,这样预计可以节省一些流量。如果是UDPspeeder跟Linux默认的Cubic一起用,最少也要把丢包率降低到1%以下才能流畅使用TCP。
|
|
||||||
|
|
||||||
对下文的`UDPspeeder + openvpn`和`UDPspeeder + openvpn + $***`方法有效。不过有一点区别,具体见下文。
|
|
||||||
|
|
||||||
### UDPspeeder和Kcptun配合
|
|
||||||
|
|
||||||
UDPspeeder和Kcptun配合,UDPspeeder和Kcptun可以并联也可以串联。
|
|
||||||
|
|
||||||
并联的情况下,让kcptun负责加速TCP,UDPspeeder负责加速UDP。见下文的`UDPspeeder + kcptun + $*** 同时加速tcp和udp流量`。
|
|
||||||
|
|
||||||
串联的情况。UDPspeeder的FEC跟Kcptun自带的相比:可以对两个方向设置不同的FEC参数、有一个更省流量的mode 0模式、可以动态改变FEC参数;但是UDPspeeder本身不优化拥塞和重传算法。所以UDPspeeder和Kcptun也可以配合使用,结合两者的优点。
|
|
||||||
|
|
||||||
串联时可以关掉Kcptun的FEC,让UDPspeeder接管FEC功能。这样UDPspeeder工作在UDP层负责降低丢包率,Kcptun工作在应用层用kcp算法负责优化拥塞和重传,能起到和`UDPspeeder+BBR/锐速`类似的效果。
|
|
||||||
|
|
||||||
如果发Issue问Kcptun+UDPspeeder相关的问题,一定要说明是并联还是串联。
|
|
||||||
|
|
||||||
# 应用
|
# 应用
|
||||||
|
|
||||||
#### UDPspeeder + OpenVPN加速任何流量,也适用于其他VPN
|
#### UDPspeeder + OpenVPN加速任何流量,也适用于其他VPN
|
||||||

|

|
||||||
|
|
||||||
具体配置见,[UDPspeeder + openvpn config guide](/doc/udpspeeder_openvpn.md).
|
可以和BBR/锐速叠加,不过BBR/锐速部署在VPS上只对本地和VPS间的流量有效,对从本地和第三方服务器间的流量无效。
|
||||||
|
|
||||||
可以和BBR/锐速叠加,不过BBR/锐速部署在VPS上只对从本地到VPS的流量有效,对从本地到第三方服务器的流量无效。
|
|
||||||
|
|
||||||
需要在服务端开启ipforward和NAT。在客户端改路由表(可以手动修改,也可以由OpenVPN的redirect-gateway选项自动加好)。
|
需要在服务端开启ipforward和NAT。在客户端改路由表(可以手动修改,也可以由OpenVPN的redirect-gateway选项自动加好)。
|
||||||
|
|
||||||
|
Linux具体配置: [UDPspeeder + openvpn config guide](/doc/udpspeeder_openvpn.md).
|
||||||
|
|
||||||
|
Windows具体配置: [win10系统UDPspeeder+OpenVPN的完整设置](https://github.com/wangyu-/UDPspeeder/wiki/win10系统UDPspeeder-OpenVPN的完整设置)
|
||||||
|
|
||||||
|
如果UDPspeeder + OpenVPN对你来说显得太麻烦了,你可以尝试一下tinyFecVPN,一个集成了UDPspeeder功能的VPN:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN/
|
||||||
|
|
||||||
#### UDPspeeder + kcptun/finalspeed + $*** 同时加速tcp和udp流量
|
#### UDPspeeder + kcptun/finalspeed + $*** 同时加速tcp和udp流量
|
||||||
如果你需要用加速的tcp看视频和下载文件,这样效果可能比没有BBR的UDPspeeder+vpn方案更好。另外,如果你需要玩游戏,但是嫌配VPN麻烦,也可以用这种方案。
|
如果你需要用加速的tcp看视频和下载文件,这样效果可能比没有BBR的UDPspeeder+vpn方案更好。另外,如果你需要玩游戏,但是嫌配VPN麻烦,也可以用这种方案。
|
||||||

|

|
||||||
@@ -281,9 +238,11 @@ run at client side:
|
|||||||
|
|
||||||
这就是全部的命令了。issue里有很多人困惑于怎么把tcp和udp流量"分开",其实很简单就可以做到。
|
这就是全部的命令了。issue里有很多人困惑于怎么把tcp和udp流量"分开",其实很简单就可以做到。
|
||||||
|
|
||||||
如果只需要加速UDP,不需要加速TCP,可以把kcptun换成其他的任意端口转发方式,比如ncat/socat/ssh tunnel/iptables。
|
如果只需要加速UDP,不需要加速TCP,可以把kcptun换成其他的任意端口转发方式,比如ncat/socat/ssh tunnel/iptables/[tinyPortMapper](https://github.com/wangyu-/tinyPortMapper/releases)。
|
||||||
|
|
||||||
另外,如果没有kcptun只有BBR/锐速的话,也可以把kcptun换成ncat/socat/ssh tunnel/iptables。这样,TCP流量由锐速/BBR加速,UDP由UDPspeeder加速。
|
如果你没有kcptun只有BBR/锐速的话,也可以把kcptun换成ncat/socat/ssh tunnel/iptables/[tinyPortMapper](https://github.com/wangyu-/tinyPortMapper/releases)。这样,TCP流量由锐速/BBR加速,UDP由UDPspeeder加速。
|
||||||
|
|
||||||
|
另外,即使你不想使用$\*\*\*的TCP功能,你也必须把$\*\*\*的TCP端口转发过来,否则无法使用UDP功能,这是socks5协议的工作方式决定的。($\*\*\*-redir方式不受此限制)
|
||||||
|
|
||||||
#### UDPspeeder + openvpn + $*** 混合方案,也适用于其他VPN
|
#### UDPspeeder + openvpn + $*** 混合方案,也适用于其他VPN
|
||||||
也是我正在用的方案。优点是可以随时在vpn和$\*\*\*方案间快速切换。
|
也是我正在用的方案。优点是可以随时在vpn和$\*\*\*方案间快速切换。
|
||||||
@@ -295,7 +254,32 @@ run at client side:
|
|||||||
|
|
||||||
可以和BBR/锐速叠加,BBR/锐速只要部署在VPS上就有效。
|
可以和BBR/锐速叠加,BBR/锐速只要部署在VPS上就有效。
|
||||||
|
|
||||||
|
也可以用[tinyFecVPN](https://github.com/wangyu-/tinyFecVPN/) + $\*\*\* ,配置起来更简单。
|
||||||
|
|
||||||
|
# 应用实例
|
||||||
|
|
||||||
|
#### win10系统UDPspeeder+OpenVPN的完整设置
|
||||||
|
|
||||||
|
https://github.com/wangyu-/UDPspeeder/wiki/win10系统UDPspeeder-OpenVPN的完整设置
|
||||||
|
|
||||||
|
|
||||||
|
#### UDPspeeder+OpenVPN运行在linux上,透明加速linux本机的网络
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN/wiki/tinyFecVPN运行在linux上,透明加速linux本机的网络
|
||||||
|
|
||||||
|
|
||||||
|
#### UDPspeeder+OpenVPN运行在虚拟机中,加速windows和局域网内其他主机的网络
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN/wiki/tinyFecVPN运行在虚拟机中,加速windows和局域网内其他主机的网络
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### 用树莓派做路由器,搭建透明代理,加速游戏主机的网络
|
||||||
|
|
||||||
|
https://github.com/wangyu-/UDPspeeder/wiki/用树莓派做路由器,搭建透明代理,加速游戏主机的网络
|
||||||
|
|
||||||
# 编译教程
|
# 编译教程
|
||||||
暂时先参考udp2raw的这篇教程,几乎一样的过程。
|
暂时先参考udp2raw的这篇教程,几乎一样的过程。
|
||||||
|
|
||||||
https://github.com/wangyu-/udp2raw-tunnel/blob/master/doc/build_guide.zh-cn.md
|
https://github.com/wangyu-/udp2raw-tunnel/blob/master/doc/build_guide.zh-cn.md
|
||||||
|
|
||||||
|
@@ -100,3 +100,8 @@ or
|
|||||||
ip route add 44.55.66.77 dev XXX
|
ip route add 44.55.66.77 dev XXX
|
||||||
```
|
```
|
||||||
(run at client side)
|
(run at client side)
|
||||||
|
|
||||||
|
##### Other Info
|
||||||
|
You can also use tinyFecVPN,a lightweight VPN with build-in FEC support:
|
||||||
|
|
||||||
|
https://github.com/wangyu-/tinyFecVPN
|
||||||
|
@@ -16,7 +16,7 @@ int g_fec_redundant_num=10;
|
|||||||
int g_fec_mtu=1250;
|
int g_fec_mtu=1250;
|
||||||
int g_fec_queue_len=200;
|
int g_fec_queue_len=200;
|
||||||
int g_fec_timeout=8*1000; //8ms
|
int g_fec_timeout=8*1000; //8ms
|
||||||
int g_fec_mode=1;
|
int g_fec_mode=0;
|
||||||
|
|
||||||
int dynamic_update_fec=1;
|
int dynamic_update_fec=1;
|
||||||
|
|
||||||
@@ -146,11 +146,11 @@ fec_encode_manager_t::fec_encode_manager_t()
|
|||||||
}
|
}
|
||||||
timer_fd64=fd_manager.create(timer_fd);
|
timer_fd64=fd_manager.create(timer_fd);
|
||||||
|
|
||||||
re_init(fec_data_num,fec_redundant_num,fec_mtu,fec_queue_len,fec_timeout,fec_mode);
|
reset_fec_parameter(g_fec_data_num,g_fec_redundant_num,g_fec_mtu,g_fec_queue_len,g_fec_timeout,g_fec_mode);
|
||||||
|
|
||||||
|
|
||||||
seq=(u32_t)get_true_random_number(); //TODO temp solution for a bug.
|
|
||||||
}
|
}
|
||||||
int fec_encode_manager_t::re_init(int data_num,int redundant_num,int mtu,int queue_len,int timeout,int mode)
|
int fec_encode_manager_t::reset_fec_parameter(int data_num,int redundant_num,int mtu,int queue_len,int timeout,int mode)
|
||||||
{
|
{
|
||||||
fec_data_num=data_num;
|
fec_data_num=data_num;
|
||||||
fec_redundant_num=redundant_num;
|
fec_redundant_num=redundant_num;
|
||||||
@@ -160,15 +160,8 @@ int fec_encode_manager_t::re_init(int data_num,int redundant_num,int mtu,int que
|
|||||||
fec_mode=mode;
|
fec_mode=mode;
|
||||||
|
|
||||||
assert(data_num+redundant_num<max_fec_packet_num);
|
assert(data_num+redundant_num<max_fec_packet_num);
|
||||||
counter=0;
|
|
||||||
blob_encode.clear();
|
|
||||||
ready_for_output=0;
|
|
||||||
//seq=0;
|
|
||||||
|
|
||||||
itimerspec zero_its;
|
clear();
|
||||||
memset(&zero_its, 0, sizeof(zero_its));
|
|
||||||
|
|
||||||
timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &zero_its, 0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -192,7 +185,7 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/)
|
|||||||
{
|
{
|
||||||
mylog(log_trace,"counter=%d\n",counter);
|
mylog(log_trace,"counter=%d\n",counter);
|
||||||
assert(len<=65535&&len>=0);
|
assert(len<=65535&&len>=0);
|
||||||
assert(len<=fec_mtu);
|
//assert(len<=fec_mtu);//relax this limitation
|
||||||
char * p=input_buf[counter]+sizeof(u32_t)+4*sizeof(char);//copy directly to final position,avoid unnecessary copy.
|
char * p=input_buf[counter]+sizeof(u32_t)+4*sizeof(char);//copy directly to final position,avoid unnecessary copy.
|
||||||
//remember to change this,if protocol is modified
|
//remember to change this,if protocol is modified
|
||||||
|
|
||||||
@@ -225,15 +218,19 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
|||||||
//int counter_back=counter;
|
//int counter_back=counter;
|
||||||
assert(fec_mode==0||fec_mode==1);
|
assert(fec_mode==0||fec_mode==1);
|
||||||
|
|
||||||
if(fec_mode==0&& s!=0 &&counter==0&&blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu)
|
if(fec_mode==0&& s!=0 &&counter==0)
|
||||||
{
|
{
|
||||||
mylog(log_warn,"message too long len=%d,ignored\n",len);
|
int out_len=blob_encode.get_shard_len(fec_data_num,len);
|
||||||
return -1;
|
if(out_len>fec_mtu)
|
||||||
|
{
|
||||||
|
mylog(log_warn,"message too long ori_len=%d out_len=%d fec_mtu=%d,ignored\n",len,out_len,fec_mtu);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(fec_mode==1&&s!=0&&len>=fec_mtu)
|
if(fec_mode==1&&s!=0&&len>fec_mtu)
|
||||||
{
|
{
|
||||||
mylog(log_warn,"message too long len=%d fec_mtu=%d,ignored\n",len,fec_mtu);
|
mylog(log_warn,"mode==1,message len=%d,len>fec_mtu,fec_mtu=%d,packet may not be delivered\n",len,fec_mtu);
|
||||||
return -1;
|
//return -1;
|
||||||
}
|
}
|
||||||
if(s==0&&counter==0)
|
if(s==0&&counter==0)
|
||||||
{
|
{
|
||||||
@@ -242,7 +239,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
|||||||
}
|
}
|
||||||
if(s==0) about_to_fec=1;//now
|
if(s==0) about_to_fec=1;//now
|
||||||
|
|
||||||
if(fec_mode==0&& blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) {about_to_fec=1; delayed_append=1;}//fec then add packet
|
if(fec_mode==0&& blob_encode.get_shard_len(fec_data_num,len)>fec_mtu) {about_to_fec=1; delayed_append=1;}//fec then add packet
|
||||||
|
|
||||||
if(fec_mode==0) assert(counter<fec_queue_len);//counter will never equal fec_pending_num,if that happens fec should already been done.
|
if(fec_mode==0) assert(counter<fec_queue_len);//counter will never equal fec_pending_num,if that happens fec should already been done.
|
||||||
if(fec_mode==1) assert(counter<fec_data_num);
|
if(fec_mode==1) assert(counter<fec_data_num);
|
||||||
@@ -285,7 +282,10 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
|||||||
int best_data_num=fec_data_num;
|
int best_data_num=fec_data_num;
|
||||||
for(int i=1;i<actual_data_num;i++)
|
for(int i=1;i<actual_data_num;i++)
|
||||||
{
|
{
|
||||||
u32_t new_len=(blob_encode.get_shard_len(i,0)+header_overhead)*(i+fec_redundant_num);
|
u32_t shard_len=blob_encode.get_shard_len(i,0);
|
||||||
|
if(shard_len>(u32_t)fec_mtu) continue;
|
||||||
|
|
||||||
|
u32_t new_len=(shard_len+header_overhead)*(i+fec_redundant_num);
|
||||||
if(new_len<best_len)
|
if(new_len<best_len)
|
||||||
{
|
{
|
||||||
best_len=new_len;
|
best_len=new_len;
|
||||||
@@ -489,15 +489,12 @@ int fec_encode_manager_t::output(int &n,char ** &s_arr,int *&len)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int fec_decode_manager_t::re_init()
|
int fec_decode_manager_t::re_init()
|
||||||
{
|
{
|
||||||
for(int i=0;i<(int)fec_buff_num;i++)
|
clear();
|
||||||
fec_data[i].used=0;
|
|
||||||
ready_for_output=0;
|
|
||||||
index=0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
int fec_decode_manager_t::input(char *s,int len)
|
int fec_decode_manager_t::input(char *s,int len)
|
||||||
{
|
{
|
||||||
|
@@ -37,10 +37,16 @@ struct anti_replay_t
|
|||||||
unordered_set<u32_t> st;
|
unordered_set<u32_t> st;
|
||||||
int index;
|
int index;
|
||||||
anti_replay_t()
|
anti_replay_t()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
int clear()
|
||||||
{
|
{
|
||||||
memset(replay_buffer,-1,sizeof(replay_buffer));
|
memset(replay_buffer,-1,sizeof(replay_buffer));
|
||||||
|
st.clear();
|
||||||
st.rehash(anti_replay_buff_size*3);
|
st.rehash(anti_replay_buff_size*3);
|
||||||
index=0;
|
index=0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
void set_invaild(u32_t seq)
|
void set_invaild(u32_t seq)
|
||||||
{
|
{
|
||||||
@@ -140,6 +146,22 @@ public:
|
|||||||
fec_encode_manager_t();
|
fec_encode_manager_t();
|
||||||
~fec_encode_manager_t();
|
~fec_encode_manager_t();
|
||||||
|
|
||||||
|
int clear()
|
||||||
|
{
|
||||||
|
counter=0;
|
||||||
|
blob_encode.clear();
|
||||||
|
ready_for_output=0;
|
||||||
|
|
||||||
|
itimerspec zero_its;
|
||||||
|
memset(&zero_its, 0, sizeof(zero_its));
|
||||||
|
|
||||||
|
timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &zero_its, 0);
|
||||||
|
|
||||||
|
seq=(u32_t)get_true_random_number(); //TODO temp solution for a bug.
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
my_time_t get_first_packet_time()
|
my_time_t get_first_packet_time()
|
||||||
{
|
{
|
||||||
return first_packet_time_for_output;
|
return first_packet_time_for_output;
|
||||||
@@ -155,7 +177,7 @@ public:
|
|||||||
return fec_mode;
|
return fec_mode;
|
||||||
}
|
}
|
||||||
u64_t get_timer_fd64();
|
u64_t get_timer_fd64();
|
||||||
int re_init(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type);
|
int reset_fec_parameter(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type);
|
||||||
int input(char *s,int len/*,int &is_first_packet*/);
|
int input(char *s,int len/*,int &is_first_packet*/);
|
||||||
int output(int &n,char ** &s_arr,int *&len);
|
int output(int &n,char ** &s_arr,int *&len);
|
||||||
};
|
};
|
||||||
@@ -200,7 +222,7 @@ public:
|
|||||||
fec_decode_manager_t()
|
fec_decode_manager_t()
|
||||||
{
|
{
|
||||||
fec_data=new fec_data_t[fec_buff_num+5];
|
fec_data=new fec_data_t[fec_buff_num+5];
|
||||||
re_init();
|
clear();
|
||||||
}
|
}
|
||||||
fec_decode_manager_t(const fec_decode_manager_t &b)
|
fec_decode_manager_t(const fec_decode_manager_t &b)
|
||||||
{
|
{
|
||||||
@@ -210,7 +232,21 @@ public:
|
|||||||
{
|
{
|
||||||
delete fec_data;
|
delete fec_data;
|
||||||
}
|
}
|
||||||
int re_init();
|
int clear()
|
||||||
|
{
|
||||||
|
anti_replay.clear();
|
||||||
|
mp.clear();
|
||||||
|
mp.rehash(fec_buff_num*3);
|
||||||
|
|
||||||
|
for(int i=0;i<(int)fec_buff_num;i++)
|
||||||
|
fec_data[i].used=0;
|
||||||
|
ready_for_output=0;
|
||||||
|
index=0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//int re_init();
|
||||||
int input(char *s,int len);
|
int input(char *s,int len);
|
||||||
int output(int &n,char ** &s_arr,int* &len_arr);
|
int output(int &n,char ** &s_arr,int* &len_arr);
|
||||||
};
|
};
|
||||||
|
BIN
images/cn/ping_compare_cn.PNG
Normal file
BIN
images/cn/ping_compare_cn.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
106
main.cpp
106
main.cpp
@@ -9,10 +9,72 @@
|
|||||||
#include "fec_manager.h"
|
#include "fec_manager.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "tunnel.h"
|
#include "tunnel.h"
|
||||||
#include "tun_dev.h"
|
//#include "tun_dev.h"
|
||||||
|
#include "git_version.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
static void print_help()
|
||||||
|
{
|
||||||
|
char git_version_buf[100]={0};
|
||||||
|
strncpy(git_version_buf,gitversion,10);
|
||||||
|
|
||||||
|
printf("UDPspeeder V2\n");
|
||||||
|
printf("git version: %s ",git_version_buf);
|
||||||
|
printf("build date: %s %s\n",__DATE__,__TIME__);
|
||||||
|
printf("repository: https://github.com/wangyu-/UDPspeeder\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("usage:\n");
|
||||||
|
printf(" run as client: ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]\n");
|
||||||
|
printf(" run as server: ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("common options, must be same on both sides:\n");
|
||||||
|
printf(" -k,--key <string> key for simple xor encryption. if not set, xor is disabled\n");
|
||||||
|
|
||||||
|
printf("main options:\n");
|
||||||
|
printf(" -f,--fec x:y forward error correction, send y redundant packets for every x packets\n");
|
||||||
|
printf(" --timeout <number> how long could a packet be held in queue before doing fec, unit: ms, default: 8ms\n");
|
||||||
|
printf(" --report <number> turn on send/recv report, and set a period for reporting, unit: s\n");
|
||||||
|
|
||||||
|
printf("advanced options:\n");
|
||||||
|
printf(" --mode <number> fec-mode,available values: 0,1; mode 0(default) costs less bandwidth,no mtu problem.\n");
|
||||||
|
printf(" mode 1 usually introduces less latency, but you have to care about mtu.\n");
|
||||||
|
printf(" --mtu <number> mtu. for mode 0, the program will split packet to segment smaller than mtu value.\n");
|
||||||
|
printf(" for mode 1, no packet will be split, the program just check if the mtu is exceed.\n");
|
||||||
|
printf(" default value: 1250. you typically shouldnt change this value.\n");
|
||||||
|
printf(" -q,--queue-len <number> fec queue len, only for mode 0, fec will be performed immediately after queue is full.\n");
|
||||||
|
printf(" default value: 200. \n");
|
||||||
|
printf(" -j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.\n");
|
||||||
|
printf(" do not use if you dont know what it means.\n");
|
||||||
|
printf(" -i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.\n");
|
||||||
|
printf(" default value: 0. do not use if you dont know what it means.\n");
|
||||||
|
printf(" --random-drop <number> simulate packet loss, unit: 0.01%%. default value: 0.\n");
|
||||||
|
printf(" --disable-obscure <number> disable obscure, to save a bit bandwidth and cpu.\n");
|
||||||
|
// printf(" --disable-xor <number> disable xor\n");
|
||||||
|
|
||||||
|
printf("developer options:\n");
|
||||||
|
printf(" --fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you\n");
|
||||||
|
printf(" can change fec encode parameters dynamically, check readme.md in repository for\n");
|
||||||
|
printf(" supported commands.\n");
|
||||||
|
printf(" -j ,--jitter jmin:jmax similiar to -j above, but create jitter randomly between jmin and jmax\n");
|
||||||
|
printf(" -i,--interval imin:imax similiar to -i above, but scatter randomly between imin and imax\n");
|
||||||
|
printf(" --decode-buf <number> size of buffer of fec decoder,u nit: packet, default: 2000\n");
|
||||||
|
printf(" --fix-latency <number> try to stabilize latency, only for mode 0\n");
|
||||||
|
printf(" --delay-capacity <number> max number of delayed packets\n");
|
||||||
|
printf(" --disable-fec <number> completely disable fec, turn the program into a normal udp tunnel\n");
|
||||||
|
printf(" --sock-buf <number> buf size for socket, >=10 and <=10240, unit: kbyte, default: 1024\n");
|
||||||
|
printf("log and help options:\n");
|
||||||
|
printf(" --log-level <number> 0: never 1: fatal 2: error 3: warn \n");
|
||||||
|
printf(" 4: info (default) 5: debug 6: trace\n");
|
||||||
|
printf(" --log-position enable file name, function name, line number in log\n");
|
||||||
|
printf(" --disable-color disable log color\n");
|
||||||
|
printf(" -h,--help print this help message\n");
|
||||||
|
|
||||||
|
//printf("common options,these options must be same on both side\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
//working_mode=tunnel_mode;
|
//working_mode=tunnel_mode;
|
||||||
@@ -25,33 +87,41 @@ int main(int argc, char *argv[])
|
|||||||
assert(sizeof(i16_t)==2);
|
assert(sizeof(i16_t)==2);
|
||||||
dup2(1, 2); //redirect stderr to stdout
|
dup2(1, 2); //redirect stderr to stdout
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
print_help();
|
||||||
|
myexit( -1);
|
||||||
|
}
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0)
|
||||||
|
{
|
||||||
|
print_help();
|
||||||
|
myexit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
process_arg(argc,argv);
|
process_arg(argc,argv);
|
||||||
|
|
||||||
delay_manager.set_capacity(delay_capacity);
|
delay_manager.set_capacity(delay_capacity);
|
||||||
local_ip_uint32=inet_addr(local_ip);
|
local_ip_uint32=inet_addr(local_ip);
|
||||||
remote_ip_uint32=inet_addr(remote_ip);
|
remote_ip_uint32=inet_addr(remote_ip);
|
||||||
|
sub_net_uint32=inet_addr(sub_net);
|
||||||
|
|
||||||
if(working_mode==tunnel_mode)
|
if(strlen(tun_dev)==0)
|
||||||
{
|
{
|
||||||
if(client_or_server==client_mode)
|
sprintf(tun_dev,"tun%u",get_true_random_number()%1000);
|
||||||
{
|
}
|
||||||
tunnel_client_event_loop();
|
|
||||||
}
|
if(client_or_server==client_mode)
|
||||||
else
|
{
|
||||||
{
|
tunnel_client_event_loop();
|
||||||
tunnel_server_event_loop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(client_or_server==client_mode)
|
tunnel_server_event_loop();
|
||||||
{
|
|
||||||
tun_dev_client_event_loop();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tun_dev_server_event_loop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
5
makefile
5
makefile
@@ -8,12 +8,12 @@ cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
|||||||
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
||||||
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb
|
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb
|
||||||
|
|
||||||
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp tun_dev.cpp misc.cpp tunnel.cpp
|
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp misc.cpp tunnel.cpp
|
||||||
|
|
||||||
NAME=speederv2
|
NAME=speederv2
|
||||||
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
|
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
|
||||||
|
|
||||||
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'`
|
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speederv2_\1/g'` version.txt
|
||||||
|
|
||||||
all:git_version
|
all:git_version
|
||||||
rm -f ${NAME}
|
rm -f ${NAME}
|
||||||
@@ -56,6 +56,7 @@ cross3:git_version
|
|||||||
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
|
||||||
|
|
||||||
release: ${TARGETS}
|
release: ${TARGETS}
|
||||||
|
cp git_version.h version.txt
|
||||||
tar -zcvf ${TAR}
|
tar -zcvf ${TAR}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
142
misc.cpp
142
misc.cpp
@@ -15,6 +15,7 @@ int mtu_warn=1350;
|
|||||||
|
|
||||||
int disable_mtu_warn=1;
|
int disable_mtu_warn=1;
|
||||||
int disable_fec=0;
|
int disable_fec=0;
|
||||||
|
int disable_checksum=0;
|
||||||
|
|
||||||
int debug_force_flush_fec=0;
|
int debug_force_flush_fec=0;
|
||||||
|
|
||||||
@@ -40,8 +41,17 @@ int time_mono_test=0;
|
|||||||
int delay_capacity=0;
|
int delay_capacity=0;
|
||||||
|
|
||||||
|
|
||||||
|
char sub_net[100]="10.22.22.0";
|
||||||
|
u32_t sub_net_uint32=0;
|
||||||
|
|
||||||
|
char tun_dev[100]="";
|
||||||
|
|
||||||
|
|
||||||
|
int keep_reconnect=0;
|
||||||
|
|
||||||
|
int tun_mtu=1500;
|
||||||
|
|
||||||
|
int mssfix=1;
|
||||||
|
|
||||||
|
|
||||||
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
|
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay)
|
||||||
@@ -55,13 +65,17 @@ int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,ch
|
|||||||
inner_stat_t &inner_stat=conn_info.stat.normal_to_fec;
|
inner_stat_t &inner_stat=conn_info.stat.normal_to_fec;
|
||||||
if(disable_fec)
|
if(disable_fec)
|
||||||
{
|
{
|
||||||
assert(data!=0);
|
if(data==0)
|
||||||
|
{
|
||||||
|
out_n=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//assert(data!=0);
|
||||||
inner_stat.input_packet_num++;
|
inner_stat.input_packet_num++;
|
||||||
inner_stat.input_packet_size+=len;
|
inner_stat.input_packet_size+=len;
|
||||||
inner_stat.output_packet_num++;
|
inner_stat.output_packet_num++;
|
||||||
inner_stat.output_packet_size+=len;
|
inner_stat.output_packet_size+=len;
|
||||||
|
|
||||||
if(data==0) return 0;
|
|
||||||
out_n=1;
|
out_n=1;
|
||||||
static char *data_static;
|
static char *data_static;
|
||||||
data_static=data;
|
data_static=data;
|
||||||
@@ -166,7 +180,11 @@ int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,ch
|
|||||||
inner_stat.output_packet_num++;
|
inner_stat.output_packet_num++;
|
||||||
inner_stat.output_packet_size+=len;
|
inner_stat.output_packet_size+=len;
|
||||||
|
|
||||||
if(data==0) return 0;
|
if(data==0)
|
||||||
|
{
|
||||||
|
out_n=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
out_n=1;
|
out_n=1;
|
||||||
static char *data_static;
|
static char *data_static;
|
||||||
data_static=data;
|
data_static=data;
|
||||||
@@ -472,7 +490,7 @@ int unit_test()
|
|||||||
int * len;
|
int * len;
|
||||||
fec_decode_manager.output(n,s_arr,len);
|
fec_decode_manager.output(n,s_arr,len);
|
||||||
|
|
||||||
fec_encode_manager.re_init(3,2,g_fec_mtu,g_fec_queue_len,g_fec_timeout,1);
|
fec_encode_manager.reset_fec_parameter(3,2,g_fec_mtu,g_fec_queue_len,g_fec_timeout,1);
|
||||||
|
|
||||||
fec_encode_manager.input((char *) a.c_str(), a.length());
|
fec_encode_manager.input((char *) a.c_str(), a.length());
|
||||||
fec_encode_manager.output(n,s_arr,len);
|
fec_encode_manager.output(n,s_arr,len);
|
||||||
@@ -541,6 +559,7 @@ void process_arg(int argc, char *argv[])
|
|||||||
{"disable-fec", no_argument, 0, 1},
|
{"disable-fec", no_argument, 0, 1},
|
||||||
{"disable-obscure", no_argument, 0, 1},
|
{"disable-obscure", no_argument, 0, 1},
|
||||||
{"disable-xor", no_argument, 0, 1},
|
{"disable-xor", no_argument, 0, 1},
|
||||||
|
{"disable-checksum", no_argument, 0, 1},
|
||||||
{"fix-latency", no_argument, 0, 1},
|
{"fix-latency", no_argument, 0, 1},
|
||||||
{"sock-buf", required_argument, 0, 1},
|
{"sock-buf", required_argument, 0, 1},
|
||||||
{"random-drop", required_argument, 0, 1},
|
{"random-drop", required_argument, 0, 1},
|
||||||
@@ -554,15 +573,15 @@ void process_arg(int argc, char *argv[])
|
|||||||
{"fec", required_argument, 0,'f'},
|
{"fec", required_argument, 0,'f'},
|
||||||
{"jitter", required_argument, 0,'j'},
|
{"jitter", required_argument, 0,'j'},
|
||||||
{"fifo", required_argument, 0, 1},
|
{"fifo", required_argument, 0, 1},
|
||||||
{"tun-dev", optional_argument, 0, 1},
|
{"sub-net", required_argument, 0, 1},
|
||||||
|
{"tun-dev", required_argument, 0, 1},
|
||||||
|
{"tun-mtu", required_argument, 0, 1},
|
||||||
|
{"disable-mssfix", no_argument, 0, 1},
|
||||||
|
{"keep-reconnect", no_argument, 0, 1},
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
if (argc == 1)
|
|
||||||
{
|
|
||||||
print_help();
|
|
||||||
myexit( -1);
|
|
||||||
}
|
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if(strcmp(argv[i],"--unit-test")==0)
|
if(strcmp(argv[i],"--unit-test")==0)
|
||||||
@@ -571,14 +590,7 @@ void process_arg(int argc, char *argv[])
|
|||||||
myexit(0);
|
myexit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
{
|
|
||||||
if(strcmp(argv[i],"-h")==0||strcmp(argv[i],"--help")==0)
|
|
||||||
{
|
|
||||||
print_help();
|
|
||||||
myexit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if(strcmp(argv[i],"--log-level")==0)
|
if(strcmp(argv[i],"--log-level")==0)
|
||||||
@@ -609,11 +621,6 @@ void process_arg(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
log_bare(log_info, "\n");
|
log_bare(log_info, "\n");
|
||||||
|
|
||||||
if (argc == 1)
|
|
||||||
{
|
|
||||||
print_help();
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int no_l = 1, no_r = 1;
|
int no_l = 1, no_r = 1;
|
||||||
while ((opt = getopt_long(argc, argv, "l:r:hcsk:j:f:p:n:i:q:",long_options,&option_index)) != -1)
|
while ((opt = getopt_long(argc, argv, "l:r:hcsk:j:f:p:n:i:q:",long_options,&option_index)) != -1)
|
||||||
@@ -773,6 +780,11 @@ void process_arg(int argc, char *argv[])
|
|||||||
mylog(log_info,"xor disabled\n");
|
mylog(log_info,"xor disabled\n");
|
||||||
disable_xor=1;
|
disable_xor=1;
|
||||||
}
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"disable-checksum")==0)
|
||||||
|
{
|
||||||
|
disable_checksum=1;
|
||||||
|
mylog(log_warn,"checksum disabled\n");
|
||||||
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"fix-latency")==0)
|
else if(strcmp(long_options[option_index].name,"fix-latency")==0)
|
||||||
{
|
{
|
||||||
mylog(log_info,"fix-latency enabled\n");
|
mylog(log_info,"fix-latency enabled\n");
|
||||||
@@ -872,12 +884,35 @@ void process_arg(int argc, char *argv[])
|
|||||||
|
|
||||||
mylog(log_info,"fifo_file =%s \n",fifo_file);
|
mylog(log_info,"fifo_file =%s \n",fifo_file);
|
||||||
}
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"keep-reconnect")==0)
|
||||||
|
{
|
||||||
|
keep_reconnect=1;
|
||||||
|
mylog(log_info,"keep_reconnect enabled\n");
|
||||||
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"sub-net")==0)
|
||||||
|
{
|
||||||
|
sscanf(optarg,"%s",sub_net);
|
||||||
|
mylog(log_info,"sub_net %s\n",sub_net);
|
||||||
|
|
||||||
|
}
|
||||||
else if(strcmp(long_options[option_index].name,"tun-dev")==0)
|
else if(strcmp(long_options[option_index].name,"tun-dev")==0)
|
||||||
{
|
{
|
||||||
//sscanf(optarg,"%s",fifo_file);
|
sscanf(optarg,"%s",tun_dev);
|
||||||
mylog(log_info,"enabled tun-dev mode\n");
|
mylog(log_info,"tun_dev=%s\n",tun_dev);
|
||||||
|
|
||||||
|
mylog(log_info,"running at tun-dev mode\n");
|
||||||
working_mode=tun_dev_mode;
|
working_mode=tun_dev_mode;
|
||||||
}
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"tun-mtu")==0)
|
||||||
|
{
|
||||||
|
sscanf(optarg,"%d",&tun_mtu);
|
||||||
|
mylog(log_warn,"changed tun_mtu,tun_mtu=%d\n",tun_mtu);
|
||||||
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"disable-mssfix")==0)
|
||||||
|
{
|
||||||
|
mssfix=0;
|
||||||
|
mylog(log_warn,"mssfix disabled\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"unknown option\n");
|
mylog(log_fatal,"unknown option\n");
|
||||||
@@ -937,60 +972,3 @@ void process_arg(int argc, char *argv[])
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_help()
|
|
||||||
{
|
|
||||||
char git_version_buf[100]={0};
|
|
||||||
strncpy(git_version_buf,gitversion,10);
|
|
||||||
|
|
||||||
printf("UDPspeeder V2\n");
|
|
||||||
printf("git version: %s ",git_version_buf);
|
|
||||||
printf("build date: %s %s\n",__DATE__,__TIME__);
|
|
||||||
printf("repository: https://github.com/wangyu-/UDPspeeder\n");
|
|
||||||
printf("\n");
|
|
||||||
printf("usage:\n");
|
|
||||||
printf(" run as client: ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]\n");
|
|
||||||
printf(" run as server: ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]\n");
|
|
||||||
printf("\n");
|
|
||||||
printf("common options, must be same on both sides:\n");
|
|
||||||
printf(" -k,--key <string> key for simple xor encryption. if not set, xor is disabled\n");
|
|
||||||
|
|
||||||
printf("main options:\n");
|
|
||||||
printf(" -f,--fec x:y forward error correction, send y redundant packets for every x packets\n");
|
|
||||||
printf(" --timeout <number> how long could a packet be held in queue before doing fec, unit: ms, default: 8ms\n");
|
|
||||||
printf(" --mode <number> fec-mode,available values: 0, 1; 0 cost less bandwidth, 1 cost less latency(default)\n");
|
|
||||||
printf(" --report <number> turn on send/recv report, and set a period for reporting, unit: s\n");
|
|
||||||
|
|
||||||
printf("advanced options:\n");
|
|
||||||
printf(" --mtu <number> mtu. for mode 0, the program will split packet to segment smaller than mtu_value.\n");
|
|
||||||
printf(" for mode 1, no packet will be split, the program just check if the mtu is exceed.\n");
|
|
||||||
printf(" default value: 1250\n");
|
|
||||||
printf(" -j,--jitter <number> simulated jitter. randomly delay first packet for 0~<number> ms, default value: 0.\n");
|
|
||||||
printf(" do not use if you dont know what it means.\n");
|
|
||||||
printf(" -i,--interval <number> scatter each fec group to a interval of <number> ms, to protect burst packet loss.\n");
|
|
||||||
printf(" default value: 0. do not use if you dont know what it means.\n");
|
|
||||||
printf(" --random-drop <number> simulate packet loss, unit: 0.01%%. default value: 0\n");
|
|
||||||
printf(" --disable-obscure <number> disable obscure, to save a bit bandwidth and cpu\n");
|
|
||||||
// printf(" --disable-xor <number> disable xor\n");
|
|
||||||
|
|
||||||
printf("developer options:\n");
|
|
||||||
printf(" --fifo <string> use a fifo(named pipe) for sending commands to the running program, so that you\n");
|
|
||||||
printf(" can change fec encode parameters dynamically, check readme.md in repository for\n");
|
|
||||||
printf(" supported commands.\n");
|
|
||||||
printf(" -j ,--jitter jmin:jmax similiar to -j above, but create jitter randomly between jmin and jmax\n");
|
|
||||||
printf(" -i,--interval imin:imax similiar to -i above, but scatter randomly between imin and imax\n");
|
|
||||||
printf(" -q,--queue-len <number> max fec queue len, only for mode 0\n");
|
|
||||||
printf(" --decode-buf <number> size of buffer of fec decoder,u nit: packet, default: 2000\n");
|
|
||||||
printf(" --fix-latency <number> try to stabilize latency, only for mode 0\n");
|
|
||||||
printf(" --delay-capacity <number> max number of delayed packets\n");
|
|
||||||
printf(" --disable-fec <number> completely disable fec, turn the program into a normal udp tunnel\n");
|
|
||||||
printf(" --sock-buf <number> buf size for socket, >=10 and <=10240, unit: kbyte, default: 1024\n");
|
|
||||||
printf("log and help options:\n");
|
|
||||||
printf(" --log-level <number> 0: never 1: fatal 2: error 3: warn \n");
|
|
||||||
printf(" 4: info (default) 5: debug 6: trace\n");
|
|
||||||
printf(" --log-position enable file name, function name, line number in log\n");
|
|
||||||
printf(" --disable-color disable log color\n");
|
|
||||||
printf(" -h,--help print this help message\n");
|
|
||||||
|
|
||||||
//printf("common options,these options must be same on both side\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
12
misc.h
12
misc.h
@@ -13,7 +13,7 @@
|
|||||||
#include "fd_manager.h"
|
#include "fd_manager.h"
|
||||||
#include "delay_manager.h"
|
#include "delay_manager.h"
|
||||||
#include "fec_manager.h"
|
#include "fec_manager.h"
|
||||||
#include "git_version.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern char fifo_file[1000];
|
extern char fifo_file[1000];
|
||||||
@@ -22,6 +22,7 @@ extern int mtu_warn;
|
|||||||
|
|
||||||
extern int disable_mtu_warn;
|
extern int disable_mtu_warn;
|
||||||
extern int disable_fec;
|
extern int disable_fec;
|
||||||
|
extern int disable_checksum;
|
||||||
|
|
||||||
extern int debug_force_flush_fec;
|
extern int debug_force_flush_fec;
|
||||||
|
|
||||||
@@ -46,7 +47,11 @@ extern int time_mono_test;
|
|||||||
|
|
||||||
extern int delay_capacity;
|
extern int delay_capacity;
|
||||||
|
|
||||||
|
extern int keep_reconnect;
|
||||||
|
|
||||||
|
extern int tun_mtu;
|
||||||
|
|
||||||
|
extern int mssfix;
|
||||||
|
|
||||||
|
|
||||||
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay);
|
||||||
@@ -58,9 +63,12 @@ int handle_command(char *s);
|
|||||||
|
|
||||||
int unit_test();
|
int unit_test();
|
||||||
|
|
||||||
void print_help();
|
//void print_help();
|
||||||
|
|
||||||
void process_arg(int argc, char *argv[]);
|
void process_arg(int argc, char *argv[]);
|
||||||
|
|
||||||
|
extern char sub_net[100];
|
||||||
|
extern u32_t sub_net_uint32;
|
||||||
|
extern char tun_dev[100];
|
||||||
|
|
||||||
#endif /* MISC_H_ */
|
#endif /* MISC_H_ */
|
||||||
|
21
packet.cpp
21
packet.cpp
@@ -9,6 +9,7 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
int iv_min=4;
|
int iv_min=4;
|
||||||
int iv_max=32;//< 256;
|
int iv_max=32;//< 256;
|
||||||
@@ -177,9 +178,7 @@ int my_send(const dest_t &dest,char *data,int len)
|
|||||||
{
|
{
|
||||||
if(dest.cook)
|
if(dest.cook)
|
||||||
{
|
{
|
||||||
put_crc32(data,len);
|
do_cook(data,len);
|
||||||
if(!disable_obscure)do_obscure(data,len);
|
|
||||||
if(!disable_xor)encrypt_0(data,len,key_string);
|
|
||||||
}
|
}
|
||||||
switch(dest.type)
|
switch(dest.type)
|
||||||
{
|
{
|
||||||
@@ -201,6 +200,11 @@ int my_send(const dest_t &dest,char *data,int len)
|
|||||||
return send_fd(dest.inner.fd,data,len,0);
|
return send_fd(dest.inner.fd,data,len,0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case type_write_fd:
|
||||||
|
{
|
||||||
|
return write(dest.inner.fd,data,len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case type_fd64:
|
case type_fd64:
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -312,6 +316,7 @@ int get_conv0(u32_t &conv,const char *input,int len_in,char *&output,int &len_ou
|
|||||||
}
|
}
|
||||||
int put_crc32(char * s,int &len)
|
int put_crc32(char * s,int &len)
|
||||||
{
|
{
|
||||||
|
if(disable_checksum)return 0;
|
||||||
assert(len>=0);
|
assert(len>=0);
|
||||||
//if(len<0) return -1;
|
//if(len<0) return -1;
|
||||||
u32_t crc32=crc32h((unsigned char *)s,len);
|
u32_t crc32=crc32h((unsigned char *)s,len);
|
||||||
@@ -322,6 +327,14 @@ int put_crc32(char * s,int &len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int do_cook(char * data,int &len)
|
||||||
|
{
|
||||||
|
put_crc32(data,len);
|
||||||
|
if(!disable_obscure)do_obscure(data,len);
|
||||||
|
if(!disable_xor)encrypt_0(data,len,key_string);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int de_cook(char * s,int &len)
|
int de_cook(char * s,int &len)
|
||||||
{
|
{
|
||||||
if(!disable_xor)decrypt_0(s,len,key_string);
|
if(!disable_xor)decrypt_0(s,len,key_string);
|
||||||
@@ -344,8 +357,8 @@ int de_cook(char * s,int &len)
|
|||||||
}
|
}
|
||||||
int rm_crc32(char * s,int &len)
|
int rm_crc32(char * s,int &len)
|
||||||
{
|
{
|
||||||
|
if(disable_checksum)return 0;
|
||||||
assert(len>=0);
|
assert(len>=0);
|
||||||
|
|
||||||
len-=sizeof(u32_t);
|
len-=sizeof(u32_t);
|
||||||
if(len<0) return -1;
|
if(len<0) return -1;
|
||||||
u32_t crc32_in=read_u32(s+len);
|
u32_t crc32_in=read_u32(s+len);
|
||||||
|
1
packet.h
1
packet.h
@@ -42,5 +42,6 @@ int put_conv(u32_t conv,const char * input,int len_in,char *&output,int &len_out
|
|||||||
int get_conv(u32_t &conv,const char *input,int len_in,char *&output,int &len_out );
|
int get_conv(u32_t &conv,const char *input,int len_in,char *&output,int &len_out );
|
||||||
int put_crc32(char * s,int &len);
|
int put_crc32(char * s,int &len);
|
||||||
int rm_crc32(char * s,int &len);
|
int rm_crc32(char * s,int &len);
|
||||||
|
int do_cook(char * data,int &len);
|
||||||
int de_cook(char * s,int &len);
|
int de_cook(char * s,int &len);
|
||||||
#endif /* PACKET_H_ */
|
#endif /* PACKET_H_ */
|
||||||
|
411
tun_dev.cpp
411
tun_dev.cpp
@@ -1,411 +0,0 @@
|
|||||||
/*
|
|
||||||
* tun.cpp
|
|
||||||
*
|
|
||||||
* Created on: Oct 26, 2017
|
|
||||||
* Author: root
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
int get_tun_fd(char * dev_name)
|
|
||||||
{
|
|
||||||
int tun_fd=open("/dev/net/tun",O_RDWR);
|
|
||||||
|
|
||||||
if(tun_fd <0)
|
|
||||||
{
|
|
||||||
mylog(log_fatal,"open /dev/net/tun failed");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
struct ifreq ifr;
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
|
||||||
ifr.ifr_flags = IFF_TUN|IFF_NO_PI;
|
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, dev_name, IFNAMSIZ);
|
|
||||||
|
|
||||||
if(ioctl(tun_fd, TUNSETIFF, (void *)&ifr) != 0)
|
|
||||||
{
|
|
||||||
mylog(log_fatal,"open /dev/net/tun failed");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
return tun_fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
int set_if(char *if_name,char * local_ip,char * remote_ip,int mtu)
|
|
||||||
{
|
|
||||||
//printf("i m here1\n");
|
|
||||||
struct ifreq ifr;
|
|
||||||
struct sockaddr_in sai;
|
|
||||||
memset(&ifr,0,sizeof(ifr));
|
|
||||||
memset(&sai, 0, sizeof(struct sockaddr));
|
|
||||||
|
|
||||||
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
|
|
||||||
|
|
||||||
sai.sin_family = AF_INET;
|
|
||||||
sai.sin_port = 0;
|
|
||||||
sai.sin_addr.s_addr = inet_addr(local_ip);
|
|
||||||
memcpy(&ifr.ifr_addr,&sai, sizeof(struct sockaddr));
|
|
||||||
assert(ioctl(sockfd, SIOCSIFADDR, &ifr)==0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sai.sin_addr.s_addr = inet_addr(local_ip);
|
|
||||||
memcpy(&ifr.ifr_addr,&sai, sizeof(struct sockaddr));
|
|
||||||
assert(ioctl(sockfd, SIOCSIFADDR, &ifr)==0);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sai.sin_addr.s_addr = inet_addr(remote_ip);
|
|
||||||
memcpy(&ifr.ifr_addr,&sai, sizeof(struct sockaddr));
|
|
||||||
assert(ioctl(sockfd, SIOCSIFDSTADDR, &ifr)==0);
|
|
||||||
|
|
||||||
ifr.ifr_mtu=mtu;
|
|
||||||
assert(ioctl(sockfd, SIOCSIFMTU, &ifr)==0);
|
|
||||||
|
|
||||||
|
|
||||||
assert(ioctl(sockfd, SIOCGIFFLAGS, &ifr)==0);
|
|
||||||
// ifr.ifr_flags |= ( IFF_UP|IFF_POINTOPOINT|IFF_RUNNING|IFF_NOARP|IFF_MULTICAST );
|
|
||||||
ifr.ifr_flags |= ( IFF_UP|IFF_POINTOPOINT|IFF_RUNNING|IFF_NOARP|IFF_MULTICAST );
|
|
||||||
assert(ioctl(sockfd, SIOCSIFFLAGS, &ifr)==0);
|
|
||||||
|
|
||||||
//printf("i m here2\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//enum tun_header_t {header_reserved=0,header_normal=1,header_new=2,header_reject=3};
|
|
||||||
const char header_normal=1;
|
|
||||||
const char header_new_connect=2;
|
|
||||||
const char header_reject=3;
|
|
||||||
|
|
||||||
int put_header(char header,char *& data,int &len)
|
|
||||||
{
|
|
||||||
assert(len>=0);
|
|
||||||
data=data-1;
|
|
||||||
data[0]=header;
|
|
||||||
len+=1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int get_header(char &header,char *& data,int &len)
|
|
||||||
{
|
|
||||||
assert(len>=0);
|
|
||||||
if(len<1) return -1;
|
|
||||||
header=data[0];
|
|
||||||
data=data+1;
|
|
||||||
len-=1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int tun_dev_client_event_loop()
|
|
||||||
{
|
|
||||||
char buf0[buf_len+100];
|
|
||||||
char *data=buf0+100;
|
|
||||||
int len;
|
|
||||||
int i,j,k,ret;
|
|
||||||
int epoll_fd,tun_fd;
|
|
||||||
|
|
||||||
int remote_fd;
|
|
||||||
fd64_t remote_fd64;
|
|
||||||
|
|
||||||
tun_fd=get_tun_fd("tun11");
|
|
||||||
assert(tun_fd>0);
|
|
||||||
|
|
||||||
assert(new_connected_socket(remote_fd,remote_ip_uint32,remote_port)==0);
|
|
||||||
remote_fd64=fd_manager.create(remote_fd);
|
|
||||||
|
|
||||||
assert(set_if("tun11","10.0.0.2","10.0.0.1",1000)==0);
|
|
||||||
|
|
||||||
epoll_fd = epoll_create1(0);
|
|
||||||
assert(epoll_fd>0);
|
|
||||||
|
|
||||||
const int max_events = 4096;
|
|
||||||
struct epoll_event ev, events[max_events];
|
|
||||||
if (epoll_fd < 0) {
|
|
||||||
mylog(log_fatal,"epoll return %d\n", epoll_fd);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.events = EPOLLIN;
|
|
||||||
ev.data.u64 = remote_fd64;
|
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, remote_fd, &ev);
|
|
||||||
if (ret!=0) {
|
|
||||||
mylog(log_fatal,"add remote_fd64 error\n");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.events = EPOLLIN;
|
|
||||||
ev.data.u64 = tun_fd;
|
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, tun_fd, &ev);
|
|
||||||
if (ret!=0) {
|
|
||||||
mylog(log_fatal,"add tun_fd error\n");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
dest_t dest;
|
|
||||||
dest.type=type_fd64;
|
|
||||||
dest.inner.fd64=remote_fd64;
|
|
||||||
//dest.conv=conv;
|
|
||||||
//dest.inner.ip_port=dest_ip_port;
|
|
||||||
//dest.cook=1;
|
|
||||||
|
|
||||||
|
|
||||||
int got_feed_back=0;
|
|
||||||
|
|
||||||
while(1)////////////////////////
|
|
||||||
{
|
|
||||||
|
|
||||||
if(about_to_exit) myexit(0);
|
|
||||||
|
|
||||||
int nfds = epoll_wait(epoll_fd, events, max_events, 180 * 1000);
|
|
||||||
if (nfds < 0) { //allow zero
|
|
||||||
if(errno==EINTR )
|
|
||||||
{
|
|
||||||
mylog(log_info,"epoll interrupted by signal\n");
|
|
||||||
myexit(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int idx;
|
|
||||||
for (idx = 0; idx < nfds; ++idx)
|
|
||||||
{
|
|
||||||
if(events[idx].data.u64==(u64_t)tun_fd)
|
|
||||||
{
|
|
||||||
len=read(tun_fd,data,max_data_len);
|
|
||||||
assert(len>=0);
|
|
||||||
|
|
||||||
mylog(log_trace,"Received packet from tun,len: %d\n",len);
|
|
||||||
|
|
||||||
if(got_feed_back==0)
|
|
||||||
put_header(header_new_connect,data,len);
|
|
||||||
else
|
|
||||||
put_header(header_normal,data,len);
|
|
||||||
|
|
||||||
delay_manager.add(0,dest,data,len);;
|
|
||||||
}
|
|
||||||
else if(events[idx].data.u64==(u64_t)remote_fd64)
|
|
||||||
{
|
|
||||||
fd64_t fd64=events[idx].data.u64;
|
|
||||||
int fd=fd_manager.to_fd(fd64);
|
|
||||||
|
|
||||||
len=recv(fd,data,max_data_len,0);
|
|
||||||
|
|
||||||
if(len<0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"recv return %d,errno=%s\n",len,strerror(errno));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char header=0;
|
|
||||||
if(get_header(header,data,len)!=0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"get_header failed\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(header==header_reject)
|
|
||||||
{
|
|
||||||
mylog(log_fatal,"server switched to handle another client,exit\n");
|
|
||||||
myexit(-1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if(header==header_normal)
|
|
||||||
{
|
|
||||||
got_feed_back=1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(log_warn,"invalid header\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mylog(log_trace,"Received packet from udp,len: %d\n",len);
|
|
||||||
assert(len>=0);
|
|
||||||
|
|
||||||
assert(write(tun_fd,data,len)>=0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delay_manager.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int tun_dev_server_event_loop()
|
|
||||||
{
|
|
||||||
char buf0[buf_len+100];
|
|
||||||
char *data=buf0+100;
|
|
||||||
int len;
|
|
||||||
int i,j,k,ret;
|
|
||||||
int epoll_fd,tun_fd;
|
|
||||||
|
|
||||||
int local_listen_fd;
|
|
||||||
//fd64_t local_listen_fd64;
|
|
||||||
|
|
||||||
tun_fd=get_tun_fd("tun11");
|
|
||||||
assert(tun_fd>0);
|
|
||||||
|
|
||||||
assert(new_listen_socket(local_listen_fd,local_ip_uint32,local_port)==0);
|
|
||||||
// local_listen_fd64=fd_manager.create(local_listen_fd);
|
|
||||||
|
|
||||||
assert(set_if("tun11","10.0.0.1","10.0.0.2",1000)==0);
|
|
||||||
|
|
||||||
epoll_fd = epoll_create1(0);
|
|
||||||
assert(epoll_fd>0);
|
|
||||||
|
|
||||||
const int max_events = 4096;
|
|
||||||
struct epoll_event ev, events[max_events];
|
|
||||||
if (epoll_fd < 0) {
|
|
||||||
mylog(log_fatal,"epoll return %d\n", epoll_fd);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.events = EPOLLIN;
|
|
||||||
ev.data.u64 = local_listen_fd;
|
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, local_listen_fd, &ev);
|
|
||||||
if (ret!=0) {
|
|
||||||
mylog(log_fatal,"add udp_listen_fd error\n");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.events = EPOLLIN;
|
|
||||||
ev.data.u64 = tun_fd;
|
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, tun_fd, &ev);
|
|
||||||
if (ret!=0) {
|
|
||||||
mylog(log_fatal,"add tun_fd error\n");
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//ip_port_t dest_ip_port;
|
|
||||||
|
|
||||||
dest_t dest;
|
|
||||||
dest.type=type_fd_ip_port;
|
|
||||||
|
|
||||||
dest.inner.fd_ip_port.fd=local_listen_fd;
|
|
||||||
dest.inner.fd_ip_port.ip_port.ip=0;
|
|
||||||
dest.inner.fd_ip_port.ip_port.port=0;
|
|
||||||
//dest.conv=conv;
|
|
||||||
//dest.inner.ip_port=dest_ip_port;
|
|
||||||
//dest.cook=1;
|
|
||||||
|
|
||||||
while(1)////////////////////////
|
|
||||||
{
|
|
||||||
|
|
||||||
if(about_to_exit) myexit(0);
|
|
||||||
|
|
||||||
int nfds = epoll_wait(epoll_fd, events, max_events, 180 * 1000);
|
|
||||||
if (nfds < 0) { //allow zero
|
|
||||||
if(errno==EINTR )
|
|
||||||
{
|
|
||||||
mylog(log_info,"epoll interrupted by signal\n");
|
|
||||||
myexit(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
|
||||||
myexit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int idx;
|
|
||||||
for (idx = 0; idx < nfds; ++idx)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(events[idx].data.u64==(u64_t)local_listen_fd)
|
|
||||||
{
|
|
||||||
struct sockaddr_in udp_new_addr_in={0};
|
|
||||||
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
|
|
||||||
if ((len = recvfrom(local_listen_fd, data, max_data_len, 0,
|
|
||||||
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
|
|
||||||
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
|
|
||||||
continue;
|
|
||||||
//myexit(1);
|
|
||||||
};
|
|
||||||
char header=0;
|
|
||||||
if(get_header(header,data,len)!=0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"get_header failed\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((dest.inner.fd_ip_port.ip_port.ip==udp_new_addr_in.sin_addr.s_addr) && (dest.inner.fd_ip_port.ip_port.port=ntohs(udp_new_addr_in.sin_port)))
|
|
||||||
{
|
|
||||||
if(header!=header_new_connect&& header!=header_normal)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"invalid header\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(header==header_new_connect)
|
|
||||||
{
|
|
||||||
mylog(log_info,"new connection from %s:%d \n", inet_ntoa(udp_new_addr_in.sin_addr),
|
|
||||||
ntohs(udp_new_addr_in.sin_port));
|
|
||||||
dest.inner.fd_ip_port.ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
|
|
||||||
dest.inner.fd_ip_port.ip_port.port=ntohs(udp_new_addr_in.sin_port);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mylog(log_info,"rejected connection from %s:%d\n", inet_ntoa(udp_new_addr_in.sin_addr),ntohs(udp_new_addr_in.sin_port));
|
|
||||||
|
|
||||||
|
|
||||||
len=1;
|
|
||||||
data[0]=header_reject;
|
|
||||||
|
|
||||||
dest_t tmp_dest;
|
|
||||||
tmp_dest.type=type_fd_ip_port;
|
|
||||||
|
|
||||||
tmp_dest.inner.fd_ip_port.fd=local_listen_fd;
|
|
||||||
tmp_dest.inner.fd_ip_port.ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
|
|
||||||
tmp_dest.inner.fd_ip_port.ip_port.port=ntohs(udp_new_addr_in.sin_port);
|
|
||||||
|
|
||||||
delay_manager.add(0,tmp_dest,data,len);;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mylog(log_trace,"Received packet from %s:%d,len: %d\n", inet_ntoa(udp_new_addr_in.sin_addr),
|
|
||||||
ntohs(udp_new_addr_in.sin_port),len);
|
|
||||||
|
|
||||||
ret=write(tun_fd,data,len);
|
|
||||||
if( ret<0 )
|
|
||||||
{
|
|
||||||
mylog(log_warn,"write to tun failed len=%d ret=%d\n errno=%s\n",len,ret,strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(events[idx].data.u64==(u64_t)tun_fd)
|
|
||||||
{
|
|
||||||
len=read(tun_fd,data,max_data_len);
|
|
||||||
assert(len>=0);
|
|
||||||
|
|
||||||
mylog(log_trace,"Received packet from tun,len: %d\n",len);
|
|
||||||
|
|
||||||
if(dest.inner.fd64_ip_port.ip_port.to_u64()==0)
|
|
||||||
{
|
|
||||||
mylog(log_warn,"there is no client yet\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
put_header(header_normal,data,len);
|
|
||||||
|
|
||||||
delay_manager.add(0,dest,data,len);;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delay_manager.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
16
tun_dev.h
16
tun_dev.h
@@ -1,16 +0,0 @@
|
|||||||
/*
|
|
||||||
* tun.h
|
|
||||||
*
|
|
||||||
* Created on: Oct 26, 2017
|
|
||||||
* Author: root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TUN_DEV_H_
|
|
||||||
#define TUN_DEV_H_
|
|
||||||
|
|
||||||
|
|
||||||
int tun_dev_client_event_loop();
|
|
||||||
|
|
||||||
int tun_dev_server_event_loop();
|
|
||||||
|
|
||||||
#endif /* TUN_H_ */
|
|
20
tunnel.cpp
20
tunnel.cpp
@@ -70,12 +70,12 @@ int tunnel_client_event_loop()
|
|||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64_t fd64=conn_info.fec_encode_manager.get_timer_fd64();
|
u64_t tmp_fd64=conn_info.fec_encode_manager.get_timer_fd64();
|
||||||
ev.events = EPOLLIN;
|
ev.events = EPOLLIN;
|
||||||
ev.data.u64 = fd64;
|
ev.data.u64 = tmp_fd64;
|
||||||
|
|
||||||
mylog(log_debug,"conn_info.fec_encode_manager.get_timer_fd64()=%llu\n",conn_info.fec_encode_manager.get_timer_fd64());
|
mylog(log_debug,"conn_info.fec_encode_manager.get_timer_fd64()=%llu\n",conn_info.fec_encode_manager.get_timer_fd64());
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd_manager.to_fd(fd64), &ev);
|
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd_manager.to_fd(tmp_fd64), &ev);
|
||||||
if (ret!= 0) {
|
if (ret!= 0) {
|
||||||
mylog(log_fatal,"add fec_encode_manager.get_timer_fd64() error\n");
|
mylog(log_fatal,"add fec_encode_manager.get_timer_fd64() error\n");
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
@@ -113,12 +113,12 @@ int tunnel_client_event_loop()
|
|||||||
if (nfds < 0) { //allow zero
|
if (nfds < 0) { //allow zero
|
||||||
if(errno==EINTR )
|
if(errno==EINTR )
|
||||||
{
|
{
|
||||||
mylog(log_info,"epoll interrupted by signal\n");
|
mylog(log_info,"epoll interrupted by signal continue\n");
|
||||||
myexit(0);
|
//myexit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
mylog(log_fatal,"epoll_wait return %d,%s\n", nfds,strerror(errno));
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,6 +173,7 @@ int tunnel_client_event_loop()
|
|||||||
|
|
||||||
if(events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64())
|
if(events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64())
|
||||||
{
|
{
|
||||||
|
fd64_t fd64=events[idx].data.u64;
|
||||||
mylog(log_trace,"events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64()\n");
|
mylog(log_trace,"events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64()\n");
|
||||||
|
|
||||||
//mylog(log_info,"timer!!!\n");
|
//mylog(log_info,"timer!!!\n");
|
||||||
@@ -314,6 +315,7 @@ int tunnel_client_event_loop()
|
|||||||
if(!conn_info.conv_manager.is_conv_used(conv))
|
if(!conn_info.conv_manager.is_conv_used(conv))
|
||||||
{
|
{
|
||||||
mylog(log_trace,"!conn_info.conv_manager.is_conv_used(conv)");
|
mylog(log_trace,"!conn_info.conv_manager.is_conv_used(conv)");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn_info.conv_manager.update_active_time(conv);
|
conn_info.conv_manager.update_active_time(conv);
|
||||||
@@ -415,12 +417,12 @@ int tunnel_server_event_loop()
|
|||||||
if (nfds < 0) { //allow zero
|
if (nfds < 0) { //allow zero
|
||||||
if(errno==EINTR )
|
if(errno==EINTR )
|
||||||
{
|
{
|
||||||
mylog(log_info,"epoll interrupted by signal\n");
|
mylog(log_info,"epoll interrupted by signal,continue\n");
|
||||||
myexit(0);
|
//myexit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
mylog(log_fatal,"epoll_wait return %d,%s\n", nfds,strerror(errno));
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user