mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-09-18 05:04:32 +08:00
Compare commits
12 Commits
v2@2017102
...
v1
Author | SHA1 | Date | |
---|---|---|---|
|
b006b651c8 | ||
|
08f2b5d405 | ||
|
ee9dab37fa | ||
|
d25e1ea9df | ||
|
3b5279235a | ||
|
cccff0a8a5 | ||
|
66da392357 | ||
|
a5bad45780 | ||
|
b1a47bb8ea | ||
|
00cffe1072 | ||
|
b5a873d073 | ||
|
8a2e2b8ce4 |
@@ -62,6 +62,10 @@ https://github.com/wangyu-/UDPspeeder/releases
|
|||||||
|
|
||||||
-k 指定一个字符串,server/client间所有收发的包都会被异或,改变协议特征,防止UDPspeeder的协议被运营商针对。
|
-k 指定一个字符串,server/client间所有收发的包都会被异或,改变协议特征,防止UDPspeeder的协议被运营商针对。
|
||||||
|
|
||||||
|
### MTU设置(重要)
|
||||||
|
|
||||||
|
不论你用udpspeeder来加速kcptun还是vpn,为了稳定使用,都需要设置合理的MTU(在kcptun/vpn里设置,而不是在udpspeeder里),建议把MTU设置成1200。client和server端都要设置。
|
||||||
|
|
||||||
# 进阶操作说明
|
# 进阶操作说明
|
||||||
|
|
||||||
### 命令选项
|
### 命令选项
|
||||||
|
@@ -23,7 +23,7 @@ u64_t get_current_time()
|
|||||||
{
|
{
|
||||||
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()
|
||||||
|
2
common.h
2
common.h
@@ -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;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
58
main.cpp
58
main.cpp
@@ -29,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;
|
||||||
|
|
||||||
@@ -162,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++)
|
||||||
{
|
{
|
||||||
@@ -198,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);
|
||||||
@@ -241,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;
|
||||||
@@ -277,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;
|
||||||
@@ -422,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;
|
||||||
@@ -698,9 +705,18 @@ int event_loop()
|
|||||||
int nfds = epoll_wait(epollfd, events, max_events, 180 * 1000); //3mins
|
int nfds = epoll_wait(epollfd, events, max_events, 180 * 1000); //3mins
|
||||||
if (nfds < 0)
|
if (nfds < 0)
|
||||||
{
|
{
|
||||||
mylog(log_fatal,"epoll_wait return %d\n", nfds);
|
if(errno==EINTR )
|
||||||
|
{
|
||||||
|
mylog(log_info,"epoll interrupted by signal,continue\n");
|
||||||
|
//myexit(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mylog(log_fatal,"epoll_wait return %d,%s\n", nfds,strerror(errno));
|
||||||
myexit(-1);
|
myexit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
int n;
|
int n;
|
||||||
int clear_triggered=0;
|
int clear_triggered=0;
|
||||||
for (n = 0; n < nfds; ++n)
|
for (n = 0; n < nfds; ++n)
|
||||||
@@ -773,9 +789,20 @@ 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));
|
||||||
}
|
}
|
||||||
|
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);
|
add_and_new(new_udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64);
|
||||||
}
|
}
|
||||||
else
|
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
|
||||||
{
|
{
|
||||||
add_and_new(new_udp_fd, dup_num,random_between(jitter_min,jitter_max), data, data_len,u64);
|
add_and_new(new_udp_fd, dup_num,random_between(jitter_min,jitter_max), data, data_len,u64);
|
||||||
}
|
}
|
||||||
@@ -889,7 +916,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");
|
||||||
@@ -1087,9 +1125,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;
|
||||||
@@ -1097,9 +1135,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user