moved rehash() function back in classic.cpp,fec under developing

This commit is contained in:
wangyu- 2017-09-15 22:45:13 -05:00
parent f8efcaf48b
commit da48f6e003
7 changed files with 81 additions and 53 deletions

View File

@ -14,7 +14,6 @@
namespace classic
{
using namespace std;
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
@ -97,14 +96,13 @@ struct anti_replay_t
}
void prepare()
{
st.rehash(anti_replay_buff_size*10);
anti_replay_seq=get_true_random_number();//random first seq
const_id=get_true_random_number_nz();
}
anti_replay_t()
{
memset(replay_buffer,0,sizeof(replay_buffer));
st.rehash(anti_replay_buff_size*10);
max_packet_received=0;
index=0;
}
@ -1271,4 +1269,6 @@ int main(int argc, char *argv[])
return 0;
}
}
}//namespace end

View File

@ -15,8 +15,11 @@ int about_to_exit=0;
raw_mode_t raw_mode=mode_faketcp;
unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
int socket_buf_size=1024*1024;
int max_pending_packet=0;
static int random_number_fd=-1;
char iptables_rule[200]="";
int is_client = 0, is_server = 0;
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
u64_t get_current_time()

View File

@ -49,6 +49,7 @@
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<list>
using namespace std;
@ -59,6 +60,7 @@ typedef long long i64_t;
typedef unsigned int u32_t;
typedef int i32_t;
typedef u64_t my_time_t;
const int max_data_len=1600;
const int buf_len=max_data_len+200;
@ -114,6 +116,9 @@ enum program_mode_t {unset_mode=0,client_mode,server_mode};
extern program_mode_t program_mode;
extern unordered_map<int, const char*> raw_mode_tostring ;
extern int socket_buf_size;
extern int max_pending_packet;
extern int is_client, is_server;
typedef u32_t id_t;

View File

@ -5,6 +5,7 @@
#include "packet.h"
#include "conn_manager.h"
#include "classic.h"
using namespace std;
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64
@ -27,7 +28,7 @@ int random_number_fd=-1;
int remote_fd=-1;
int local_fd=-1;
int is_client = 0, is_server = 0;
int local_listen_fd=-1;
@ -41,13 +42,13 @@ int multi_process_mode=0;
int random_drop=0;
u64_t last_report_time=0;
int report_interval=0;
int max_pending_packet=0;
conn_manager_t conn_manager;
@ -57,7 +58,7 @@ int VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
typedef u64_t my_time_t;
struct delay_data
{
@ -69,50 +70,6 @@ struct delay_data
};
int delay_timer_fd;
int sendto_u64 (int fd,char * buf, int len,int flags, u64_t u64)
{
if(is_server)
{
dup_packet_send_count++;
}
if(is_server&&random_drop!=0)
{
if(get_true_random_number()%10000<(u32_t)random_drop)
{
return 0;
}
}
sockaddr_in tmp_sockaddr;
memset(&tmp_sockaddr,0,sizeof(tmp_sockaddr));
tmp_sockaddr.sin_family = AF_INET;
tmp_sockaddr.sin_addr.s_addr = (u64 >> 32u);
tmp_sockaddr.sin_port = htons(uint16_t((u64 << 32u) >> 32u));
return sendto(fd, buf,
len , 0,
(struct sockaddr *) &tmp_sockaddr,
sizeof(tmp_sockaddr));
}
int send_fd (int fd,char * buf, int len,int flags)
{
if(is_client)
{
dup_packet_send_count++;
}
if(is_client&&random_drop!=0)
{
if(get_true_random_number()%10000<(u32_t)random_drop)
{
return 0;
}
}
return send(fd,buf,len,flags);
}
multimap<my_time_t,delay_data> delay_mp;
@ -893,6 +850,16 @@ void process_arg(int argc, char *argv[])
int main(int argc, char *argv[])
{
if(argc==1||argc==0)
{
printf("this_program classic\n");
printf("this_program fec\n");
return 0;
}
if(argc==2&&strcmp(argv[1],"fec")!=0)
{
return classic::main(argc,argv);
}
assert(sizeof(u64_t)==8);
assert(sizeof(i64_t)==8);
assert(sizeof(u32_t)==4);

View File

@ -8,7 +8,7 @@ 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
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp conn_manager.cpp classic.cpp
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp conn_manager.cpp classic.cpp delay_manager.cpp
NAME=speeder
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le

View File

@ -19,6 +19,8 @@ typedef u64_t anti_replay_seq_t;
const u32_t anti_replay_buff_size=10000;
int disable_replay_filter=0;
int random_drop=0;
char key_string[1000]= "secret key";
struct anti_replay_t
@ -188,3 +190,50 @@ int de_obscure(const char * input, int in_len,char *output,int &out_len)
dup_packet_recv_count++;
return 0;
}
int sendto_u64 (int fd,char * buf, int len,int flags, u64_t u64)
{
if(is_server)
{
dup_packet_send_count++;
}
if(is_server&&random_drop!=0)
{
if(get_true_random_number()%10000<(u32_t)random_drop)
{
return 0;
}
}
sockaddr_in tmp_sockaddr;
memset(&tmp_sockaddr,0,sizeof(tmp_sockaddr));
tmp_sockaddr.sin_family = AF_INET;
tmp_sockaddr.sin_addr.s_addr = (u64 >> 32u);
tmp_sockaddr.sin_port = htons(uint16_t((u64 << 32u) >> 32u));
return sendto(fd, buf,
len , 0,
(struct sockaddr *) &tmp_sockaddr,
sizeof(tmp_sockaddr));
}
int send_fd (int fd,char * buf, int len,int flags)
{
if(is_client)
{
dup_packet_send_count++;
}
if(is_client&&random_drop!=0)
{
if(get_true_random_number()%10000<(u32_t)random_drop)
{
return 0;
}
}
return send(fd,buf,len,flags);
}

View File

@ -19,6 +19,7 @@ extern u64_t packet_recv_count;
extern u64_t dup_packet_recv_count;
extern char key_string[1000];
extern int disable_replay_filter;
extern int random_drop;
void encrypt_0(char * input,int &len,char *key);
void decrypt_0(char * input,int &len,char *key);
@ -27,4 +28,7 @@ int remove_seq(char * data,int &data_len);
int do_obscure(const char * input, int in_len,char *output,int &out_len);
int de_obscure(const char * input, int in_len,char *output,int &out_len);
int sendto_u64 (int fd,char * buf, int len,int flags, u64_t u64);
int send_fd (int fd,char * buf, int len,int flags);
#endif /* PACKET_H_ */