Update repair logic

This commit is contained in:
Quentin 2020-01-23 20:04:33 +01:00
parent ea35a8dd93
commit 020c342fb1
2 changed files with 25 additions and 5 deletions

View file

@ -101,10 +101,10 @@ int donar_client_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
if (removed == 2) {
fprintf(stdout, "[%s][donar-client] Retriggering socks5 for port %d\n", current_human_datetime (), port);
init_socks5_client (app_ctx, pos);
return 0;
return 1;
} else if (removed == 0) {
fprintf(stdout, "[%s][donar-client] Socks5 has already been retriggered for port %d\n", current_human_datetime (), port);
return 0;
return 1;
} else {
fprintf(stderr, "[%s][donar-client] We only removed 1 link and not 2 for port %d, strange behaviour, exiting...\n", current_human_datetime (), port);
exit(EXIT_FAILURE);

View file

@ -52,9 +52,29 @@ socket_create_err:
}
struct tor_ctl* ugly_global_tctl;
int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fd) {
fprintf(stderr, "[%s][donar-server] I am a server, I do nothing with broken streams...\n", current_human_datetime ());
/* tor_ctl_list_onions(ugly_global_tctl); */
int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
fprintf(stdout, "[%s][donar-server] %s broke\n", current_human_datetime (), fdinfo->url);
struct evt_core_fdinfo* fdtarget = NULL;
int port = url_get_port_int (fdinfo->url);
int pos = port - 7500, removed = 0;
char buffer[256];
sprintf(buffer, "tcp:read:127.0.0.1:%d", port);
fdtarget = evt_core_get_from_url (ctx, buffer);
if (fdtarget != NULL) {
evt_core_rm_fd(ctx, fdtarget->fd);
removed++;
}
sprintf(buffer, "tcp:write:127.0.0.1:%d", port);
fdtarget = evt_core_get_from_url (ctx, buffer);
if (fdtarget != NULL) {
evt_core_rm_fd(ctx, fdtarget->fd);
removed++;
}
printf("[%s][donar-server] removed %d links\n", current_human_datetime (), removed);
return 1;
}