2024-08-07 14:25:26 +03:00
|
|
|
#ifndef CONEV_H
|
|
|
|
#define CONEV_H
|
|
|
|
|
2023-06-03 22:52:10 +03:00
|
|
|
#include <stdint.h>
|
2024-10-20 18:50:08 +03:00
|
|
|
#include <stdbool.h>
|
2023-06-03 22:52:10 +03:00
|
|
|
|
|
|
|
#ifndef __linux__
|
2024-02-18 23:20:52 +03:00
|
|
|
#define NOEPOLL
|
2023-06-03 22:52:10 +03:00
|
|
|
#endif
|
|
|
|
|
2024-02-18 23:20:52 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#define poll(fds, cnt, to) WSAPoll(fds, cnt, to)
|
|
|
|
#define close(fd) closesocket(fd)
|
2023-06-03 22:52:10 +03:00
|
|
|
#else
|
2024-02-18 23:20:52 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#ifndef NOEPOLL
|
|
|
|
#include <sys/epoll.h>
|
|
|
|
#define POLLIN EPOLLIN
|
|
|
|
#define POLLOUT EPOLLOUT
|
|
|
|
#define POLLERR EPOLLERR
|
|
|
|
#define POLLHUP EPOLLHUP
|
|
|
|
#define POLLRDHUP EPOLLRDHUP
|
|
|
|
#else
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#endif
|
2023-06-03 22:52:10 +03:00
|
|
|
#endif
|
2024-02-18 23:20:52 +03:00
|
|
|
|
|
|
|
#ifndef POLLRDHUP
|
2024-05-11 17:23:34 +03:00
|
|
|
#define POLLRDHUP 0
|
2023-06-03 22:52:10 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum eid {
|
|
|
|
EV_ACCEPT,
|
|
|
|
EV_REQUEST,
|
|
|
|
EV_CONNECT,
|
|
|
|
EV_IGNORE,
|
2024-03-08 03:37:02 +03:00
|
|
|
EV_TUNNEL,
|
2024-04-23 08:47:27 +03:00
|
|
|
EV_UDP_TUNNEL,
|
2024-10-20 18:50:08 +03:00
|
|
|
EV_FIRST_TUNNEL
|
2023-06-03 22:52:10 +03:00
|
|
|
};
|
|
|
|
|
2023-07-05 11:33:07 +03:00
|
|
|
#define FLAG_S4 1
|
|
|
|
#define FLAG_S5 2
|
|
|
|
#define FLAG_CONN 4
|
2023-06-03 22:52:10 +03:00
|
|
|
|
2024-04-23 08:47:27 +03:00
|
|
|
#ifdef EID_STR
|
2023-06-03 22:52:10 +03:00
|
|
|
char *eid_name[] = {
|
|
|
|
"EV_ACCEPT",
|
|
|
|
"EV_REQUEST",
|
|
|
|
"EV_CONNECT",
|
|
|
|
"EV_IGNORE",
|
2024-03-08 03:37:02 +03:00
|
|
|
"EV_TUNNEL",
|
2024-04-23 08:47:27 +03:00
|
|
|
"EV_UDP_TUNNEL",
|
2024-10-20 18:50:08 +03:00
|
|
|
"EV_FIRST_TUNNEL"
|
2023-06-03 22:52:10 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2024-03-08 03:37:02 +03:00
|
|
|
struct buffer {
|
2024-10-20 18:50:08 +03:00
|
|
|
size_t size;
|
|
|
|
unsigned int offset;
|
2024-03-08 03:37:02 +03:00
|
|
|
char *data;
|
|
|
|
};
|
|
|
|
|
2023-06-03 22:52:10 +03:00
|
|
|
struct eval {
|
|
|
|
int fd;
|
|
|
|
int index;
|
2024-09-08 16:50:21 +03:00
|
|
|
unsigned long long mod_iter;
|
2023-06-03 22:52:10 +03:00
|
|
|
enum eid type;
|
|
|
|
struct eval *pair;
|
2024-03-08 03:37:02 +03:00
|
|
|
struct buffer buff;
|
2023-06-03 22:52:10 +03:00
|
|
|
int flag;
|
2023-07-07 16:26:04 +03:00
|
|
|
union {
|
|
|
|
struct sockaddr_in in;
|
|
|
|
struct sockaddr_in6 in6;
|
|
|
|
};
|
2024-03-08 03:37:02 +03:00
|
|
|
ssize_t recv_count;
|
2024-10-20 18:50:08 +03:00
|
|
|
ssize_t round_sent;
|
2024-09-14 15:47:57 +03:00
|
|
|
unsigned int round_count;
|
2024-03-11 18:38:39 +03:00
|
|
|
int attempt;
|
2024-10-20 18:50:08 +03:00
|
|
|
bool cache;
|
|
|
|
bool mark; //
|
2023-06-03 22:52:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct poolhd {
|
|
|
|
int max;
|
|
|
|
int count;
|
|
|
|
int efd;
|
|
|
|
struct eval **links;
|
|
|
|
struct eval *items;
|
|
|
|
#ifndef NOEPOLL
|
|
|
|
struct epoll_event *pevents;
|
|
|
|
#else
|
|
|
|
struct pollfd *pevents;
|
|
|
|
#endif
|
2024-09-08 16:50:21 +03:00
|
|
|
unsigned long long iters;
|
2023-06-03 22:52:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct poolhd *init_pool(int count);
|
|
|
|
|
|
|
|
struct eval *add_event(struct poolhd *pool, enum eid type, int fd, int e);
|
|
|
|
|
|
|
|
struct eval *add_pair(struct poolhd *pool, struct eval *val, int sfd, int e);
|
|
|
|
|
|
|
|
void del_event(struct poolhd *pool, struct eval *val);
|
|
|
|
|
|
|
|
void destroy_pool(struct poolhd *pool);
|
|
|
|
|
|
|
|
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
|
|
|
|
|
2024-05-04 22:18:43 +03:00
|
|
|
int mod_etype(struct poolhd *pool, struct eval *val, int type);
|
2024-08-07 14:25:26 +03:00
|
|
|
|
|
|
|
#endif
|