From 3b7619e081a89ef8864d8967f16fcd45feecb626 Mon Sep 17 00:00:00 2001 From: wangyu- Date: Tue, 10 Oct 2017 05:42:59 -0500 Subject: [PATCH] type 1 bug fixed --- delay_manager.cpp | 2 +- fec_manager.cpp | 115 ++++++++++++++++++++++++++++++++++------------ fec_manager.h | 4 +- main.cpp | 12 +++-- 4 files changed, 95 insertions(+), 38 deletions(-) diff --git a/delay_manager.cpp b/delay_manager.cpp index 711a446..e610388 100644 --- a/delay_manager.cpp +++ b/delay_manager.cpp @@ -56,7 +56,7 @@ int delay_manager_t::add(my_time_t delay,const dest_t &dest,char *data,int len) { int ret=delay_data.handle(); if (ret != 0) { - mylog(log_debug, "handle() return %d\n", ret); + mylog(log_trace, "handle() return %d\n", ret); } return 0; } diff --git a/fec_manager.cpp b/fec_manager.cpp index 77db1e0..f2e9a36 100644 --- a/fec_manager.cpp +++ b/fec_manager.cpp @@ -162,16 +162,18 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/) its.it_value.tv_nsec=(tmp_time%1000000llu)*1000llu; timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0); } - if(type==0) { blob_encode.input(s,len); } else if(type==1) { + mylog(log_info,"counter=%d\n",counter); assert(len<=65535&&len>=0); - write_u16(buf[counter]+sizeof(u32_t)+4*sizeof(char),(u16_t)((u32_t)len)); - memcpy(buf[counter]+sizeof(u32_t)+4*sizeof(char)+sizeof(u16_t),s,len);//remember to change this,if protocol is modified + char * p=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); } else @@ -185,7 +187,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) { int about_to_fec=0; int delayed_append=0; - if(type==0&& s!=0 &&blob_encode.get_num()==0&&blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) + if(type==0&& s!=0 &&counter==0&&blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) { mylog(log_warn,"message too long len=%d,ignored\n",len); return -1; @@ -196,6 +198,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) return -1; } if(s==0) about_to_fec=1;//now + assert(type==0||type==1); if(type==0&& blob_encode.get_shard_len(fec_data_num,len)>=fec_mtu) {about_to_fec=1; delayed_append=1;}//fec then add packet if(type==0) assert(counter0); + assert(buf_s_len[i]>=0); if(buf_s_len[i]>fec_len) fec_len=buf_s_len[i]; } } + mylog(log_info,"%d %d %d\n",actual_data_num,actual_redundant_num,fec_len); + char *tmp_output_buf[max_fec_packet_num+5]={0}; for(int i=0;imax_fec_packet_num) { @@ -375,18 +395,22 @@ int fec_decode_manager_t::input(char *s,int len) ok=0; if(ok==0) { - return 0; + return -1; } } if(fec_data[index].used!=0) { - int tmp_seq=fec_data[index].seq; + u32_t tmp_seq=fec_data[index].seq; anti_replay.set_invaild(tmp_seq); if(mp.find(tmp_seq)!=mp.end()) { mp.erase(tmp_seq); } + if(tmp_seq==seq) + { + return -1; + } } fec_data[index].used=1; @@ -425,11 +449,19 @@ int fec_decode_manager_t::input(char *s,int len) { int max_len=-1; int fec_ok=1; + int debug_num=inner_mp.size(); //outupt_s_arr_buf[max_fec_packet_num+5]={0}; + + //memset(output_s_arr_buf,0,sizeof(output_s_arr_buf));//in efficient + + for(int i=0;ifirst]=fec_data[it->second].buf; - assert(fec_data[it->second].len>=0); + assert(fec_data[it->second].len>=(int)sizeof(u16_t)); if(fec_data[it->second].len > max_len) max_len=fec_data[it->second].len; @@ -440,6 +472,8 @@ int fec_decode_manager_t::input(char *s,int len) } int missed_packet[max_fec_packet_num+5]; int missed_packet_counter=0; + + for(int i=0;imax_data_len) { + mylog(log_warn,"invaild len %d,seq= %u,data_num= %d r_num= %d,i= %d\n",output_len_arr_buf[i],seq,data_num,redundant_num,i); fec_ok=0; - break; + for(int i=0;i=80) - { - //return 0; - //mylog(log_info,"dropped!\n"); + + if (dest.cook&&random_drop != 0) { + if (get_true_random_number() % 10000 < (u32_t) random_drop) { + return 0; + } } return delay_manager.add(delay,dest,data,len);; } @@ -155,6 +156,7 @@ 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