Skip to content

Commit

Permalink
prepare for sync UDPspeeder update
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Aug 20, 2018
1 parent 55757c6 commit e856b51
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion UDPspeeder
Submodule UDPspeeder updated 63 files
+1 −0 .gitattributes
+31 −21 README.md
+599 −197 common.cpp
+347 −41 common.h
+66 −206 connection.cpp
+254 −23 connection.h
+26 −14 delay_manager.cpp
+16 −4 delay_manager.h
+35 −90 doc/README.zh-cn.md
+1 −1 fd_manager.cpp
+142 −63 fec_manager.cpp
+272 −40 fec_manager.h
+ images/cn/merlin1.jpg
+ images/cn/merlin2.jpg
+ images/cn/merlin3.jpg
+ images/cn/udp2rawudpspeeder.PNG
+4 −4 lib/fec.cpp
+0 −0 lib/rs.cpp
+31 −0 libev/CVS/Entries
+1 −0 libev/CVS/Repository
+1 −0 libev/CVS/Root
+517 −0 libev/Changes
+37 −0 libev/LICENSE
+20 −0 libev/Makefile.am
+58 −0 libev/README
+3 −0 libev/README.embed
+73 −0 libev/Symbols.ev
+24 −0 libev/Symbols.event
+3 −0 libev/autogen.sh
+27 −0 libev/configure.ac
+816 −0 libev/ev++.h
+5,647 −0 libev/ev.3
+5,143 −0 libev/ev.c
+854 −0 libev/ev.h
+5,570 −0 libev/ev.pod
+285 −0 libev/ev_epoll.c
+218 −0 libev/ev_kqueue.c
+151 −0 libev/ev_poll.c
+189 −0 libev/ev_port.c
+316 −0 libev/ev_select.c
+204 −0 libev/ev_vars.h
+162 −0 libev/ev_win32.c
+200 −0 libev/ev_wrap.h
+425 −0 libev/event.c
+177 −0 libev/event.h
+226 −0 libev/event_compat.h
+131 −0 libev/import_libevent
+42 −0 libev/libev.m4
+8 −0 libev/update_ev_c
+19 −0 libev/update_ev_wrap
+7 −0 libev/update_symbols
+1 −41 log.h
+48 −7 main.cpp
+20 −3 makefile
+150 −56 misc.cpp
+5 −3 misc.h
+16 −0 my_ev.cpp
+5 −0 my_ev.h
+13 −0 my_ev_common.h
+16 −7 packet.cpp
+0 −705 tunnel.cpp
+439 −0 tunnel_client.cpp
+491 −0 tunnel_server.cpp
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void print_help()


printf("advanced options:\n");
printf(" --mtu <number> mtu. for mode 0, the program will split packet to segment smaller than mtu_value.\n");
printf(" --mtu <number> mtu for fec. for mode 0, the program will split packet to segment smaller than mtu.\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");
Expand All @@ -53,8 +53,8 @@ static void print_help()
printf(" --disable-xor <number> disable xor encryption to save a bit cpu\n");

printf("developer options:\n");
printf(" --tun-mtu <number > mtu of the tun interface,most time you shouldnt change this\n");
printf(" --disable-mssfix <number > disable mssfix for tcp connection\n");
printf(" --tun-mtu <number> mtu of the tun interface,most time you shouldnt change this\n");
printf(" --mssfix <number> do mssfix for tcp connection, use 0 to disable. default value: 1250\n");
printf(" -i,--interval imin:imax similiar to -i above, but scatter randomly between imin and imax\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");
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cc_cross=/home/wangyu/Desktop/arm-2014.05/bin/arm-none-linux-gnueabi-g++
cc_cross=/toolchains/tmp/OpenWrt-SDK-15.05.1-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++ -s
cc_local=g++
#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++
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++
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++
#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
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++
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb -I. -IUDPspeeder ${OPT}
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb -I. -IUDPspeeder -isystem UDPspeeder/libev ${OPT}

SOURCES=`ls UDPspeeder/*.cpp UDPspeeder/lib/*.c|grep -v main.cpp|grep -v tunnel.cpp` main.cpp tun_dev.cpp
SOURCES=`ls UDPspeeder/*.cpp UDPspeeder/lib/*.cpp|grep -v main.cpp|grep -v tunnel.cpp` main.cpp tun_dev.cpp

