ProxyServerTcp / include /udp_client.h
xukc
[fix]udp runtime error
99dc157
#ifndef PROXYSERVER_UDP_CLIENT_H
#define PROXYSERVER_UDP_CLIENT_H
#include "hv/hloop.h"
#include "hv/UdpClient.h"
#include "bolt/crypt.h"
#include "udp_client_map.h"
#include <string>
class UdpBoltConfig
{
public:
uint32_t request_id;
uint32_t session_id;
std::string signal_id;
std::string data_st;
bool encrypt = false;
CRYPT_TYPE ept_type;
char ept_key;
};
#define TIMEOUT_TIMEUNIT 10 * 1000
#define DNS_TIMEOUT 5 * 1000
class UdpClientProxy
{
public:
UdpClientProxy(struct sockaddr_in t_addr, struct sockaddr_in u_addr, uint32_t session_id) : t_addr(t_addr), u_addr(u_addr), session_id(session_id) {}
hio_t *getClientIO() { return cli_io; }
bool init(hloop_t* loop);
void close();
bool isDns() {
return ntohs(t_addr.sin_port) == 53;
};
private:
void onRecv(void* buf, int readbytes);
void onWrited(const void* buf, int writebytes);
void onClosed();
public:
struct sockaddr_in t_addr, u_addr;
private:
hio_t *cli_io;
htimer_t* timer;
uint32_t session_id;
long long ts;
};
class UdpServerBoltProxy
{
public:
UdpServerBoltProxy(hio_t *_io) : io(_io) {}
UdpBoltConfig &getConfig() { return config; }
bool analyzeData(struct sockaddr_in t_addr, struct sockaddr_in u_addr, uint32_t session_id, char *data, int data_len, char *extend, int extend_len);
int sendData(struct sockaddr_in t_addr, struct sockaddr_in u_addr, void *data, int data_len);
void closeClient(struct sockaddr_in &t_addr, struct sockaddr_in &u_addr);
void recycle();
private:
UdpBoltConfig config;
hio_t *io;
UdpClientMap<std::string, UdpClientProxy> _map;
};
#endif // PROXYSERVER_UDP_CLIENT_H