77 Commits

Author SHA1 Message Date
wangyu-
ee9dab37fa fixed a issue of last commit; increase udp conv timeout to 180s 2017-11-17 01:39:00 -06:00
wangyu-
d25e1ea9df clear_it=it 2017-11-06 03:36:42 -06:00
wangyu-
3b5279235a fix var name 2017-09-27 12:13:09 -05:00
wangyu-
cccff0a8a5 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-09-27 11:51:47 -05:00
wangyu-
66da392357 fixed a log info 2017-09-27 11:23:17 -05:00
wangyu-
a5bad45780 allow dup_delay=0 2017-09-27 11:21:03 -05:00
wangyu-
b1a47bb8ea performance optimization for dup_max=0 2017-09-27 11:11:06 -05:00
wangyu-
00cffe1072 Update README.md 2017-09-20 03:20:03 -07:00
wangyu-
b5a873d073 Update README.md 2017-09-20 03:15:48 -07:00
wangyu-
8a2e2b8ce4 Update README.md 2017-09-20 03:14:17 -07:00
wangyu-
a13358cdb3 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-09-12 23:35:01 -05:00
wangyu-
a4b8c5f5b9 added debug info 2017-09-12 23:34:55 -05:00
wangyu-
916b5e94d8 Update README.md 2017-09-11 08:55:36 -07:00
wangyu-
19553d1bb8 Update README.md 2017-09-11 08:51:02 -07:00
wangyu-
b4bd385e88 trival 2017-09-11 10:29:24 -05:00
wangyu-
d985eb6634 trival 2017-09-11 10:28:32 -05:00
wangyu-
aa42887a67 fixed help page 2017-09-11 10:26:56 -05:00
wangyu-
0cafbff271 new targets,change to static compile 2017-09-10 04:04:07 -05:00
wangyu-
a04f976c20 Add files via upload 2017-09-03 21:54:11 -05:00
wangyu-
2837f3b955 Update README.md 2017-09-03 18:01:37 -07:00
wangyu-
83ec1296a3 Update README.md 2017-09-03 18:00:25 -07:00
wangyu-
edfc23e273 Update README.md 2017-09-03 17:58:31 -07:00
wangyu-
32c51decad Update README.md 2017-09-03 17:56:28 -07:00
wangyu-
9ce560d9d1 Add files via upload 2017-09-03 17:48:29 -05:00
wangyu-
3c333b59e6 Add files via upload 2017-09-03 17:45:57 -05:00
wangyu-
073eb5fc2d Add files via upload 2017-09-03 17:17:54 -05:00
wangyu-
8388c5dbce Update README.md 2017-09-03 15:12:59 -07:00
wangyu-
24e980069e Update README.md 2017-09-03 15:11:38 -07:00
wangyu-
9a42db3200 Add files via upload 2017-09-03 17:11:19 -05:00
wangyu-
7e0d9f99f2 Update README.md 2017-09-03 15:03:35 -07:00
wangyu-
88564a1f56 Add files via upload 2017-09-03 16:59:29 -05:00
wangyu-
a95c383cc6 Update README.md 2017-08-16 07:55:21 -07:00
wangyu-
f99de500ba Update README.md 2017-08-16 06:02:18 -07:00
wangyu-
aa7c520642 Update README.md 2017-08-16 05:46:34 -07:00
wangyu
a7e31940a0 add arm target in makefile 2017-08-16 20:41:19 +08:00
wangyu-
244f28cb1d Update README.md 2017-08-14 08:26:00 -07:00
wangyu-
39231d7939 Update README.md 2017-08-14 02:27:34 -07:00
wangyu-
e16d993c2e Update README.md 2017-08-14 02:26:46 -07:00
wangyu-
47ae2d94e7 Update README.md 2017-08-12 21:38:41 -07:00
wangyu
c5f7c74717 improve makefile 2017-08-13 10:35:14 +08:00
wangyu
70e3de7f41 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-08-13 10:19:22 +08:00
wangyu
f8fde9b630 fixed uninitialized variable 2017-08-13 10:19:17 +08:00
wangyu-
f79ca90513 Update README.md 2017-08-12 18:59:07 -07:00
wangyu-
03bcf99340 Update README.md 2017-08-12 18:24:41 -07:00
wangyu-
143a25236d Update README.md 2017-08-11 18:22:26 -07:00
wangyu-
1a4933f38e Update README.md 2017-08-11 18:09:48 -07:00
wangyu-
b65df8bc7f Update README.md 2017-08-11 04:42:55 -07:00
wangyu-
c7ff4f7bdd Update README.md 2017-08-10 07:16:26 -07:00
wangyu
11ddf3f586 Merge branch 'master' of https://github.com/wangyu-/UDPspeeder 2017-08-10 22:13:58 +08:00
wangyu
42ea567303 update makefile 2017-08-10 22:11:23 +08:00
wangyu-
a850b4471f Update README.md 2017-08-10 00:19:45 -07:00
wangyu-
797c90952f Update README.md 2017-08-10 00:18:54 -07:00
wangyu-
d441326f8d Update README.md 2017-08-10 00:18:37 -07:00
wangyu-
42b8853b35 Update README.md 2017-08-09 23:30:42 -07:00
wangyu-
72585b1cf3 Update README.md 2017-08-09 23:16:36 -07:00
wangyu-
dacda01ce1 Update README.md 2017-08-09 22:57:54 -07:00
wangyu-
0d6b29188f Update README.md 2017-08-09 21:13:19 -07:00
wangyu-
f04f5a724a Update README.md 2017-08-09 21:12:59 -07:00
wangyu-
e477d66731 Update README.md 2017-08-09 20:55:34 -07:00
wangyu-
d6a541dc0d Update README.md 2017-08-09 20:51:21 -07:00
wangyu-
898df9d11a Add files via upload 2017-08-10 01:55:08 +08:00
wangyu-
da16288d89 Delete Capture8.PNG 2017-08-09 10:54:56 -07:00
wangyu-
222f66b8de Update README.md 2017-08-09 10:53:44 -07:00
wangyu-
d363ac6ce6 Add files via upload 2017-08-10 01:52:39 +08:00
wangyu-
297758f856 Update README.md 2017-08-09 10:47:06 -07:00
wangyu-
71c2eea7d3 Update README.md 2017-08-09 10:45:54 -07:00
wangyu-
0c0692b867 Update README.md 2017-08-09 10:31:41 -07:00
wangyu-
7b400b0a7b Update README.md 2017-08-09 10:29:04 -07:00
wangyu-
961bb411ca Update README.md 2017-08-09 05:59:05 -07:00
wangyu-
fbcd88fbe8 Update README.md 2017-08-09 05:52:33 -07:00
wangyu-
52a1b3ba15 Update README.md 2017-08-09 05:39:53 -07:00
wangyu-
fe17d82a40 Add files via upload 2017-08-09 20:39:39 +08:00
wangyu-
d5cf49ee66 Delete Capture7.PNG 2017-08-09 05:39:16 -07:00
wangyu-
847a9a3663 Add files via upload 2017-08-09 20:39:00 +08:00
wangyu-
672efc5831 Update README.md 2017-08-09 05:26:39 -07:00
wangyu-
295ba4f727 Update README.md 2017-08-09 05:21:36 -07:00
wangyu-
675121c768 Update README.md 2017-08-09 20:16:25 +08:00
15 changed files with 276 additions and 35 deletions

