mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 06:19:31 +08:00
fix a dead loop, moved some code blocks
This commit is contained in:
parent
2e8294ab88
commit
3a372b9eee
@ -245,6 +245,7 @@ struct conn_info_t //stores info for a raw connection.for client ,there is o
|
||||
|
||||
|
||||
fd64_t timer_fd64;
|
||||
fd64_t udp_fd64;
|
||||
|
||||
id_t oppsite_const_id;
|
||||
|
||||
|
140
main.cpp
140
main.cpp
@ -590,9 +590,15 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,id_t tmp_oppsite_id )
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
int server_on_timer_multi(conn_info_t &conn_info,char * ip_port) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection
|
||||
int server_on_timer(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection
|
||||
|
||||
{
|
||||
char ip_port[40];
|
||||
u32_t ip=conn_info.raw_info.send_info.dst_ip;
|
||||
u32_t port=conn_info.raw_info.send_info.dst_port;
|
||||
|
||||
sprintf(ip_port,"%s:%d",my_ntoa(ip),port);
|
||||
|
||||
//keep_iptables_rule();
|
||||
mylog(log_trace,"server timer!\n");
|
||||
raw_info_t &raw_info=conn_info.raw_info;
|
||||
@ -1164,101 +1170,17 @@ int server_on_raw_recv_multi() //called when server received an raw packet
|
||||
return -1;
|
||||
}
|
||||
|
||||
int server_on_udp_recv(fd64_t fd64)
|
||||
int server_on_udp_recv(conn_info_t &conn_info,fd64_t fd64)
|
||||
{
|
||||
u64_t begin_time=0;
|
||||
u64_t end_time=0;
|
||||
|
||||
char buf[buf_len];
|
||||
|
||||
if(!fd_manager.exist(fd64))
|
||||
{
|
||||
mylog(log_trace ,"fd64 no longer exist\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
assert(fd_manager.exist_info(fd64));
|
||||
|
||||
conn_info_t* p_conn_info=fd_manager.get_info(fd64).p_conn_info;
|
||||
u32_t ip=p_conn_info->raw_info.send_info.dst_ip;
|
||||
u32_t port=p_conn_info->raw_info.send_info.dst_port;
|
||||
|
||||
//assert(conn_manager.exist(ip,port));
|
||||
|
||||
///conn_info_t* p_conn_info=conn_manager.find_insert_p(ip,port);
|
||||
|
||||
|
||||
if(fd64==p_conn_info->timer_fd64)//////////timer_fd64
|
||||
{
|
||||
|
||||
if(debug_flag)begin_time=get_current_time();
|
||||
//int fd=get_u64_l(events[idx].data.u64);
|
||||
int fd=fd_manager.to_fd(fd64);
|
||||
u64_t dummy;
|
||||
read(fd, &dummy, 8);
|
||||
|
||||
/*if(conn_manager.timer_fd_mp.find(fd)==conn_manager.timer_fd_mp.end()) //this can happen,when fd is a just closed fd
|
||||
{
|
||||
mylog(log_info,"timer_fd no longer exits\n");
|
||||
continue;
|
||||
}*/
|
||||
//conn_info_t* p_conn_info=conn_manager.timer_fd_mp[fd];
|
||||
//u32_t ip=p_conn_info->raw_info.recv_info.src_ip;
|
||||
//u32_t port=p_conn_info->raw_info.recv_info.src_port;
|
||||
//assert(conn_manager.exist(ip,port));//TODO remove this for peformance
|
||||
|
||||
assert(p_conn_info->state.server_current_state == server_ready); //TODO remove this for peformance
|
||||
|
||||
//conn_info_t &conn_info=conn_manager.find(ip,port);
|
||||
char ip_port[40];
|
||||
|
||||
sprintf(ip_port,"%s:%d",my_ntoa(ip),port);
|
||||
|
||||
server_on_timer_multi(*p_conn_info,ip_port);
|
||||
|
||||
if(debug_flag)
|
||||
{
|
||||
end_time=get_current_time();
|
||||
mylog(log_debug,"(events[idx].data.u64 >>32u) == 2u ,%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time);
|
||||
}
|
||||
|
||||
}
|
||||
else//udp_fd64
|
||||
{
|
||||
//}
|
||||
//else if ((events[idx].data.u64 >>32u) == 1u)
|
||||
//{
|
||||
//uint32_t conv_id=events[n].data.u64>>32u;
|
||||
|
||||
if(debug_flag)begin_time=get_current_time();
|
||||
|
||||
//int fd=int((events[idx].data.u64<<32u)>>32u);
|
||||
|
||||
/*
|
||||
if(conn_manager.udp_fd_mp.find(fd)==conn_manager.udp_fd_mp.end()) //this can happen,when fd is a just closed fd
|
||||
{
|
||||
mylog(log_debug,"fd no longer exists in udp_fd_mp,udp fd %d\n",fd);
|
||||
recv(fd,0,0,0);
|
||||
continue;
|
||||
}*/
|
||||
//conn_info_t* p_conn_info=conn_manager.udp_fd_mp[fd];
|
||||
|
||||
//u32_t ip=p_conn_info->raw_info.recv_info.src_ip;
|
||||
//u32_t port=p_conn_info->raw_info.recv_info.src_port;
|
||||
|
||||
/*if(!conn_manager.exist(ip,port))//TODO remove this for peformance
|
||||
{
|
||||
mylog(log_fatal,"ip port no longer exits 2!!!this shouldnt happen\n");
|
||||
myexit(-1);
|
||||
}*/
|
||||
|
||||
if(p_conn_info->state.server_current_state!=server_ready)//TODO remove this for peformance
|
||||
if(conn_info.state.server_current_state!=server_ready)//TODO remove this for peformance
|
||||
{
|
||||
mylog(log_fatal,"p_conn_info->state.server_current_state!=server_ready!!!this shouldnt happen\n");
|
||||
myexit(-1);
|
||||
}
|
||||
|
||||
conn_info_t &conn_info=*p_conn_info;
|
||||
//conn_info_t &conn_info=*p_conn_info;
|
||||
|
||||
assert(conn_info.blob->conv_manager.s.is_data_used(fd64));
|
||||
|
||||
@ -1296,14 +1218,6 @@ int server_on_udp_recv(fd64_t fd64)
|
||||
mylog(log_trace,"send_data_safer ,sent !!\n");
|
||||
}
|
||||
|
||||
if(debug_flag)
|
||||
{
|
||||
end_time=get_current_time();
|
||||
mylog(log_debug,"(events[idx].data.u64 >>32u) == 1u,%lld,%lld,%lld \n",begin_time,end_time,end_time-begin_time);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1780,7 +1694,39 @@ int server_event_loop()
|
||||
{
|
||||
|
||||
fd64_t fd64=events[idx].data.u64;
|
||||
server_on_udp_recv(fd64);
|
||||
if(!fd_manager.exist(fd64))
|
||||
{
|
||||
mylog(log_trace ,"fd64 no longer exist\n");
|
||||
return -1;
|
||||
}
|
||||
assert(fd_manager.exist_info(fd64));
|
||||
conn_info_t* p_conn_info=fd_manager.get_info(fd64).p_conn_info;
|
||||
conn_info_t &conn_info=*p_conn_info;
|
||||
if(fd64==conn_info.timer_fd64)//////////timer_fd64
|
||||
{
|
||||
|
||||
if(debug_flag)begin_time=get_current_time();
|
||||
int fd=fd_manager.to_fd(fd64);
|
||||
u64_t dummy;
|
||||
read(fd, &dummy, 8);
|
||||
assert(conn_info.state.server_current_state == server_ready); //TODO remove this for peformance
|
||||
server_on_timer(conn_info);
|
||||
if(debug_flag)
|
||||
{
|
||||
end_time=get_current_time();
|
||||
mylog(log_debug,"(events[idx].data.u64 >>32u) == 2u ,%llu,%llu,%llu \n",begin_time,end_time,end_time-begin_time);
|
||||
}
|
||||
}
|
||||
else//udp_fd64
|
||||
{
|
||||
if(debug_flag)begin_time=get_current_time();
|
||||
server_on_udp_recv(conn_info,fd64);
|
||||
if(debug_flag)
|
||||
{
|
||||
end_time=get_current_time();
|
||||
mylog(log_debug,"(events[idx].data.u64 >>32u) == 1u,%lld,%lld,%lld \n",begin_time,end_time,end_time-begin_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
18
network.cpp
18
network.cpp
@ -1388,11 +1388,19 @@ int parse_tcp_option(char * option_begin,char * option_end,packet_info_t &recv_i
|
||||
}
|
||||
else
|
||||
{
|
||||
int len=(unsigned char)*(ptr+1);
|
||||
if(len<=1)
|
||||
{
|
||||
mylog(log_debug,"invaild option len %d\n",len);
|
||||
return -1;
|
||||
}
|
||||
//omit check
|
||||
ptr+=*(ptr+1);
|
||||
ptr+=len;
|
||||
}
|
||||
}
|
||||
//printf("!");
|
||||
}
|
||||
//printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1429,6 +1437,11 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tcphdrlen >ip_payloadlen) {
|
||||
mylog(log_debug,"error,tcphdrlen >ip_payloadlen\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if(tcph->dest!=ntohs(uint16_t(filter_port)))
|
||||
{
|
||||
@ -1467,6 +1480,7 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
||||
char *tcp_begin=ip_payload; //ip packet's data part
|
||||
|
||||
char *tcp_option=ip_payload+sizeof(tcphdr);
|
||||
char *option_end=ip_payload+tcphdrlen;
|
||||
|
||||
/*
|
||||
//old ts parse code
|
||||
@ -1516,7 +1530,7 @@ int recv_raw_tcp(raw_info_t &raw_info,char * &payload,int &payloadlen)
|
||||
}
|
||||
printf("<%d %d>\n",recv_info.ts,recv_info.ts_ack);
|
||||
*/
|
||||
parse_tcp_option(tcp_option,tcp_begin+tcph->doff*4,recv_info);
|
||||
parse_tcp_option(tcp_option,option_end,recv_info);
|
||||
|
||||
recv_info.ack=tcph->ack;
|
||||
recv_info.syn=tcph->syn;
|
||||
|
Loading…
x
Reference in New Issue
Block a user