mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-31 12:19:35 +08:00
just commit
This commit is contained in:
parent
45032e4a95
commit
44e9f5cb8b
1274
classic.cpp
1274
classic.cpp
File diff suppressed because it is too large
Load Diff
18
classic.h
18
classic.h
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
* classic.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 15, 2017
|
|
||||||
* Author: root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLASSIC_H_
|
|
||||||
#define CLASSIC_H_
|
|
||||||
|
|
||||||
|
|
||||||
namespace classic
|
|
||||||
{
|
|
||||||
int main(int argc, char *argv[]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* CLASSIC_H_ */
|
|
40
common.cpp
40
common.cpp
@ -14,11 +14,11 @@ int about_to_exit=0;
|
|||||||
|
|
||||||
raw_mode_t raw_mode=mode_faketcp;
|
raw_mode_t raw_mode=mode_faketcp;
|
||||||
unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
|
unordered_map<int, const char*> raw_mode_tostring = {{mode_faketcp, "faketcp"}, {mode_udp, "udp"}, {mode_icmp, "icmp"}};
|
||||||
int socket_buf_size=1024*1024;
|
|
||||||
int max_pending_packet=0;
|
int max_pending_packet=0;
|
||||||
static int random_number_fd=-1;
|
static int random_number_fd=-1;
|
||||||
char iptables_rule[200]="";
|
char iptables_rule[200]="";
|
||||||
int is_client = 0, is_server = 0;
|
//int is_client = 0, is_server = 0;
|
||||||
|
|
||||||
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
|
program_mode_t program_mode=unset_mode;//0 unset; 1client 2server
|
||||||
|
|
||||||
@ -204,23 +204,37 @@ unsigned short csum(const unsigned short *ptr,int nbytes) {
|
|||||||
|
|
||||||
return(answer);
|
return(answer);
|
||||||
}
|
}
|
||||||
int set_buf_size(int fd,int size)
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
|
||||||
{
|
{
|
||||||
//int socket_buf_size=1024*1024;
|
if(force_socket_buf)
|
||||||
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
|
||||||
//if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
|
||||||
{
|
{
|
||||||
printf("set SO_SNDBUF fail\n");
|
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||||
exit(1);
|
{
|
||||||
|
mylog(log_fatal,"SO_SNDBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||||
|
myexit(1);
|
||||||
|
}
|
||||||
|
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||||
|
{
|
||||||
|
mylog(log_fatal,"SO_RCVBUFFORCE fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||||
|
myexit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||||
|
{
|
||||||
|
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||||
|
myexit(1);
|
||||||
}
|
}
|
||||||
//if(setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &socket_buf_size, sizeof(socket_buf_size))<0)
|
|
||||||
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
|
||||||
{
|
{
|
||||||
printf("set SO_RCVBUF fail\n");
|
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
|
||||||
exit(1);
|
myexit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void myexit(int a)
|
void myexit(int a)
|
||||||
{
|
{
|
||||||
if(enable_log_color)
|
if(enable_log_color)
|
||||||
@ -374,7 +388,7 @@ int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port)
|
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in remote_addr_in;
|
struct sockaddr_in remote_addr_in;
|
||||||
@ -401,4 +415,4 @@ int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}*/
|
||||||
|
9
common.h
9
common.h
@ -45,8 +45,6 @@
|
|||||||
#include <linux/if_packet.h>
|
#include <linux/if_packet.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include<unordered_map>
|
#include<unordered_map>
|
||||||
#include<unordered_set>
|
#include<unordered_set>
|
||||||
#include<map>
|
#include<map>
|
||||||
@ -116,9 +114,8 @@ extern raw_mode_t raw_mode;
|
|||||||
enum program_mode_t {unset_mode=0,client_mode,server_mode};
|
enum program_mode_t {unset_mode=0,client_mode,server_mode};
|
||||||
extern program_mode_t program_mode;
|
extern program_mode_t program_mode;
|
||||||
extern unordered_map<int, const char*> raw_mode_tostring ;
|
extern unordered_map<int, const char*> raw_mode_tostring ;
|
||||||
extern int socket_buf_size;
|
|
||||||
extern int max_pending_packet;
|
extern int max_pending_packet;
|
||||||
extern int is_client, is_server;
|
|
||||||
|
|
||||||
|
|
||||||
typedef u32_t id_t;
|
typedef u32_t id_t;
|
||||||
@ -149,7 +146,7 @@ u64_t hton64(u64_t a);
|
|||||||
bool larger_than_u16(uint16_t a,uint16_t b);
|
bool larger_than_u16(uint16_t a,uint16_t b);
|
||||||
bool larger_than_u32(u32_t a,u32_t b);
|
bool larger_than_u32(u32_t a,u32_t b);
|
||||||
void setnonblocking(int sock);
|
void setnonblocking(int sock);
|
||||||
int set_buf_size(int fd,int size=socket_buf_size);
|
int set_buf_size(int fd,int socket_buf_size,int force_socket_buf=0);
|
||||||
|
|
||||||
unsigned short csum(const unsigned short *ptr,int nbytes);
|
unsigned short csum(const unsigned short *ptr,int nbytes);
|
||||||
|
|
||||||
@ -167,6 +164,8 @@ int random_between(u32_t a,u32_t b);
|
|||||||
|
|
||||||
int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval);
|
int set_timer_ms(int epollfd,int &timer_fd,u32_t timer_interval);
|
||||||
|
|
||||||
|
/*
|
||||||
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port);
|
int create_new_udp(int &new_udp_fd,int remote_address_uint32,int remote_port);
|
||||||
|
*/
|
||||||
|
|
||||||
#endif /* COMMON_H_ */
|
#endif /* COMMON_H_ */
|
||||||
|
135
conn_manager.cpp
135
conn_manager.cpp
@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* conn_manager.cpp
|
|
||||||
*
|
|
||||||
* Created on: Sep 15, 2017
|
|
||||||
* Author: root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "conn_manager.h"
|
|
||||||
|
|
||||||
int disable_conv_clear=0;
|
|
||||||
|
|
||||||
conn_manager_t_not_used::conn_manager_t_not_used() {
|
|
||||||
clear_it = fd_last_active_time.begin();
|
|
||||||
long long last_clear_time = 0;
|
|
||||||
rehash();
|
|
||||||
//clear_function=0;
|
|
||||||
}
|
|
||||||
conn_manager_t_not_used::~conn_manager_t_not_used() {
|
|
||||||
clear();
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::get_size() {
|
|
||||||
return fd_to_u64.size();
|
|
||||||
}
|
|
||||||
void conn_manager_t_not_used::rehash() {
|
|
||||||
u64_to_fd.rehash(10007);
|
|
||||||
fd_to_u64.rehash(10007);
|
|
||||||
fd_last_active_time.rehash(10007);
|
|
||||||
}
|
|
||||||
void conn_manager_t_not_used::clear() {
|
|
||||||
if (disable_conv_clear)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (it = fd_to_u64.begin(); it != fd_to_u64.end(); it++) {
|
|
||||||
//int fd=int((it->second<<32u)>>32u);
|
|
||||||
close(it->first);
|
|
||||||
}
|
|
||||||
u64_to_fd.clear();
|
|
||||||
fd_to_u64.clear();
|
|
||||||
fd_last_active_time.clear();
|
|
||||||
|
|
||||||
clear_it = fd_last_active_time.begin();
|
|
||||||
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::exist_fd(u32_t fd) {
|
|
||||||
return fd_to_u64.find(fd) != fd_to_u64.end();
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::exist_u64(u64_t u64) {
|
|
||||||
return u64_to_fd.find(u64) != u64_to_fd.end();
|
|
||||||
}
|
|
||||||
u32_t conn_manager_t_not_used::find_fd_by_u64(u64_t u64) {
|
|
||||||
return u64_to_fd[u64];
|
|
||||||
}
|
|
||||||
u64_t conn_manager_t_not_used::find_u64_by_fd(u32_t fd) {
|
|
||||||
return fd_to_u64[fd];
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::update_active_time(u32_t fd) {
|
|
||||||
return fd_last_active_time[fd] = get_current_time();
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::insert_fd(u32_t fd, u64_t u64) {
|
|
||||||
u64_to_fd[u64] = fd;
|
|
||||||
fd_to_u64[fd] = u64;
|
|
||||||
fd_last_active_time[fd] = get_current_time();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::erase_fd(u32_t fd) {
|
|
||||||
if (disable_conv_clear)
|
|
||||||
return 0;
|
|
||||||
u64_t u64 = fd_to_u64[fd];
|
|
||||||
|
|
||||||
u32_t ip = (u64 >> 32u);
|
|
||||||
|
|
||||||
int port = uint16_t((u64 << 32u) >> 32u);
|
|
||||||
|
|
||||||
mylog(log_info, "fd %d cleared,assocated adress %s,%d\n", fd, my_ntoa(ip),
|
|
||||||
port);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
fd_to_u64.erase(fd);
|
|
||||||
u64_to_fd.erase(u64);
|
|
||||||
fd_last_active_time.erase(fd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
void conn_manager_t::check_clear_list() {
|
|
||||||
while (!clear_list.empty()) {
|
|
||||||
int fd = *clear_list.begin();
|
|
||||||
clear_list.pop_front();
|
|
||||||
erase_fd(fd);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
int conn_manager_t_not_used::clear_inactive() {
|
|
||||||
if (get_current_time() - last_clear_time > conv_clear_interval) {
|
|
||||||
last_clear_time = get_current_time();
|
|
||||||
return clear_inactive0();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int conn_manager_t_not_used::clear_inactive0() {
|
|
||||||
if (disable_conv_clear)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
//map<uint32_t,uint64_t>::iterator it;
|
|
||||||
int cnt = 0;
|
|
||||||
it = clear_it;
|
|
||||||
int size = fd_last_active_time.size();
|
|
||||||
int num_to_clean = size / conv_clear_ratio + conv_clear_min; //clear 1/10 each time,to avoid latency glitch
|
|
||||||
|
|
||||||
u64_t current_time = get_current_time();
|
|
||||||
for (;;) {
|
|
||||||
if (cnt >= num_to_clean)
|
|
||||||
break;
|
|
||||||
if (fd_last_active_time.begin() == fd_last_active_time.end())
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (it == fd_last_active_time.end()) {
|
|
||||||
it = fd_last_active_time.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current_time - it->second > conv_timeout) {
|
|
||||||
//mylog(log_info,"inactive conv %u cleared \n",it->first);
|
|
||||||
old_it = it;
|
|
||||||
it++;
|
|
||||||
u32_t fd = old_it->first;
|
|
||||||
erase_fd(old_it->first);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* conn_manager.h
|
|
||||||
*
|
|
||||||
* Created on: Sep 15, 2017
|
|
||||||
* Author: root
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONN_MANAGER_H_
|
|
||||||
#define CONN_MANAGER_H_
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
extern int disable_conv_clear;
|
|
||||||
|
|
||||||
struct conn_manager_t_not_used //TODO change map to unordered map
|
|
||||||
{
|
|
||||||
//typedef hash_map map;
|
|
||||||
unordered_map<u64_t,u32_t> u64_to_fd; //conv and u64 are both supposed to be uniq
|
|
||||||
unordered_map<u32_t,u64_t> fd_to_u64;
|
|
||||||
|
|
||||||
unordered_map<u32_t,u64_t> fd_last_active_time;
|
|
||||||
|
|
||||||
unordered_map<u32_t,u64_t>::iterator clear_it;
|
|
||||||
|
|
||||||
unordered_map<u32_t,u64_t>::iterator it;
|
|
||||||
unordered_map<u32_t,u64_t>::iterator old_it;
|
|
||||||
|
|
||||||
//void (*clear_function)(uint64_t u64) ;
|
|
||||||
|
|
||||||
long long last_clear_time;
|
|
||||||
//list<int> clear_list;
|
|
||||||
conn_manager_t_not_used();
|
|
||||||
~conn_manager_t_not_used();
|
|
||||||
int get_size();
|
|
||||||
void rehash();
|
|
||||||
void clear();
|
|
||||||
int exist_fd(u32_t fd);
|
|
||||||
int exist_u64(u64_t u64);
|
|
||||||
u32_t find_fd_by_u64(u64_t u64);
|
|
||||||
u64_t find_u64_by_fd(u32_t fd);
|
|
||||||
int update_active_time(u32_t fd);
|
|
||||||
int insert_fd(u32_t fd,u64_t u64);
|
|
||||||
int erase_fd(u32_t fd);
|
|
||||||
//void check_clear_list();
|
|
||||||
int clear_inactive();
|
|
||||||
int clear_inactive0();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* CONN_MANAGER_H_ */
|
|
2
makefile
2
makefile
@ -8,7 +8,7 @@ cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
|
|||||||
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
|
||||||
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
|
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
|
||||||
|
|
||||||
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp conn_manager.cpp classic.cpp delay_manager.cpp
|
SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp conn_manager.cpp delay_manager.cpp
|
||||||
|
|
||||||
NAME=speeder
|
NAME=speeder
|
||||||
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
|
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le
|
||||||
|
66
packet.cpp
66
packet.cpp
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "packet.h"
|
||||||
|
|
||||||
int iv_min=2;
|
int iv_min=2;
|
||||||
int iv_max=16;//< 256;
|
int iv_max=16;//< 256;
|
||||||
@ -194,38 +195,25 @@ int de_obscure(const char * input, int in_len,char *output,int &out_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sendto_fd_u64 (int fd,u64_t u64,char * buf, int len,int flags)
|
int sendto_fd_ip_port (int fd,u32_t ip,int port,char * buf, int len,int flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
if(is_server)
|
|
||||||
{
|
|
||||||
dup_packet_send_count++;
|
|
||||||
}
|
|
||||||
if(is_server&&random_drop!=0)
|
|
||||||
{
|
|
||||||
if(get_true_random_number()%10000<(u32_t)random_drop)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
sockaddr_in tmp_sockaddr;
|
sockaddr_in tmp_sockaddr;
|
||||||
|
|
||||||
memset(&tmp_sockaddr,0,sizeof(tmp_sockaddr));
|
memset(&tmp_sockaddr,0,sizeof(tmp_sockaddr));
|
||||||
tmp_sockaddr.sin_family = AF_INET;
|
tmp_sockaddr.sin_family = AF_INET;
|
||||||
tmp_sockaddr.sin_addr.s_addr = (u64 >> 32u);
|
tmp_sockaddr.sin_addr.s_addr = ip;
|
||||||
|
|
||||||
tmp_sockaddr.sin_port = htons(uint16_t((u64 << 32u) >> 32u));
|
tmp_sockaddr.sin_port = htons(uint16_t(port));
|
||||||
|
|
||||||
return sendto(fd, buf,
|
return sendto(fd, buf,
|
||||||
len , 0,
|
len , 0,
|
||||||
(struct sockaddr *) &tmp_sockaddr,
|
(struct sockaddr *) &tmp_sockaddr,
|
||||||
sizeof(tmp_sockaddr));
|
sizeof(tmp_sockaddr));
|
||||||
}
|
}
|
||||||
int sendto_u64 (u64_t u64,char * buf, int len,int flags)
|
int sendto_ip_port (u32_t ip,int port,char * buf, int len,int flags)
|
||||||
{
|
{
|
||||||
return sendto_fd_u64(local_listen_fd,u64,buf,len,flags);
|
return sendto_fd_ip_port(local_listen_fd,ip,port,buf,len,flags);
|
||||||
}
|
}
|
||||||
int send_fd (int fd,char * buf, int len,int flags)
|
int send_fd (int fd,char * buf, int len,int flags)
|
||||||
{
|
{
|
||||||
@ -243,4 +231,46 @@ int send_fd (int fd,char * buf, int len,int flags)
|
|||||||
}*/
|
}*/
|
||||||
return send(fd,buf,len,flags);
|
return send(fd,buf,len,flags);
|
||||||
}
|
}
|
||||||
|
//enum delay_type_t {none=0,enum_sendto_u64,enum_send_fd,client_to_local,client_to_remote,server_to_local,server_to_remote};
|
||||||
|
|
||||||
|
int my_send(dest_t &dest,char *data,int len)
|
||||||
|
{
|
||||||
|
switch(dest.type)
|
||||||
|
{
|
||||||
|
case type_ip_port:
|
||||||
|
return sendto_ip_port(dest.inner.ip_port.ip,dest.inner.ip_port.port,data,len,0);
|
||||||
|
break;
|
||||||
|
case type_fd64:
|
||||||
|
if(!fd_manager.fd64_exist(dest.inner.fd64)) return -1;
|
||||||
|
int fd=fd_manager.fd64_to_fd(dest.inner.fd64);
|
||||||
|
return send_fd(fd,data,len,0);
|
||||||
|
break;
|
||||||
|
case type_fd:
|
||||||
|
send_fd(dest.inner.fd,data,len,0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0==1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int put_conv(u32_t conv,char * input,int len_in,char *&output,int &len_out)
|
||||||
|
{
|
||||||
|
static char buf[buf_len];
|
||||||
|
output=buf;
|
||||||
|
u32_t n_conv=htonl(conv);
|
||||||
|
memcpy(output,&n_conv,sizeof(n_conv));
|
||||||
|
memcpy(output+sizeof(n_conv),input,len_in);
|
||||||
|
len_out=len_in+(int)(sizeof(n_conv));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int get_conv(u32_t &conv,char *input,int len_in,char *&output,int &len_out )
|
||||||
|
{
|
||||||
|
u32_t n_conv;
|
||||||
|
memcpy(&n_conv,input,sizeof(n_conv));
|
||||||
|
conv=ntohl(n_conv);
|
||||||
|
output=input+sizeof(n_conv);
|
||||||
|
len_out=len_in-(int)(sizeof(n_conv));
|
||||||
|
if(len_out<0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
28
packet.h
28
packet.h
@ -9,6 +9,7 @@
|
|||||||
#define PACKET_H_
|
#define PACKET_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "fd_manager.h"
|
||||||
|
|
||||||
extern int iv_min;
|
extern int iv_min;
|
||||||
extern int iv_max;//< 256;
|
extern int iv_max;//< 256;
|
||||||
@ -22,6 +23,29 @@ extern int disable_replay_filter;
|
|||||||
extern int random_drop;
|
extern int random_drop;
|
||||||
extern int local_listen_fd;
|
extern int local_listen_fd;
|
||||||
|
|
||||||
|
|
||||||
|
enum dest_type{none=0,type_ip_port,type_fd64,type_fd};
|
||||||
|
|
||||||
|
|
||||||
|
struct ip_port_t
|
||||||
|
{
|
||||||
|
u32_t ip;
|
||||||
|
int port;
|
||||||
|
};
|
||||||
|
union inner_t
|
||||||
|
{
|
||||||
|
ip_port_t ip_port;
|
||||||
|
int fd;
|
||||||
|
fd64_t fd64;
|
||||||
|
};
|
||||||
|
struct dest_t
|
||||||
|
{
|
||||||
|
dest_type type;
|
||||||
|
inner_t inner;
|
||||||
|
};
|
||||||
|
|
||||||
|
int my_send(dest_t &dest,char *data,int len);
|
||||||
|
|
||||||
void encrypt_0(char * input,int &len,char *key);
|
void encrypt_0(char * input,int &len,char *key);
|
||||||
void decrypt_0(char * input,int &len,char *key);
|
void decrypt_0(char * input,int &len,char *key);
|
||||||
int add_seq(char * data,int &data_len );
|
int add_seq(char * data,int &data_len );
|
||||||
@ -29,8 +53,8 @@ int remove_seq(char * data,int &data_len);
|
|||||||
int do_obscure(const char * input, int in_len,char *output,int &out_len);
|
int do_obscure(const char * input, int in_len,char *output,int &out_len);
|
||||||
int de_obscure(const char * input, int in_len,char *output,int &out_len);
|
int de_obscure(const char * input, int in_len,char *output,int &out_len);
|
||||||
|
|
||||||
int sendto_fd_u64 (int fd,u64_t u64,char * buf, int len,int flags);
|
//int sendto_fd_u64 (int fd,u64_t u64,char * buf, int len,int flags);
|
||||||
int sendto_u64 (u64_t u64,char * buf, int len,int flags);
|
int sendto_ip_port (u32_t ip,int port,char * buf, int len,int flags);
|
||||||
int send_fd (int fd,char * buf, int len,int flags);
|
int send_fd (int fd,char * buf, int len,int flags);
|
||||||
|
|
||||||
#endif /* PACKET_H_ */
|
#endif /* PACKET_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user