Skip to content

Commit

Permalink
more robust,more log
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Oct 17, 2017
1 parent 9e96a94 commit 93cbe52
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 68 deletions.
2 changes: 1 addition & 1 deletion common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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 max_pending_packet=0;
int delay_capacity=0;
//static int random_number_fd=-1;
char iptables_rule[200]="";
//int is_client = 0, is_server = 0;
Expand Down
4 changes: 2 additions & 2 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef short i16_t;

typedef u64_t my_time_t;

const int max_data_len=2000;
const int max_data_len=2200;
const int buf_len=max_data_len+200;

const u32_t conv_clear_interval=200;
Expand Down Expand Up @@ -117,7 +117,7 @@ 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 max_pending_packet;
extern int delay_capacity;


typedef u32_t id_t;
Expand Down
1 change: 1 addition & 0 deletions connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const int disable_conv_clear=0;//a udp connection in the multiplexer is called c

const int disable_conn_clear=0;//a raw connection is called conn.

int report_interval=0;

void server_clear_function(u64_t u64)//used in conv_manager in server mode.for server we have to use one udp fd for one conv(udp connection),
//so we have to close the fd when conv expires
Expand Down
50 changes: 50 additions & 0 deletions connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern int disable_anti_replay;
#include "fd_manager.h"
#include "fec_manager.h"

extern int report_interval;

struct conv_manager_t // manage the udp connections
{
Expand Down Expand Up @@ -51,6 +52,54 @@ struct conv_manager_t // manage the udp connections
int clear_inactive(char * ip_port=0);
int clear_inactive0(char * ip_port);
};


struct inner_stat_t
{
u64_t input_packet_num;
u64_t input_packet_size;
u64_t output_packet_num;
u64_t output_packet_size;
};
struct stat_t
{
u64_t last_report_time;
inner_stat_t normal_to_fec;
inner_stat_t fec_to_normal;
stat_t()
{
memset(this,0,sizeof(stat_t));
}
void report_as_client()
{
if(report_interval!=0 &&get_current_time()-last_report_time>u64_t(report_interval)*1000)
{
last_report_time=get_current_time();
inner_stat_t &a=normal_to_fec;
inner_stat_t &b=fec_to_normal;
mylog(log_info,"[report]client-->server:(original:%llu pkt;%llu byte) (fec:%llu pkt,%llu byte) server-->client:(original:%llu pkt;%llu byte) (fec:%llu pkt;%llu byte)\n",
a.input_packet_num,a.input_packet_size,a.output_packet_num,a.output_packet_size,
b.output_packet_num,b.output_packet_size,b.input_packet_num,b.input_packet_size
);
}
}
void report_as_server(ip_port_t &ip_port)
{
if(report_interval!=0 &&get_current_time()-last_report_time>u64_t(report_interval)*1000)
{
last_report_time=get_current_time();
inner_stat_t &a=fec_to_normal;
inner_stat_t &b=normal_to_fec;
mylog(log_info,"[report][%s]client-->server:(original:%llu pkt;%llu byte) (fec:%llu pkt;%llu byte) server-->client:(original:%llu pkt;%llu byte) (fec:%llu pkt;%llu byte)\n",
ip_port.to_s(),
a.output_packet_num,a.output_packet_size,a.input_packet_num,a.input_packet_size,
b.input_packet_num,b.input_packet_size,b.output_packet_num,b.output_packet_size
);
}
}
};


struct conn_info_t //stores info for a raw connection.for client ,there is only one connection,for server there can be thousand of connection since server can
//handle multiple clients
{
Expand All @@ -60,6 +109,7 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
my_timer_t timer;
ip_port_t ip_port;
u64_t last_active_time;
stat_t stat;
conn_info_t()
{
}
Expand Down
Loading

0 comments on commit 93cbe52

Please sign in to comment.