mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
new option hb-mode
This commit is contained in:
parent
d487ca57f7
commit
50f682daf4
30
main.cpp
30
main.cpp
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
|
int mtu_warn=1375;//if a packet larger than mtu warn is receviced,there will be a warning
|
||||||
|
|
||||||
|
|
||||||
char hb_buf[buf_len];
|
char hb_buf[buf_len];
|
||||||
int hb_len=1200;
|
int hb_len=1200;
|
||||||
|
|
||||||
@ -242,8 +243,10 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is
|
|||||||
|
|
||||||
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
|
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
|
||||||
|
|
||||||
send_safer(conn_info,'h',hb_buf,hb_len);/////////////send
|
if(hb_mode==0)
|
||||||
|
send_safer(conn_info,'h',hb_buf,0);/////////////send
|
||||||
|
else
|
||||||
|
send_safer(conn_info,'h',hb_buf,hb_len);
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -285,8 +288,10 @@ int server_on_timer_multi(conn_info_t &conn_info,char * ip_port) //for server.
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_safer(conn_info,'h',hb_buf,hb_len); /////////////send
|
if(hb_mode==0)
|
||||||
|
send_safer(conn_info,'h',hb_buf,0); /////////////send
|
||||||
|
else
|
||||||
|
send_safer(conn_info,'h',hb_buf,hb_len);
|
||||||
conn_info.last_hb_sent_time=get_current_time();
|
conn_info.last_hb_sent_time=get_current_time();
|
||||||
|
|
||||||
mylog(log_debug,"heart beat sent<%x,%x>\n",conn_info.my_id,conn_info.oppsite_id);
|
mylog(log_debug,"heart beat sent<%x,%x>\n",conn_info.my_id,conn_info.oppsite_id);
|
||||||
@ -442,6 +447,7 @@ int client_on_raw_recv(conn_info_t &conn_info) //called when raw fd received a p
|
|||||||
{
|
{
|
||||||
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
mylog(log_trace,"received a data from fake tcp,len:%d\n",data_len);
|
||||||
|
|
||||||
|
if(hb_mode==0)
|
||||||
conn_info.last_hb_recv_time=get_current_time();
|
conn_info.last_hb_recv_time=get_current_time();
|
||||||
|
|
||||||
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
|
//u32_t tmp_conv_id= ntohl(* ((u32_t *)&data[0]));
|
||||||
@ -790,6 +796,7 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
|
|||||||
tmp_conv_id=ntohl(tmp_conv_id);
|
tmp_conv_id=ntohl(tmp_conv_id);
|
||||||
|
|
||||||
|
|
||||||
|
if(hb_mode==0)
|
||||||
conn_info.last_hb_recv_time = get_current_time();
|
conn_info.last_hb_recv_time = get_current_time();
|
||||||
|
|
||||||
mylog(log_trace, "conv:%u\n", tmp_conv_id);
|
mylog(log_trace, "conv:%u\n", tmp_conv_id);
|
||||||
@ -916,11 +923,14 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
|||||||
|
|
||||||
//my_id=conn_info.my_id;
|
//my_id=conn_info.my_id;
|
||||||
//oppsite_id=conn_info.oppsite_id;
|
//oppsite_id=conn_info.oppsite_id;
|
||||||
|
|
||||||
conn_info.last_hb_recv_time = get_current_time();
|
conn_info.last_hb_recv_time = get_current_time();
|
||||||
|
|
||||||
conn_info.last_hb_sent_time = conn_info.last_hb_recv_time;//=get_current_time()
|
conn_info.last_hb_sent_time = conn_info.last_hb_recv_time;//=get_current_time()
|
||||||
|
|
||||||
send_safer(conn_info, 'h',hb_buf, hb_len); /////////////send
|
if(hb_mode==0)
|
||||||
|
send_safer(conn_info,'h',hb_buf,0);/////////////send
|
||||||
|
else
|
||||||
|
send_safer(conn_info,'h',hb_buf,hb_len);
|
||||||
|
|
||||||
mylog(log_info, "[%s]changed state to server_ready\n",ip_port);
|
mylog(log_info, "[%s]changed state to server_ready\n",ip_port);
|
||||||
conn_info.blob->anti_replay.re_init();
|
conn_info.blob->anti_replay.re_init();
|
||||||
@ -980,8 +990,14 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
|
|||||||
//ori_conn_info.state.server_current_state=server_ready;
|
//ori_conn_info.state.server_current_state=server_ready;
|
||||||
ori_conn_info.recover(conn_info);
|
ori_conn_info.recover(conn_info);
|
||||||
|
|
||||||
send_safer(ori_conn_info, 'h',hb_buf, hb_len);
|
//send_safer(ori_conn_info, 'h',hb_buf, hb_len);
|
||||||
//ori_conn_info.blob->anti_replay.re_init();
|
//ori_conn_info.blob->anti_replay.re_init();
|
||||||
|
if(hb_mode==0)
|
||||||
|
send_safer(ori_conn_info,'h',hb_buf,0);/////////////send
|
||||||
|
else
|
||||||
|
send_safer(ori_conn_info,'h',hb_buf,hb_len);
|
||||||
|
|
||||||
|
ori_conn_info.last_hb_recv_time=get_current_time();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
9
misc.cpp
9
misc.cpp
@ -13,6 +13,8 @@
|
|||||||
#include "fd_manager.h"
|
#include "fd_manager.h"
|
||||||
|
|
||||||
|
|
||||||
|
int hb_mode=1;
|
||||||
|
|
||||||
fd_manager_t fd_manager;
|
fd_manager_t fd_manager;
|
||||||
|
|
||||||
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
char local_ip[100]="0.0.0.0", remote_ip[100]="255.255.255.255",source_ip[100]="0.0.0.0";//local_ip is for -l option,remote_ip for -r option,source for --source-ip
|
||||||
@ -247,6 +249,7 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{"force-sock-buf", no_argument, 0, 1},
|
{"force-sock-buf", no_argument, 0, 1},
|
||||||
{"random-drop", required_argument, 0, 1},
|
{"random-drop", required_argument, 0, 1},
|
||||||
{"fifo", required_argument, 0, 1},
|
{"fifo", required_argument, 0, 1},
|
||||||
|
{"hb-mode", required_argument, 0, 1},
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -589,6 +592,12 @@ void process_arg(int argc, char *argv[]) //process all options
|
|||||||
{
|
{
|
||||||
mylog(log_info,"configuration loaded from %s\n",optarg);
|
mylog(log_info,"configuration loaded from %s\n",optarg);
|
||||||
}
|
}
|
||||||
|
else if(strcmp(long_options[option_index].name,"hb-mode")==0)
|
||||||
|
{
|
||||||
|
sscanf(optarg,"%d",&hb_mode);
|
||||||
|
assert(hb_mode==0||hb_mode==1);
|
||||||
|
mylog(log_info,"hb_mode =%d \n",hb_mode);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user