155
README.md
View File

@@ -1,2 +1,155 @@
# UDPspeeder # UDPspeeder
UDP加速器降低UDP传输的丢包率。尤其适用于游戏和语音。 ![image0](images/Capture7.PNG)
UDP双边加速工具降低丢包率配合vpn可以加速任何协议尤其适用于加速游戏和网页打开速度同时也是一个UDP连接的调试和统计工具。
这个是我自己稳定用了一个月的项目用来加速美服的Brawl Stars和亚服的Mobile Legend效果不错。加速前卡得几乎没法玩加速后就没怎么卡过了。
#### 效果
![image0](images/Capture8.PNG)
#### 原理简介
目前原理是多倍发包。以后会做各种优化比如对高频率的短包先合并再冗余FECForward Error Correction在包速低的时候多倍发包包速高时用FEC。
跟net-speeder比优势在于client和server会把收到的多余包自动去掉这个过程对上层透明没有兼容性问题。而且发出的冗余数据包会做长度和内容的随机化抓包是看不出发了冗余数据的所以不用担心vps被封的问题。
每个冗余数据包都是间隔数毫秒可配置以后延迟发出的可以避开中间路由器因为瞬时buffer长度过长而连续丢掉所有副本。
模拟一定的延迟抖动,这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。
#### 适用场景
绝大部分流量不高的情况。程序本身加速udp但是配合openvpn可以加速任何流量。网络状况不好时游戏卡得没法玩或者网页卡得没法打开使用起来效果最好。对于解决语音通话的断断续续效果也不错。不适合大流量的场景比如BT下载和在线看视频。 无论从自己使用效果的角度,还是从国际出口带宽占用的角度,都建议不要在大流量环境使用。
#### 其他功能
输出UDP收发情况报告可以看出丢包率。
模拟丢包模拟延迟模拟jitter。便于通过实验找出应用卡顿的原因。
重复包过滤功能可以关掉,模拟网络本身有重复包的情况。用来测试应用对重复报的支持情况。
client支持多个udp连接server也支持多个client
目前有amd64,x86,ar71xx,树莓派armv7和android的binary
如果你需要绕过UDP屏蔽/QoS或者需要连接复用/连接保持功能或者是加密。解决方案在另一个repo(可以跟UDPspeeder一起使用)
https://github.com/wangyu-/udp2raw-tunnel
# 简明操作说明
### 环境要求
Linux主机可以是桌面版可以是android手机/平板可以是openwrt路由器也可以是树莓派。在windows和mac上配合虚拟机可以稳定使用speeder跑在Linux里其他应用照常跑在window里桥接模式测试可用
android版需要通过terminal运行。
### 安装
下载编译好的二进制文件,解压到本地和服务器的任意目录。
https://github.com/wangyu-/UDPspeeder/releases
### 运行
假设你有一个serverip为44.55.66.77有一个服务监听在udp 7777端口。 假设你需要加速本地到44.55.66.77:7777的流量。
```
在client端运行:
./speeder_ar71xx -l0.0.0.0:3333 -r 44.55.66.77:8855 -c -d2 -k "passwd"
在server端运行:
./speeder_amd64 -l0.0.0.0:8855 -r127.0.0.1:7777 -s -d2 -k "passwd"
```
现在client和server之间建立起了tunnel。想要连接44.55.66.77:7777只需要连接 127.0.0.1:3333。来回的所有的udp流量会被加速。
###### 注:
-d2 表示除了本来的包以外额外再发2个冗余包。可调。
-k 指定一个字符串server/client间所有收发的包都会被异或改变协议特征防止UDPspeeder的协议被运营商针对。
### MTU设置(重要)
不论你用udpspeeder来加速kcptun还是vpn,为了稳定使用,都需要设置合理的MTU在kcptun/vpn里设置而不是在udpspeeder里建议把MTU设置成1200。client和server端都要设置。
# 进阶操作说明
### 命令选项
```
UDPspeeder
git version:b4bd385e88 build date:Sep 11 2017 10:29:25
repository: https://github.com/wangyu-/UDPspeeder
usage:
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]
common option,must be same on both sides:
-k,--key <string> key for simple xor encryption,default:"secret key"
main options:
-d <number> duplicated packet number, -d 0 means no duplicate. default value:0
-t <number> duplicated packet delay time, unit: 0.1ms,default value:20(2ms)
-j <number> simulated jitter.randomly delay first packet for 0~jitter_value*0.1 ms,to
create simulated jitter.default value:0.do not use if you dont
know what it means
--report <number> turn on udp send/recv report,and set a time interval for reporting,unit:s
advanced options:
-t tmin:tmax simliar to -t above,but delay randomly between tmin and tmax
-j jmin:jmax simliar to -j above,but create jitter randomly between jmin and jmax
--random-drop <number> simulate packet loss ,unit:0.01%
--disable-filter disable duplicate packet filter.
-m <number> max pending packets,to prevent the program from eating up all your memory,
default value:0(disabled).
other options:
--log-level <number> 0:never 1:fatal 2:error 3:warn
4:info (default) 5:debug 6:trace
--log-position enable file name,function name,line number in log
--disable-color disable log color
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
-h,--help print this help message
```
### 包发送选项,两端设置可以不同。 只影响本地包发送。
##### -d 选项
设置冗余包数量。
##### -t 选项
为冗余包的发送,增加一个延迟.对中间路由buffer做优化应对瞬时Buffer过长导致的连续丢包.对于多个冗余包,依次在前一个包的基础上增加这个延迟。
##### -j 选项
为原始数据的发送增加一个延迟抖动值。这样上层应用计算出来的RTT方差会更大以等待后续冗余包的到达不至于发生在冗余包到达之前就触发重传的尴尬。配合-t选项使用。正常情况下跨国网络本身的延迟抖动就很大。可以不用设-j
##### --report  选项
数据发送和接受报告。开启后可以根据此数据推测出包速和丢包率等特征。
##### 加强版 -t 选项
跟普通-t类似允许设置最大值最小值用随机延迟发送冗余包。
##### 加强版 -j 选项
允许给jitter选项设置最大值最小值。在这个区间随机化jitter。如果最大值最小值一样就是模拟延迟。可以模拟高延迟、高jitter的网络环境。
##### --random-drop 选项
随机丢包。模拟恶劣的网络环境时使用。
### 包接收选项,两端设置可以不同。只影响本地包接受
##### --disable-filter    
关闭重复包过滤器。这样配合-d 选项可以模拟有重复包的网络环境。
# 应用
#### UDPspeeder + openvpn加速任何流量
如果你只是需要玩游戏效果预期会kcp/finalspeed方案更好。可以优化tcp游戏的延迟通过冗余发包避免了上层的重传。比如魔兽世界用的是tcp连接。
![image0](images/Capture2.PNG)
跟openvpn via kcptun方式的对比
kcptun在udp层有RS code也是一种冗余传输通过openvpn把流量转成tcp再通过kcptun加速是有一定效果的。但是tcp只支持按序到达。按序到达的意思是,如果你发了1 2 3 4 5 6 ,6个包如果第一个包丢了那么必须等第一个包重传成功以后 2 3 4 5 6 才能到达只要有一个包不到后续数据包就要一直等待。用tcp承载udp流量会破坏udp的实时性。会造成游戏卡顿更严重。
udp协议本身是ip协议加上了端口之后的直接封装udp继承了ip协议的实时/乱序到达特性更适合中转vpn。
#### UDPspeeder + kcptun/finalspeed + ss 同时加速tcp和udp流量
如果你需要用加速的tcp看视频和下载文件这样效果比vpn方案更好。不论是速度还是流量的耗费上。
![image0](images/Capture3.PNG)
#### UDPspeeder + openvpn + ss 混合方案
也是我正在用的方案。优点是可以随时在vpn和ss方案间快速切换。
实际部署起来比图中看起来的还要简单。不需要改路由表需要做的只是用openvpn的ip访问ss server。
![image0](images/Capture10.PNG)
(也可以把图中的ss server换成其他的socks5 server这样连ss client也不需要了)
# 编译教程
暂时先参考udp2raw的这篇教程几乎一样的过程。
https://github.com/wangyu-/udp2raw-tunnel/blob/master/doc/build_guide.zh-cn.md

