added command line options,fixed segment fault

This commit is contained in:
wangyu- 2017-10-17 02:35:18 -05:00
parent 45a8cef2f5
commit f07dae4513
5 changed files with 67 additions and 32 deletions

View File

@ -236,7 +236,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
if(about_to_fec)
{
char ** blob_output;
char ** blob_output=0;
int fec_len=-1;
mylog(log_trace,"counter=%d\n",counter);
@ -270,7 +270,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/)
}
actual_data_num=best_data_num;
actual_redundant_num=fec_redundant_num;
mylog(log_info,"actual_data_num=%d actual_redundant_num=%d\n",best_data_num,fec_redundant_num);
mylog(log_trace,"actual_data_num=%d actual_redundant_num=%d\n",best_data_num,fec_redundant_num);
}
assert(blob_encode.output(actual_data_num,blob_output,fec_len)==0);
@ -488,6 +488,7 @@ int fec_decode_manager_t::input(char *s,int len)
len=len-tmp_idx;
mylog(log_trace,"input\n");
assert(len+100<buf_len);
if(len<0)
{
mylog(log_warn,"len<0\n");
@ -591,6 +592,8 @@ int fec_decode_manager_t::input(char *s,int len)
fec_data[index].redundant_num=redundant_num;
fec_data[index].idx=inner_index;
fec_data[index].len=len;
assert(0<=index&&index<(int)fec_buff_num);
assert(len+100<buf_len);
memcpy(fec_data[index].buf,s+tmp_idx,len);
mp[seq].group_mp[inner_index]=index;
//index++ at end of function
@ -774,7 +777,7 @@ int fec_decode_manager_t::input(char *s,int len)
end:
index++;
if(index==int(anti_replay_buff_size)) index=0;
if(index==int(fec_buff_num)) index=0;
return 0;
}

View File

@ -152,7 +152,7 @@ struct fec_group_t
class fec_decode_manager_t
{
anti_replay_t anti_replay;
fec_data_t fec_data[fec_buff_num];
fec_data_t fec_data[fec_buff_num+10];
int index;
unordered_map<u32_t, fec_group_t> mp;
blob_decode_t blob_decode;

View File

@ -32,10 +32,10 @@ int disable_fec=0;
int debug_force_flush_fec=0;
int fec_data_num=160;
int fec_redundant_num=80;
int fec_data_num=20;
int fec_redundant_num=10;
int fec_mtu=1250;
int fec_pending_num=50;
int fec_pending_num=200;
int fec_pending_time=10000; //10ms
int fec_type=0;
@ -1193,15 +1193,12 @@ void process_arg(int argc, char *argv[])
}
int no_l = 1, no_r = 1;
while ((opt = getopt_long(argc, argv, "l:r:d:t:hcspk:j:m:",long_options,&option_index)) != -1)
while ((opt = getopt_long(argc, argv, "l:r:d:t:hcsk:j:m:f:p:n:",long_options,&option_index)) != -1)
{
//string opt_key;
//opt_key+=opt;
switch (opt)
{
case 'p':
//multi_process_mode=1;
break;
case 'k':
sscanf(optarg,"%s\n",key_string);
mylog(log_debug,"key=%s\n",key_string);
@ -1211,7 +1208,7 @@ void process_arg(int argc, char *argv[])
myexit(-1);
}
break;
/*
case 'm':
sscanf(optarg,"%d\n",&max_pending_packet);
if(max_pending_packet<1000)
@ -1220,7 +1217,7 @@ void process_arg(int argc, char *argv[])
myexit(-1);
}
break;
*/
case 'j':
if (strchr(optarg, ':') == 0)
{
@ -1244,31 +1241,59 @@ void process_arg(int argc, char *argv[])
}
}
break;
case 't':
sscanf(optarg,"%d",&fec_type);
/*
case 'f':
if (strchr(optarg, ':') == 0)
{
int dup_delay=-1;
sscanf(optarg,"%d\n",&dup_delay);
if(dup_delay<1||dup_delay>1000*100)
{
mylog(log_fatal,"dup_delay must be between 1 and 100,000(10 second)\n");
myexit(-1);
}
dup_delay_min=dup_delay_max=dup_delay;
mylog(log_fatal,"invalid format for f");
myexit(-1);
}
else
{
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)
sscanf(optarg,"%d:%d\n",&fec_data_num,&fec_redundant_num);
if(fec_data_num<1 ||fec_redundant_num<0||fec_data_num+fec_redundant_num>255)
{
mylog(log_fatal," must satisfy 1<=dmin<=dmax\n");
mylog(log_fatal,"fec_data_num<1 ||fec_redundant_num<0||fec_data_num+fec_redundant_num>255\n");
myexit(-1);
}
}*/
}
break;
case 't':
sscanf(optarg,"%d",&fec_type);
if(fec_type!=0&&fec_type!=1)
{
mylog(log_fatal,"mode should be 0 or 1\n");
myexit(-1);
}
break;
case 'm':
sscanf(optarg,"%d",&fec_mtu);
if(fec_mtu<500||fec_mtu>1600)
{
mylog(log_fatal,"fec_mtu should be between 500 and 1600\n");
myexit(-1);
}
break;
case 'p':
sscanf(optarg,"%d",&fec_pending_time);
if(fec_pending_time<0||fec_pending_time>10000)
{
mylog(log_fatal,"fec_pending_time should be between 0 and 10000\n");
myexit(-1);
}
fec_pending_time*=100;
break;
case 'n':
sscanf(optarg,"%d",&fec_pending_num);
if(fec_pending_num<1||fec_pending_num>1000)
{
mylog(log_fatal,"fec_pending_num should be between 1 and 1000\n");
myexit(-1);
}
break;
/*
case 'd':
dup_num=-1;
sscanf(optarg,"%d\n",&dup_num);
@ -1278,7 +1303,7 @@ void process_arg(int argc, char *argv[])
myexit(-1);
}
dup_num+=1;
break;
break;*/
case 'c':
is_client = 1;
break;

View File

@ -28,16 +28,24 @@ debug2: git_version
mips24kc_be: git_version
${cc_mips24kc_be} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
mips24kc_be_debug: git_version
${cc_mips24kc_be} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -ggdb
mips24kc_le: git_version
${cc_mips24kc_le} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
amd64:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
amd64_debug:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -ggdb
x86:git_version
${cc_local} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3 -m32
arm:git_version
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -O3
arm_debug:git_version
${cc_arm} -o ${NAME}_$@ -I. ${SOURCES} ${FLAGS} -lrt -static -ggdb
cross:git_version
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3

View File

@ -25,7 +25,7 @@ int disable_xor=0;
int random_drop=0;
char key_string[1000]= "secret key";
char key_string[1000]= "";
int local_listen_fd=-1;
@ -43,7 +43,6 @@ void encrypt_0(char * input,int &len,char *key)
void decrypt_0(char * input,int &len,char *key)
{
int i,j;
if(key[0]==0) return;
for(i=0,j=0;i<len;i++,j++)