#INCLUDE= -I. -IUDPspeeder

Expand Down
66 changes: 36 additions & 30 deletions tun_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
#include <netinet/ip.h> //Provides declarations for ip header
#include <netinet/if_ether.h>

#include <linux/if.h>
#include <linux/if_tun.h>


my_time_t last_keep_alive_time=0;

int keep_alive_interval=1000;//1000ms
int keep_alive_interval=3000;//3000ms

int get_tun_fd(char * dev_name)
{
Expand Down Expand Up @@ -130,7 +133,7 @@ int from_fec_to_normal2(conn_info_t & conn_info,dest_t &dest,char * data,int len
{

#ifndef NOLIMIT
if(client_or_server==server_mode)
if(program_mode==server_mode)
{
char * tmp_data=out_arr[i];
int tmp_len=out_len[i];
Expand All @@ -144,7 +147,7 @@ int from_fec_to_normal2(conn_info_t & conn_info,dest_t &dest,char * data,int len
{
string sub=my_ntoa(dest_ip);
string dst=my_ntoa( htonl( ntohl (sub_net_uint32) &0xFFFFFF00) );
mylog(log_warn,"[restriction]packet's dest ip [%s] not in subnet [%s],dropped\n", sub.c_str(), dst.c_str());
mylog(log_warn,"[restriction]packet's dest ip [%s] not in subnet [%s],dropped, maybe you need to compile an un-restricted server\n", sub.c_str(), dst.c_str());
continue;
}
}
Expand Down Expand Up @@ -279,9 +282,9 @@ int do_mssfix(char * s,int len)
}
int mss= read_u16(ptr+2);//uint8_t(ptr[2])*256+uint8_t(ptr[3]);
int new_mss=mss;
if(new_mss>g_fec_mtu-40-10) //minus extra 10 for safe
if(new_mss>::mssfix-40-10) //minus extra 10 for safe
{
new_mss=g_fec_mtu-40-10;
new_mss=::mssfix-40-10;
}
write_u16(ptr+2,(unsigned short)new_mss);

Expand Down Expand Up @@ -356,7 +359,7 @@ int tun_dev_client_event_loop()
tun_fd=get_tun_fd(tun_dev);
assert(tun_fd>0);

assert(new_connected_socket(remote_fd,remote_ip_uint32,remote_port)==0);
assert(new_connected_socket2(remote_fd,remote_addr)==0);
remote_fd64=fd_manager.create(remote_fd);

assert(set_if(tun_dev,htonl((ntohl(sub_net_uint32)&0xFFFFFF00)|2),htonl((ntohl(sub_net_uint32)&0xFFFFFF00 )|1),tun_mtu)==0);
Expand Down Expand Up @@ -641,7 +644,7 @@ int tun_dev_server_event_loop()
tun_fd=get_tun_fd(tun_dev);
assert(tun_fd>0);

assert(new_listen_socket(local_listen_fd,local_ip_uint32,local_port)==0);
assert(new_listen_socket2(local_listen_fd,local_addr)==0);
assert(set_if(tun_dev,htonl((ntohl(sub_net_uint32)&0xFFFFFF00)|1),htonl((ntohl(sub_net_uint32)&0xFFFFFF00 )|2),tun_mtu)==0);

epoll_fd = epoll_create1(0);
Expand Down Expand Up @@ -719,11 +722,10 @@ int tun_dev_server_event_loop()

dest_t udp_dest;
udp_dest.cook=1;
udp_dest.type=type_fd_ip_port;
udp_dest.type=type_fd_addr;

udp_dest.inner.fd_ip_port.fd=local_listen_fd;
udp_dest.inner.fd_ip_port.ip_port.ip=0;
udp_dest.inner.fd_ip_port.ip_port.port=0;
udp_dest.inner.fd_addr.fd=local_listen_fd;
udp_dest.inner.fd_addr.addr.clear();

dest_t tun_dest;
tun_dest.type=type_write_fd;
Expand Down Expand Up @@ -755,16 +757,16 @@ int tun_dev_server_event_loop()
uint64_t value;
read(conn_info.timer.get_timer_fd(), &value, 8);

if(udp_dest.inner.fd64_ip_port.ip_port.to_u64()==0)
if(udp_dest.inner.fd_addr.addr.is_vaild()==0)
{
continue;
}
conn_info.stat.report_as_server(udp_dest.inner.fd_ip_port.ip_port);
conn_info.stat.report_as_server(udp_dest.inner.fd_addr.addr);
do_keep_alive(udp_dest);
}
else if(events[idx].data.u64==conn_info.fec_encode_manager.get_timer_fd64())
{
assert(udp_dest.inner.fd64_ip_port.ip_port.to_u64()!=0);
assert(udp_dest.inner.fd_addr.addr.is_vaild()!=0);
mylog(log_trace,"events[idx].data.u64 == conn_info.fec_encode_manager.get_timer_fd64()\n");
uint64_t fd64=events[idx].data.u64;
//mylog(log_info,"timer!!!\n");
Expand All @@ -790,15 +792,21 @@ int tun_dev_server_event_loop()
}
else 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);
//struct sockaddr_in udp_new_addr_in={0};
//socklen_t udp_new_addr_len = sizeof(sockaddr_in);
address_t::storage_t udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(address_t::storage_t);

if ((len = recvfrom(local_listen_fd, data, max_data_len+1, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) < 0) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
continue;
//myexit(1);
};

address_t new_addr;
new_addr.from_sockaddr((struct sockaddr *) &udp_new_addr_in,udp_new_addr_len);

if(len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
Expand All @@ -819,7 +827,7 @@ int tun_dev_server_event_loop()
continue;
}

if((udp_dest.inner.fd_ip_port.ip_port.ip==udp_new_addr_in.sin_addr.s_addr) && (udp_dest.inner.fd_ip_port.ip_port.port==ntohs(udp_new_addr_in.sin_port)))
if(udp_dest.inner.fd_addr.addr==new_addr)
{
if(header==header_keep_alive)
{
Expand All @@ -843,18 +851,18 @@ int tun_dev_server_event_loop()

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));
udp_dest.inner.fd_ip_port.ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
udp_dest.inner.fd_ip_port.ip_port.port=ntohs(udp_new_addr_in.sin_port);
mylog(log_info,"new connection from %s\n", new_addr.get_str());
udp_dest.inner.fd_addr.addr=new_addr;
//udp_dest.inner.fd_ip_port.ip_port.ip=udp_new_addr_in.sin_addr.s_addr;
//udp_dest.inner.fd_ip_port.ip_port.port=ntohs(udp_new_addr_in.sin_port);
conn_info.fec_decode_manager.clear();
conn_info.fec_encode_manager.clear();
conn_info.fec_encode_manager.clear_data();
memset(&conn_info.stat,0,sizeof(conn_info.stat));

}
else if(header==header_normal)
{
mylog(log_debug,"rejected connection from %s:%d\n", inet_ntoa(udp_new_addr_in.sin_addr),ntohs(udp_new_addr_in.sin_port));
mylog(log_debug,"rejected connection from %s\n", new_addr.get_str());


len=1;
Expand All @@ -863,11 +871,10 @@ int tun_dev_server_event_loop()


dest_t tmp_dest;
tmp_dest.type=type_fd_ip_port;
tmp_dest.type=type_fd_addr;

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);
tmp_dest.inner.fd_addr.fd=local_listen_fd;
tmp_dest.inner.fd_addr.addr=new_addr;

delay_manager.add(0,tmp_dest,data,len);;
continue;
Expand All @@ -878,8 +885,7 @@ int tun_dev_server_event_loop()
}
}

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);
mylog(log_trace,"Received packet from %s,len: %d\n", new_addr.get_str(),len);

from_fec_to_normal2(conn_info,tun_dest,data,len);

Expand All @@ -904,7 +910,7 @@ int tun_dev_server_event_loop()

mylog(log_trace,"Received packet from tun,len: %d\n",len);

if(udp_dest.inner.fd64_ip_port.ip_port.to_u64()==0)
if(udp_dest.inner.fd_addr.addr.is_vaild()==0)
{
mylog(log_debug,"received packet from tun,but there is no client yet,dropped packet\n");
continue;
Expand Down

0 comments on commit e856b51

Please sign in to comment.