85 lines
2.1 KiB
C
85 lines
2.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include "evt_core.h"
|
||
|
#include "socks5.h"
|
||
|
|
||
|
int faketor_socks5_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||
|
int conn_sock1;
|
||
|
struct sockaddr_in addr;
|
||
|
socklen_t in_len;
|
||
|
|
||
|
in_len = sizeof(addr);
|
||
|
conn_sock1 = accept(fdinfo->fd, (struct sockaddr*)&addr, &in_len);
|
||
|
|
||
|
if (conn_sock1 == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
|
||
|
if (conn_sock1 == -1) goto co_error;
|
||
|
|
||
|
|
||
|
printf("[%s][torfake] Accepted a new connection for socks5 \n", current_human_datetime ());
|
||
|
|
||
|
return EVT_CORE_FD_UNFINISHED;
|
||
|
co_error:
|
||
|
perror("Failed to handle new connection");
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
|
||
|
int faketor_control_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||
|
|
||
|
return EVT_CORE_FD_UNFINISHED;
|
||
|
}
|
||
|
|
||
|
int main(void) {
|
||
|
struct evt_core_ctx evts = {0};
|
||
|
|
||
|
struct evt_core_cat socks5_listen = {
|
||
|
.app_ctx = NULL,
|
||
|
.free_app_ctx = NULL,
|
||
|
.cb = faketor_socks5_listen,
|
||
|
.err_cb = NULL,
|
||
|
.name = "socks5-listen",
|
||
|
.flags = EPOLLIN | EPOLLET,
|
||
|
.socklist = NULL
|
||
|
};
|
||
|
|
||
|
struct evt_core_cat control_listen = {
|
||
|
.app_ctx = NULL,
|
||
|
.free_app_ctx = NULL,
|
||
|
.cb = faketor_control_listen,
|
||
|
.err_cb = NULL,
|
||
|
.name = "control-listen",
|
||
|
.flags = EPOLLIN | EPOLLET,
|
||
|
.socklist = NULL
|
||
|
};
|
||
|
|
||
|
evt_core_init(&evts, 0);
|
||
|
evt_core_add_cat(&evts, &socks5_listen);
|
||
|
evt_core_add_cat(&evts, &control_listen);
|
||
|
|
||
|
struct evt_core_cat cat = {0};
|
||
|
struct evt_core_fdinfo fdinfo = {0};
|
||
|
fdinfo.cat = &cat;
|
||
|
int err, sock = 0;
|
||
|
|
||
|
sock = create_tcp_server ("0.0.0.0", "9050");
|
||
|
if (sock < 0) return EXIT_FAILURE;
|
||
|
err = listen(sock, SOMAXCONN);
|
||
|
if (err != 0) return EXIT_FAILURE;
|
||
|
fdinfo.cat->name = "socks5-listen";
|
||
|
fdinfo.fd = sock;
|
||
|
fdinfo.url = "socks5:listen:9050";
|
||
|
evt_core_add_fd(&evts, &fdinfo);
|
||
|
|
||
|
sock = create_tcp_server ("0.0.0.0", "9051");
|
||
|
if (sock < 0) return EXIT_FAILURE;
|
||
|
err = listen(sock, SOMAXCONN);
|
||
|
if (err != 0) return EXIT_FAILURE;
|
||
|
fdinfo.cat->name = "control-listen";
|
||
|
fdinfo.fd = sock;
|
||
|
fdinfo.url = "control:listen:9051";
|
||
|
evt_core_add_fd(&evts, &fdinfo);
|
||
|
|
||
|
socks5_server_init(&evts);
|
||
|
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|