mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-18 22:09:35 +08:00
before add debug code
This commit is contained in:
parent
7b939a4a64
commit
3d7391b2fa
@ -43,7 +43,7 @@ int blob_encode_t::input(char *s,int len)
|
||||
assert(current_len+len+sizeof(u16_t) <=max_fec_packet_num*buf_len);
|
||||
assert(len<=65535&&len>=0);
|
||||
counter++;
|
||||
assert(counter<=max_normal_packet_num);
|
||||
assert(counter<=max_fec_pending_packet_num);
|
||||
write_u16(buf+current_len,len);
|
||||
current_len+=sizeof(u16_t);
|
||||
memcpy(buf+current_len,s,len);
|
||||
@ -95,7 +95,7 @@ int blob_decode_t::output(int &n,char ** &s_arr,int *&len_arr)
|
||||
if(parser_pos+(int)sizeof(u32_t)>current_len) return -1;
|
||||
|
||||
n=(int)read_u32(buf+parser_pos);
|
||||
if(n>max_normal_packet_num) {mylog(log_info,"failed 1\n");return -1;}
|
||||
if(n>max_fec_pending_packet_num) {mylog(log_info,"failed 1\n");return -1;}
|
||||
s_arr=s_buf;
|
||||
len_arr=len_buf;
|
||||
|
||||
@ -172,11 +172,11 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/)
|
||||
{
|
||||
mylog(log_trace,"counter=%d\n",counter);
|
||||
assert(len<=65535&&len>=0);
|
||||
char * p=buf[counter]+sizeof(u32_t)+4*sizeof(char);
|
||||
char * p=input_buf[counter]+sizeof(u32_t)+4*sizeof(char);
|
||||
write_u16(p,(u16_t)((u32_t)len));
|
||||
p+=sizeof(u16_t);
|
||||
memcpy(p,s,len);//remember to change this,if protocol is modified
|
||||
buf_s_len[counter]=len+sizeof(u16_t);
|
||||
input_len[counter]=len+sizeof(u16_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -247,8 +247,8 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
||||
|
||||
for(int i=0;i<counter;i++)
|
||||
{
|
||||
assert(buf_s_len[i]>=0);
|
||||
if(buf_s_len[i]>fec_len) fec_len=buf_s_len[i];
|
||||
assert(input_len[i]>=0);
|
||||
if(input_len[i]>fec_len) fec_len=input_len[i];
|
||||
}
|
||||
|
||||
}
|
||||
@ -259,43 +259,43 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
||||
{
|
||||
int tmp_idx=0;
|
||||
|
||||
write_u32(buf[i] + tmp_idx, seq);
|
||||
write_u32(input_buf[i] + tmp_idx, seq);
|
||||
tmp_idx += sizeof(u32_t);
|
||||
buf[i][tmp_idx++] = (unsigned char) type;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) type;
|
||||
if (type == 1 && i < actual_data_num)
|
||||
{
|
||||
buf[i][tmp_idx++] = (unsigned char) 0;
|
||||
buf[i][tmp_idx++] = (unsigned char) 0;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) 0;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) 0;
|
||||
} else
|
||||
{
|
||||
buf[i][tmp_idx++] = (unsigned char) actual_data_num;
|
||||
buf[i][tmp_idx++] = (unsigned char) actual_redundant_num;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) actual_data_num;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) actual_redundant_num;
|
||||
}
|
||||
buf[i][tmp_idx++] = (unsigned char) i;
|
||||
input_buf[i][tmp_idx++] = (unsigned char) i;
|
||||
|
||||
|
||||
tmp_output_buf[i]=buf[i]+tmp_idx; //////caution ,trick here.
|
||||
tmp_output_buf[i]=input_buf[i]+tmp_idx; //////caution ,trick here.
|
||||
|
||||
if(type==0)
|
||||
{
|
||||
output_len[i]=tmp_idx+fec_len;
|
||||
if(i<actual_data_num)
|
||||
{
|
||||
memcpy(buf[i]+tmp_idx,blob_output[i],fec_len);
|
||||
memcpy(input_buf[i]+tmp_idx,blob_output[i],fec_len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(i<actual_data_num)
|
||||
{
|
||||
output_len[i]=tmp_idx+buf_s_len[i];
|
||||
memset(tmp_output_buf[i]+buf_s_len[i],0,fec_len-buf_s_len[i]);
|
||||
output_len[i]=tmp_idx+input_len[i];
|
||||
memset(tmp_output_buf[i]+input_len[i],0,fec_len-input_len[i]);
|
||||
}
|
||||
else
|
||||
output_len[i]=tmp_idx+fec_len;
|
||||
|
||||
}
|
||||
output_buf[i]=buf[i];
|
||||
output_buf[i]=input_buf[i];
|
||||
|
||||
}
|
||||
//output_len=blob_len+sizeof(u32_t)+4*sizeof(char);/////remember to change this 4,if modified the protocol
|
||||
@ -347,16 +347,16 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
|
||||
output_n=1;
|
||||
|
||||
int tmp_idx=0;
|
||||
write_u32(buf[buf_idx]+tmp_idx,seq);
|
||||
write_u32(input_buf[buf_idx]+tmp_idx,seq);
|
||||
tmp_idx+=sizeof(u32_t);
|
||||
|
||||
buf[buf_idx][tmp_idx++]=(unsigned char)type;
|
||||
buf[buf_idx][tmp_idx++]=(unsigned char)0;
|
||||
buf[buf_idx][tmp_idx++]=(unsigned char)0;
|
||||
buf[buf_idx][tmp_idx++]=(unsigned char)((u32_t)buf_idx);
|
||||
input_buf[buf_idx][tmp_idx++]=(unsigned char)type;
|
||||
input_buf[buf_idx][tmp_idx++]=(unsigned char)0;
|
||||
input_buf[buf_idx][tmp_idx++]=(unsigned char)0;
|
||||
input_buf[buf_idx][tmp_idx++]=(unsigned char)((u32_t)buf_idx);
|
||||
|
||||
output_len[0]=buf_s_len[buf_idx]+tmp_idx;
|
||||
output_buf[0]=buf[buf_idx];
|
||||
output_len[0]=input_len[buf_idx]+tmp_idx;
|
||||
output_buf[0]=input_buf[buf_idx];
|
||||
}
|
||||
}
|
||||
|
||||
@ -394,7 +394,7 @@ fec_decode_manager_t::fec_decode_manager_t()
|
||||
|
||||
int fec_decode_manager_t::re_init()
|
||||
{
|
||||
for(int i=0;i<(int)fec_buff_size;i++)
|
||||
for(int i=0;i<(int)fec_buff_num;i++)
|
||||
fec_data[i].used=0;
|
||||
ready_for_output=0;
|
||||
return 0;
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include "log.h"
|
||||
#include "lib/rs.h"
|
||||
|
||||
const int max_normal_packet_num=1000;
|
||||
const int max_fec_pending_packet_num=1000;
|
||||
const int max_fec_packet_num=255;
|
||||
const u32_t anti_replay_buff_size=30000;
|
||||
const u32_t fec_buff_size=3000;
|
||||
const u32_t anti_replay_buff_size=10000;
|
||||
const u32_t fec_buff_num=1000;
|
||||
|
||||
|
||||
struct anti_replay_t
|
||||
@ -27,7 +27,7 @@ struct anti_replay_t
|
||||
anti_replay_t()
|
||||
{
|
||||
memset(replay_buffer,-1,sizeof(replay_buffer));
|
||||
st.rehash(anti_replay_buff_size*10);
|
||||
st.rehash(anti_replay_buff_size*3);
|
||||
index=0;
|
||||
}
|
||||
void set_invaild(u32_t seq)
|
||||
@ -62,7 +62,6 @@ struct blob_encode_t
|
||||
int current_len;
|
||||
int counter;
|
||||
|
||||
|
||||
char *output_arr[max_fec_packet_num+100];
|
||||
|
||||
blob_encode_t();
|
||||
@ -84,8 +83,8 @@ struct blob_decode_t
|
||||
int last_len;
|
||||
int counter;
|
||||
|
||||
char *s_buf[max_normal_packet_num+100];
|
||||
int len_buf[max_normal_packet_num+100];
|
||||
char *s_buf[max_fec_pending_packet_num+100];
|
||||
int len_buf[max_fec_pending_packet_num+100];
|
||||
|
||||
blob_decode_t();
|
||||
int clear();
|
||||
@ -95,26 +94,30 @@ struct blob_decode_t
|
||||
|
||||
class fec_encode_manager_t
|
||||
{
|
||||
private:
|
||||
u32_t seq;
|
||||
|
||||
int type;
|
||||
int fec_data_num,fec_redundant_num;
|
||||
int fec_mtu;
|
||||
int fec_pending_num;
|
||||
int fec_pending_time;
|
||||
char buf[max_fec_packet_num+5][buf_len];
|
||||
int buf_s_len[max_fec_packet_num+5];
|
||||
|
||||
char input_buf[max_fec_packet_num+5][buf_len];
|
||||
int input_len[max_fec_packet_num+5];
|
||||
char *output_buf[max_fec_packet_num+5];
|
||||
int output_len[max_fec_packet_num+5];
|
||||
int ready_for_output;
|
||||
u32_t seq;
|
||||
|
||||
int counter;
|
||||
int timer_fd;
|
||||
u64_t timer_fd64;
|
||||
|
||||
int ready_for_output;
|
||||
u32_t output_n;
|
||||
|
||||
int type;
|
||||
|
||||
blob_encode_t blob_encode;
|
||||
int append(char *s,int len);
|
||||
|
||||
public:
|
||||
fec_encode_manager_t();
|
||||
~fec_encode_manager_t();
|
||||
@ -147,7 +150,7 @@ struct fec_group_t
|
||||
class fec_decode_manager_t
|
||||
{
|
||||
anti_replay_t anti_replay;
|
||||
fec_data_t fec_data[fec_buff_size];
|
||||
fec_data_t fec_data[fec_buff_num];
|
||||
int index;
|
||||
unordered_map<u32_t, fec_group_t> mp;
|
||||
blob_decode_t blob_decode;
|
||||
@ -156,8 +159,8 @@ class fec_decode_manager_t
|
||||
int output_n;
|
||||
char ** output_s_arr;
|
||||
int * output_len_arr;
|
||||
char *output_s_arr_buf[max_normal_packet_num+100];
|
||||
int output_len_arr_buf[max_normal_packet_num+100];
|
||||
char *output_s_arr_buf[max_fec_pending_packet_num+100];
|
||||
int output_len_arr_buf[max_fec_pending_packet_num+100];
|
||||
int ready_for_output;
|
||||
public:
|
||||
fec_decode_manager_t();
|
||||
|
22
main.cpp
22
main.cpp
@ -28,9 +28,10 @@ int jitter_max=0;
|
||||
int mtu_warn=1350;
|
||||
|
||||
int disable_mtu_warn=0;
|
||||
int disable_fec=1;
|
||||
|
||||
int fec_data_num=20;
|
||||
int fec_redundant_num=8;
|
||||
int fec_redundant_num=10;
|
||||
int fec_mtu=1000;
|
||||
int fec_pending_num=30;
|
||||
int fec_pending_time=10000;
|
||||
@ -125,13 +126,14 @@ int delay_send(my_time_t delay,const dest_t &dest,char *data,int len)
|
||||
}
|
||||
int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,int *&out_delay)
|
||||
{
|
||||
|
||||
static int out_delay_buf[max_fec_packet_num+100]={0};
|
||||
//static int out_len_buf[max_fec_packet_num+100]={0};
|
||||
static int counter=0;
|
||||
out_delay=out_delay_buf;
|
||||
//out_len=out_len_buf;
|
||||
|
||||
if(0)
|
||||
if(disable_fec)
|
||||
{
|
||||
if(data==0) return 0;
|
||||
out_n=1;
|
||||
@ -158,10 +160,14 @@ int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,ch
|
||||
|
||||
conn_info.fec_encode_manager.output(out_n,out_arr,out_len);
|
||||
|
||||
|
||||
for(int i=0;i<out_n;i++)
|
||||
{
|
||||
out_delay_buf[i]=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mylog(log_debug,"from_normal_to_fec input_len=%d,output_n=%d\n",len,out_n);
|
||||
//for(int i=0;i<n;i++)
|
||||
//{
|
||||
//delay_send(0,dest,s_arr[i],s_len);
|
||||
@ -172,9 +178,9 @@ int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,ch
|
||||
}
|
||||
int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,int *&out_delay)
|
||||
{
|
||||
static int out_delay_buf[max_normal_packet_num+100]={0};
|
||||
static int out_delay_buf[max_fec_pending_packet_num+100]={0};
|
||||
out_delay=out_delay_buf;
|
||||
if(0)
|
||||
if(disable_fec)
|
||||
{
|
||||
if(data==0) return 0;
|
||||
out_n=1;
|
||||
@ -195,11 +201,13 @@ int from_fec_to_normal(conn_info_t & conn_info,char *data,int len,int & out_n,ch
|
||||
conn_info.fec_decode_manager.output(out_n,out_arr,out_len);
|
||||
for(int i=0;i<out_n;i++)
|
||||
{
|
||||
//out_delay_buf[i]=100*i;
|
||||
out_delay_buf[i]=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mylog(log_debug,"from_fec_to_normal input_len=%d,output_n=%d\n",len,out_n);
|
||||
|
||||
// printf("<n:%d>",n);
|
||||
/*
|
||||
for(int i=0;i<n;i++)
|
||||
@ -642,7 +650,7 @@ int server_event_loop()
|
||||
u64_t timer_fd64=conn_info.timer.get_timer_fd64();
|
||||
fd_manager.get_info(timer_fd64).ip_port=ip_port;
|
||||
|
||||
mylog(log_info,"new connection from %s,conn_info.timer_fd %lld,\n",ip_port.to_s(),timer.get_timer_fd64());
|
||||
mylog(log_info,"new connection from %s\n",ip_port.to_s());
|
||||
|
||||
}
|
||||
conn_info_t &conn_info=conn_manager.find(ip_port);
|
||||
|
Loading…
x
Reference in New Issue
Block a user