Find alternative WIP

This commit is contained in:
Quentin 2020-02-24 19:46:30 +01:00
parent c3f99c35a9
commit 50e2cf4ccc

View file

@ -81,8 +81,15 @@ int faketor_socks5_server_failed(struct evt_core_ctx* ctx, struct evt_core_fdinf
int faketor_ctos(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
char buffer[1600];
ssize_t nread, nwrite;
size_t skip = strlen("socket:");
size_t skip_socket = strlen("socket:"), skip_torctl = strlen("torctl:");
char url[512];
struct evt_core_fdinfo *target, *source;
// 0. find source
if (strstr(fdinfo->url, "socket:") != NULL) target = fdinfo;
else {
sprintf(url, "socket:%s", fdinfo->url);
}
// 1. read some data
nread = recv(fdinfo->fd, buffer, sizeof(buffer), MSG_PEEK);
@ -90,12 +97,12 @@ int faketor_ctos(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
if (nread == -1) goto error;
// 2. find target
sprintf(url, "torctl:%s:write", fdinfo->url + skip);
sprintf(url, "torctl:%s:write", fdinfo->url + skip_socket);
printf("source url: %s, target url: %s", fdinfo->url, url);
struct evt_core_fdinfo *target = evt_core_get_from_url (ctx, url);
target = evt_core_get_from_url (ctx, url);
// 3. write to target
nwrite = send(fdinfo->fd, buffer, nread, 0);
nwrite = send(target->fd, buffer, nread, 0);
if (nwrite == -1 && errno == EAGAIN) return EVT_CORE_FD_EXHAUSTED;
if (nwrite == -1) goto error;
nread = recv(fdinfo->fd, buffer, nwrite, 0);