From f07dae45137b72fef74e564680d73bcca2f20f60 Mon Sep 17 00:00:00 2001 From: wangyu- Date: Tue, 17 Oct 2017 02:35:18 -0500 Subject: [PATCH] added command line options,fixed segment fault --- fec_manager.cpp | 9 ++++-- fec_manager.h | 2 +- main.cpp | 77 ++++++++++++++++++++++++++++++++----------------- makefile | 8 +++++ packet.cpp | 3 +- 5 files changed, 67 insertions(+), 32 deletions(-) diff --git a/fec_manager.cpp b/fec_manager.cpp index 3efc84a..97949bd 100644 --- a/fec_manager.cpp +++ b/fec_manager.cpp @@ -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 mp; blob_decode_t blob_decode; diff --git a/main.cpp b/main.cpp index 01965e8..9d2df64 100644 --- a/main.cpp +++ b/main.cpp @@ -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; diff --git a/makefile b/makefile index ef08b3b..6ab131a 100755 --- a/makefile +++ b/makefile @@ -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 diff --git a/packet.cpp b/packet.cpp index bbe10eb..5714b65 100644 --- a/packet.cpp +++ b/packet.cpp @@ -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