Successful socks5 server!
This commit is contained in:
parent
00e37ceb88
commit
b648e58863
2 changed files with 41 additions and 4 deletions
|
@ -16,6 +16,7 @@ int faketor_socks5_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
|
||||||
|
|
||||||
|
|
||||||
printf("[%s][torfake] Accepted a new connection for socks5 \n", current_human_datetime ());
|
printf("[%s][torfake] Accepted a new connection for socks5 \n", current_human_datetime ());
|
||||||
|
socks5_server_handle_req (ctx, conn_sock1);
|
||||||
|
|
||||||
return EVT_CORE_FD_UNFINISHED;
|
return EVT_CORE_FD_UNFINISHED;
|
||||||
co_error:
|
co_error:
|
||||||
|
@ -28,6 +29,17 @@ int faketor_control_listen(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdi
|
||||||
return EVT_CORE_FD_UNFINISHED;
|
return EVT_CORE_FD_UNFINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int faketor_socks5_server_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
|
printf("success!\n");
|
||||||
|
|
||||||
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int faketor_socks5_server_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
|
printf("failure!\n");
|
||||||
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
struct evt_core_ctx evts = {0};
|
struct evt_core_ctx evts = {0};
|
||||||
|
|
||||||
|
@ -51,9 +63,32 @@ int main(void) {
|
||||||
.socklist = NULL
|
.socklist = NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct evt_core_cat socks5_server_success = {
|
||||||
|
.app_ctx = NULL,
|
||||||
|
.free_app_ctx = NULL,
|
||||||
|
.cb = faketor_socks5_server_success,
|
||||||
|
.err_cb = NULL,
|
||||||
|
.name = "socks5-server-success",
|
||||||
|
.flags = EPOLLIN | EPOLLET,
|
||||||
|
.socklist = NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
struct evt_core_cat socks5_server_failed = {
|
||||||
|
.app_ctx = NULL,
|
||||||
|
.free_app_ctx = NULL,
|
||||||
|
.cb = faketor_socks5_server_failed,
|
||||||
|
.err_cb = NULL,
|
||||||
|
.name = "socks5-server-failed",
|
||||||
|
.flags = EPOLLIN | EPOLLET,
|
||||||
|
.socklist = NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
evt_core_init(&evts, 0);
|
evt_core_init(&evts, 0);
|
||||||
evt_core_add_cat(&evts, &socks5_listen);
|
evt_core_add_cat(&evts, &socks5_listen);
|
||||||
evt_core_add_cat(&evts, &control_listen);
|
evt_core_add_cat(&evts, &control_listen);
|
||||||
|
evt_core_add_cat(&evts, &socks5_server_success);
|
||||||
|
evt_core_add_cat(&evts, &socks5_server_failed);
|
||||||
|
|
||||||
struct evt_core_cat cat = {0};
|
struct evt_core_cat cat = {0};
|
||||||
struct evt_core_fdinfo fdinfo = {0};
|
struct evt_core_fdinfo fdinfo = {0};
|
||||||
|
@ -80,5 +115,7 @@ int main(void) {
|
||||||
|
|
||||||
socks5_server_init(&evts);
|
socks5_server_init(&evts);
|
||||||
|
|
||||||
|
evt_core_loop (&evts);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -398,7 +398,7 @@ int on_socks5_server_recv_handshake(struct evt_core_ctx* ctx, struct evt_core_fd
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
|
||||||
success:
|
success:
|
||||||
printf("[%s][socks5] received client handshake handshake\n", current_human_datetime ());
|
printf("[%s][socks5] received client handshake\n", current_human_datetime ());
|
||||||
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-send-handshake");
|
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-send-handshake");
|
||||||
return EVT_CORE_FD_EXHAUSTED; // Success, we are compatible with client, moving to next state
|
return EVT_CORE_FD_EXHAUSTED; // Success, we are compatible with client, moving to next state
|
||||||
|
|
||||||
|
@ -477,14 +477,14 @@ int on_socks5_server_recv_client_req(struct evt_core_ctx* ctx, struct evt_core_f
|
||||||
} else return EVT_CORE_FD_UNFINISHED;
|
} else return EVT_CORE_FD_UNFINISHED;
|
||||||
} else if (!s5ctx->cr_host_read) goto recv_client_req_error;
|
} else if (!s5ctx->cr_host_read) goto recv_client_req_error;
|
||||||
|
|
||||||
to_read = ((void*)&s5ctx->cr+1) - ((void*)&s5ctx->cr.port) - s5ctx->cr_cursor;
|
to_read = (void*)(&s5ctx->cr + 1) - ((void*)&s5ctx->cr.port) - s5ctx->cr_cursor;
|
||||||
nread = recv(fdinfo->fd, ((void*)&s5ctx->cr.port) + s5ctx->cr_cursor, to_read, 0);
|
nread = recv(fdinfo->fd, ((void*)&s5ctx->cr.port) + s5ctx->cr_cursor, to_read, 0);
|
||||||
if (nread == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
|
if (nread == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
|
||||||
if (nread == -1) goto recv_client_req_error;
|
if (nread == -1) goto recv_client_req_error;
|
||||||
s5ctx->cr_cursor += nread;
|
s5ctx->cr_cursor += nread;
|
||||||
if (to_read != nread) return EVT_CORE_FD_UNFINISHED;
|
if (to_read != nread) return EVT_CORE_FD_UNFINISHED;
|
||||||
|
|
||||||
printf("[%s][socks5] received client request atyp=%s: ", current_human_datetime (), atyp_str[s5ctx->cr.atyp]);
|
printf("[%s][socks5] received client request atyp=%s\n", current_human_datetime (), atyp_str[s5ctx->cr.atyp]);
|
||||||
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-send-server-reply");
|
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-send-server-reply");
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
|
||||||
|
@ -507,7 +507,7 @@ int on_socks5_server_send_server_reply(struct evt_core_ctx* ctx, struct evt_core
|
||||||
if (nsent != to_send) return EVT_CORE_FD_UNFINISHED;
|
if (nsent != to_send) return EVT_CORE_FD_UNFINISHED;
|
||||||
|
|
||||||
printf("[%s][socks5] sent server reply\n", current_human_datetime ());
|
printf("[%s][socks5] sent server reply\n", current_human_datetime ());
|
||||||
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-sucess");
|
evt_core_mv_fd2 (ctx, fdinfo, "socks5-server-success");
|
||||||
return EVT_CORE_FD_EXHAUSTED;
|
return EVT_CORE_FD_EXHAUSTED;
|
||||||
|
|
||||||
send_server_rep_error:
|
send_server_rep_error:
|
||||||
|
|
Loading…
Reference in a new issue