View File

@@ -67,7 +67,7 @@ const u32_t conv_clear_interval=200;
const u32_t timer_interval=400; const u32_t timer_interval=400;
const int conv_clear_ratio=40; const int conv_clear_ratio=40;
const int conv_clear_min=5; const int conv_clear_min=5;
const u32_t conv_timeout=20000; const u32_t conv_timeout=180000;
const int max_conv_num=10000; const int max_conv_num=10000;
/* /*

1
images/11 Normal file
View File

@@ -0,0 +1 @@
11

BIN
images/Capture.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
images/Capture10.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
images/Capture2.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
images/Capture3.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
images/Capture4.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
images/Capture5.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
images/Capture6.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
images/Capture7.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
images/Capture8.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

BIN
images/Capture9.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include "log.h" #include "log.h"
#include "git_version.h"
using namespace std; using namespace std;
@@ -28,7 +29,7 @@ int local_fd=-1;
int is_client = 0, is_server = 0; int is_client = 0, is_server = 0;
int local_listen_fd=-1; int local_listen_fd=-1;
int disable_conv_clear=0; int disable_conn_clear=0;
int mtu_warn=1350; int mtu_warn=1350;
u32_t remote_address_uint32=0; u32_t remote_address_uint32=0;
@@ -48,6 +49,7 @@ u64_t packet_send_count=0;
u64_t dup_packet_send_count=0; u64_t dup_packet_send_count=0;
u64_t packet_recv_count=0; u64_t packet_recv_count=0;
u64_t dup_packet_recv_count=0; u64_t dup_packet_recv_count=0;
int max_pending_packet=0;
int random_between(u32_t a,u32_t b) int random_between(u32_t a,u32_t b)
{ {
@@ -60,7 +62,7 @@ int random_between(u32_t a,u32_t b)
else return a+get_true_random_number()%(b+1-a); else return a+get_true_random_number()%(b+1-a);
} }
int max_pending_packet=0;
int VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV; int VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV;
struct anti_replay_t struct anti_replay_t
@@ -160,7 +162,7 @@ struct conn_manager_t //TODO change map to unordered map
} }
void clear() void clear()
{ {
if(disable_conv_clear) return ; if(disable_conn_clear) return ;
for(it=fd_to_u64.begin();it!=fd_to_u64.end();it++) for(it=fd_to_u64.begin();it!=fd_to_u64.end();it++)
{ {
@@ -196,14 +198,20 @@ struct conn_manager_t //TODO change map to unordered map
} }
int insert_fd(u32_t fd,u64_t u64) int insert_fd(u32_t fd,u64_t u64)
{ {
int before=fd_last_active_time.bucket_count();
u64_to_fd[u64]=fd; u64_to_fd[u64]=fd;
fd_to_u64[fd]=u64; fd_to_u64[fd]=u64;
fd_last_active_time[fd]=get_current_time(); fd_last_active_time[fd]=get_current_time();
int after=fd_last_active_time.bucket_count();
if(after!=before)//rehash happens!
{
clear_it=fd_last_active_time.begin();
}
return 0; return 0;
} }
int erase_fd(u32_t fd) int erase_fd(u32_t fd)
{ {
if(disable_conv_clear) return 0; if(disable_conn_clear) return 0;
u64_t u64=fd_to_u64[fd]; u64_t u64=fd_to_u64[fd];
u32_t ip= (u64 >> 32u); u32_t ip= (u64 >> 32u);
@@ -239,7 +247,7 @@ struct conn_manager_t //TODO change map to unordered map
} }
int clear_inactive0() int clear_inactive0()
{ {
if(disable_conv_clear) return 0; if(disable_conn_clear) return 0;
//map<uint32_t,uint64_t>::iterator it; //map<uint32_t,uint64_t>::iterator it;
@@ -275,6 +283,7 @@ struct conn_manager_t //TODO change map to unordered map
} }
cnt++; cnt++;
} }
clear_it=it;
return 0; return 0;
} }
}conn_manager; }conn_manager;
@@ -420,7 +429,7 @@ int remove_seq(char * data,int &data_len)
seq=ntoh64(seq); seq=ntoh64(seq);
if(anti_replay.is_vaild(seq)==0) if(anti_replay.is_vaild(seq)==0)
{ {
if(disable_replay_filter==1) if(disable_replay_filter==1) // inefficient, to make packet_recv_count++ work for only non-dup packet
return 0; return 0;
mylog(log_trace,"seq %llx dropped bc of replay-filter\n ",seq); mylog(log_trace,"seq %llx dropped bc of replay-filter\n ",seq);
return -1; return -1;
@@ -591,7 +600,7 @@ int create_new_udp(int &new_udp_fd)
mylog(log_debug, "created new udp_fd %d\n", new_udp_fd); mylog(log_debug, "created new udp_fd %d\n", new_udp_fd);
int ret = connect(new_udp_fd, (struct sockaddr *) &remote_addr_in, slen); int ret = connect(new_udp_fd, (struct sockaddr *) &remote_addr_in, slen);
if (ret != 0) { if (ret != 0) {
mylog(log_warn, "udp fd connect fail\n"); mylog(log_warn, "udp fd connect fail %d %s\n",ret,strerror(errno));
close(new_udp_fd); close(new_udp_fd);
return -1; return -1;
} }
@@ -708,6 +717,8 @@ int event_loop()
char data[buf_len]; char data[buf_len];
int data_len; int data_len;
slen = sizeof(sockaddr_in);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0, if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
(struct sockaddr *) &local_other, &slen)) == -1) //<--first packet from a new ip:port turple (struct sockaddr *) &local_other, &slen)) == -1) //<--first packet from a new ip:port turple
{ {
@@ -769,7 +780,18 @@ int event_loop()
if (ret < 0) { if (ret < 0) {
mylog(log_warn, "send returned %d ,errno:%s\n", ret,strerror(errno)); mylog(log_warn, "send returned %d ,errno:%s\n", ret,strerror(errno));
} }
add_and_new(new_udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64); if(dup_delay_max!=0)
{
add_and_new(new_udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64);
}
else
{
for(int i=0;i<dup_num - 1;i++)
{
do_obscure(data, data_len, new_data, new_len);
ret = send_fd(new_udp_fd, new_data,new_len, 0);
}
}
} }
else else
{ {
@@ -885,7 +907,18 @@ int event_loop()
do_obscure(data, data_len, new_data, new_len); do_obscure(data, data_len, new_data, new_len);
ret = sendto_u64(local_listen_fd, new_data, ret = sendto_u64(local_listen_fd, new_data,
new_len , 0,u64); new_len , 0,u64);
if(dup_delay_max!=0)
{
add_and_new(udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64); add_and_new(udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64);
}
else
{
for(int i=0;i<dup_num-1;i++)
{
do_obscure(data, data_len, new_data, new_len);
ret = sendto_u64(local_listen_fd, new_data,new_len , 0,u64);
}
}
if (ret < 0) { if (ret < 0) {
mylog(log_warn, "sento returned %d,%s\n", ret,strerror(errno)); mylog(log_warn, "sento returned %d,%s\n", ret,strerror(errno));
//perror("ret<0"); //perror("ret<0");
@@ -921,8 +954,12 @@ int event_loop()
} }
void print_help() void print_help()
{ {
char git_version_buf[100]={0};
strncpy(git_version_buf,gitversion,10);
printf("UDPspeeder\n"); printf("UDPspeeder\n");
printf("version: %s %s\n",__DATE__,__TIME__); printf("git version:%s ",git_version_buf);
printf("build date:%s %s\n",__DATE__,__TIME__);
printf("repository: https://github.com/wangyu-/UDPspeeder\n"); printf("repository: https://github.com/wangyu-/UDPspeeder\n");
printf("\n"); printf("\n");
printf("usage:\n"); printf("usage:\n");
@@ -942,14 +979,16 @@ void print_help()
printf("advanced options:\n"); printf("advanced options:\n");
printf(" -t tmin:tmax simliar to -t above,but delay randomly between tmin and tmax\n"); printf(" -t tmin:tmax simliar to -t above,but delay randomly between tmin and tmax\n");
printf(" -j jmin:jmax simliar to -j above,but create jitter randomly between jmin and jmax\n"); printf(" -j jmin:jmax simliar to -j above,but create jitter randomly between jmin and jmax\n");
printf(" --random-drop <number> simulate packet loss ,unit 0.01%%\n"); printf(" --random-drop <number> simulate packet loss ,unit:0.01%%\n");
printf(" -m <number> max pending packets,to prevent the program from eating up all your memory.\n"); printf(" --disable-filter disable duplicate packet filter.\n");
printf(" -m <number> max pending packets,to prevent the program from eating up all your memory,\n");
printf(" default value:0(disabled).\n");
printf("other options:\n"); printf("other options:\n");
printf(" --log-level <number> 0:never 1:fatal 2:error 3:warn \n"); printf(" --log-level <number> 0:never 1:fatal 2:error 3:warn \n");
printf(" 4:info (default) 5:debug 6:trace\n"); printf(" 4:info (default) 5:debug 6:trace\n");
printf(" --log-position enable file name,function name,line number in log\n"); printf(" --log-position enable file name,function name,line number in log\n");
printf(" --disable-color disable log color\n"); printf(" --disable-color disable log color\n");
printf(" --sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:512\n"); printf(" --sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024\n");
//printf(" -p use multi-process mode instead of epoll.very costly,only for test,do dont use\n"); //printf(" -p use multi-process mode instead of epoll.very costly,only for test,do dont use\n");
printf(" -h,--help print this help message\n"); printf(" -h,--help print this help message\n");
@@ -1077,9 +1116,9 @@ void process_arg(int argc, char *argv[])
{ {
int dup_delay=-1; int dup_delay=-1;
sscanf(optarg,"%d\n",&dup_delay); sscanf(optarg,"%d\n",&dup_delay);
if(dup_delay<1||dup_delay>1000*100) if(dup_delay<0||dup_delay>1000*100)
{ {
mylog(log_fatal,"dup_delay must be between 1 and 100,000(10 second)\n"); mylog(log_fatal,"dup_delay must be between 0 and 100,000(10 second)\n");
myexit(-1); myexit(-1);
} }
dup_delay_min=dup_delay_max=dup_delay; dup_delay_min=dup_delay_max=dup_delay;
@@ -1087,9 +1126,9 @@ void process_arg(int argc, char *argv[])
else else
{ {
sscanf(optarg,"%d:%d\n",&dup_delay_min,&dup_delay_max); sscanf(optarg,"%d:%d\n",&dup_delay_min,&dup_delay_max);
if(dup_delay_min<1 ||dup_delay_max<1||dup_delay_min>dup_delay_max) if(dup_delay_min<0 ||dup_delay_max<0||dup_delay_min>dup_delay_max)
{ {
mylog(log_fatal," must satisfy 1<=dmin<=dmax\n"); mylog(log_fatal," must satisfy 0<=tmin<=tmax\n");
myexit(-1); myexit(-1);
} }
} }
@@ -1224,7 +1263,10 @@ void process_arg(int argc, char *argv[])
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
assert(sizeof(u64_t)==8);
assert(sizeof(i64_t)==8);
assert(sizeof(u32_t)==4);
assert(sizeof(i32_t)==4);
dup2(1, 2); //redirect stderr to stdout dup2(1, 2); //redirect stderr to stdout
int i, j, k; int i, j, k;
process_arg(argc,argv); process_arg(argc,argv);

77
makefile Normal file → Executable file
View File

@@ -1,18 +1,63 @@
cross_cc=mips-openwrt-linux-g++ cc_cross=/home/wangyu/Desktop/arm-2014.05/bin/arm-none-linux-gnueabi-g++
FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -ggdb cc_local=g++
FLAGS2= -O3 #cc_mips34kc=/toolchains/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
all: cc_mips24kc_be=/toolchains/lede-sdk-17.01.2-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-musl-g++
g++ main.cpp common.cpp log.cpp -I. -o speeder -static -lrt -std=c++11 ${FLAGS} ${FLAGS2} cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16/bin/mipsel-openwrt-linux-musl-g++
release: #cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
g++ main.cpp common.cpp log.cpp -I. -o speeder_amd64 -static -lrt -std=c++11 ${FLAGS} ${FLAGS2} cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
g++ -m32 main.cpp common.cpp log.cpp -I. -o speeder_x86 -static -lrt -std=c++11 ${FLAGS} ${FLAGS2} #cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
${cross_cc} main.cpp common.cpp log.cpp -I. -o speeder_ar71xx -lrt -std=c++11 ${FLAGS} ${FLAGS2} FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
tar -zcvf udp_speeder_binaries.tar.gz speeder_amd64 speeder_x86 speeder_ar71xx
cross:
${cross_cc} main.cpp common.cpp log.cpp -I. -o speeder_cross -lrt -std=c++11 ${FLAGS} ${FLAGS2}
debug: SOURCES=main.cpp log.cpp common.cpp
g++ main.cpp common.cpp log.cpp -I. -o speeder -static -lrt -std=c++11 ${FLAGS} -Wformat-nonliteral -D MY_DEBUG
#g++ forward.cpp aes.c -o forward -static NAME=speeder
# ${ccarm} forward.cpp aes.c -o forwardarm -static -lgcc_eh TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
TAR=${NAME}_binaries.tar.gz `echo ${TARGETS}|sed -r 's/([^ ]+)/speeder_\1/g'`
all:git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb -static -O3
fast: git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -ggdb
debug: git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG
debug2: git_version
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -ggdb
mips24kc_be: git_version
${cc_mips24kc_be} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
mips24kc_le: git_version
${cc_mips24kc_le} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
amd64:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
x86:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 -m32
arm:git_version
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
cross:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3
cross2:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -lgcc_eh -O3
cross3:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -O3
release: ${TARGETS}
tar -zcvf ${TAR}
clean:
rm -f ${TAR}
rm -f speeder speeder_cross
rm -f git_version.h
git_version:
echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > git_version.h