This commit is contained in:
Quentin 2021-01-27 16:44:15 +01:00
parent 009f80509c
commit 1262d08278
7 changed files with 106 additions and 31 deletions

83
scripts/2021/torfone Executable file
View file

@ -0,0 +1,83 @@
#!/bin/bash
SOCK_PORT=$((9000+$1))
CONTROL_PORT=$((9100+$1))
LOCAL_PORT=$((9200+$1))
DONAR_PORT=$((7000+$1*12))
touch /tmp/empty
echo "tor daemon serv"
/usr/bin/tor \
-f /tmp/empty --defaults-torrc /tmp/empty \
--hush \
--UseEntryGuards 0 \
--SocksPort 0 \
--ControlPort $CONTROL_PORT \
--DataDirectory /tmp/tor$CONTROL_PORT &
sleep 1
echo "tor client serv"
/usr/bin/tor \
-f /tmp/empty --defaults-torrc /tmp/empty \
--hush \
--UseEntryGuards 0 \
--SocksPort "127.0.0.1:$SOCK_PORT IsolateDestPort IsolateDestAddr IsolateClientAddr" \
--DataDirectory /tmp/tor$SOCK_PORT &
sleep 1
echo "donar serv"
rm -rf state_$LOCAL_PORT/
mkdir state_$LOCAL_PORT/
pushd .
cd state_$LOCAL_PORT/
/usr/local/bin/donar \
-s \
-a dup2 \
-q $CONTROL_PORT \
-k $DONAR_PORT \
-l 2 \
-e $LOCAL_PORT &
sleep 1
echo "donar client"
/usr/local/bin/donar \
-c \
-a dup2 \
-q $SOCK_PORT \
-k $DONAR_PORT \
-o ./onion_services.pub \
-l 2 \
-r $LOCAL_PORT &
sleep 1
popd
echo "measlat serv"
/usr/local/bin/measlat \
-l \
-t udp \
-h 127.0.0.1 \
-p $LOCAL_PORT \
-c 135 \
-i 40 \
-s 172 &
sleep 1
echo "measlat client bootstrap"
/usr/local/bin/measlat \
-t udp \
-h 127.13.3.7 \
-p $LOCAL_PORT \
-b \
-c 1 \
-i 1000 \
-s 172
echo "measlat client collect"
/usr/local/bin/measlat \
-t udp \
-h 127.13.3.7 \
-p $LOCAL_PORT \
-c 135 \
-i 40 \
-s 172

View file

@ -83,6 +83,10 @@ int main(int argc, char** argv) {
if (dp.tor_port == NULL) dp.tor_port = dp.is_client ? "9050" : "9051"; if (dp.tor_port == NULL) dp.tor_port = dp.is_client ? "9050" : "9051";
if (dp.algo == NULL) goto in_error; if (dp.algo == NULL) goto in_error;
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, exposed_ports=%d, remote_ports=%d, transfer_base_port=%d, tor_daemon_port=%s, onion_file=%s, links=%d, duplication=%d,%d\n",
dp.is_client, dp.is_server, dp.algo, dp.exposed_ports->len, dp.remote_ports->len, dp.base_port, dp.tor_port, dp.onion_file, dp.links, dp.fresh_data, dp.redundant_data);
if (dp.is_server) { if (dp.is_server) {
struct donar_server_ctx ctx; struct donar_server_ctx ctx;
if (dp.exposed_ports->len < 1 && dp.remote_ports->len < 1) goto in_error; if (dp.exposed_ports->len < 1 && dp.remote_ports->len < 1) goto in_error;

View file

@ -53,7 +53,7 @@ enum DONAR_TIMER_DECISION reinit_socks5(struct evt_core_ctx* ctx, void* user_dat
struct donar_client_ctx* app_ctx = cat->app_ctx; struct donar_client_ctx* app_ctx = cat->app_ctx;
int64_t pos = (int64_t) user_data; // trust me... int64_t pos = (int64_t) user_data; // trust me...
fprintf(stdout, "[%s][donar-client] We have waited enough, retriggering socks5 for port %ld\n", current_human_datetime (), pos+7500); fprintf(stdout, "[%s][donar-client] We have waited enough, retriggering socks5 for port %ld\n", current_human_datetime (), app_ctx->base_port+pos);
init_socks5_client (app_ctx, pos); init_socks5_client (app_ctx, pos);
return DONAR_TIMER_STOP; return DONAR_TIMER_STOP;
} }
@ -62,7 +62,7 @@ int on_socks5_failed(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
struct donar_client_ctx* app_ctx = fdinfo->cat->app_ctx; struct donar_client_ctx* app_ctx = fdinfo->cat->app_ctx;
struct socks5_ctx* s5ctx = fdinfo->other; struct socks5_ctx* s5ctx = fdinfo->other;
int64_t pos = 0; int64_t pos = 0;
pos = s5ctx->port - 7500; pos = s5ctx->port - app_ctx->base_port;
int64_t to_wait_sec = 30 + pos*3; int64_t to_wait_sec = 30 + pos*3;
fprintf(stdout, "[%s][donar-client] Retriggering socks5 in %ld seconds for port %d\n", current_human_datetime (), to_wait_sec, s5ctx->port); fprintf(stdout, "[%s][donar-client] Retriggering socks5 in %ld seconds for port %d\n", current_human_datetime (), to_wait_sec, s5ctx->port);
@ -88,11 +88,18 @@ void init_socks5_sinks(struct donar_client_ctx* app_ctx) {
} }
int donar_client_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { int donar_client_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "socks5-failed");
if (cat == NULL) {
fprintf(stderr, "Unable to reconnect stream as socks5-failed cat is not available...\n");
exit(EXIT_FAILURE);
}
struct donar_client_ctx* app_ctx = cat->app_ctx;
fprintf(stdout, "[%s][donar-client] %s broke\n", current_human_datetime (), fdinfo->url); fprintf(stdout, "[%s][donar-client] %s broke\n", current_human_datetime (), fdinfo->url);
struct evt_core_fdinfo* fdtarget = NULL; struct evt_core_fdinfo* fdtarget = NULL;
int port = url_get_port_int (fdinfo->url); int port = url_get_port_int (fdinfo->url);
int64_t pos = 0, removed = 0; int64_t pos = 0, removed = 0;
pos = port - 7500; pos = port - app_ctx->base_port;
char buffer[256]; char buffer[256];
sprintf(buffer, "tcp:read:127.0.0.1:%d", port); sprintf(buffer, "tcp:read:127.0.0.1:%d", port);
@ -160,7 +167,7 @@ void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) {
for (int64_t i = 0; i < dp->links; i++) { for (int64_t i = 0; i < dp->links; i++) {
int64_t to_wait_sec = i * 3; int64_t to_wait_sec = i * 3;
fprintf(stdout, "[%s][donar-client] Triggering socks5 in %ld seconds for port %ld\n", current_human_datetime (), to_wait_sec, i+7500); fprintf(stdout, "[%s][donar-client] Triggering socks5 in %ld seconds for port %ld\n", current_human_datetime (), to_wait_sec, i+dp->base_port);
set_timeout(&ctx->evts, 1000 * to_wait_sec, (void*) i, reinit_socks5); set_timeout(&ctx->evts, 1000 * to_wait_sec, (void*) i, reinit_socks5);
} }
printf("--- TCP Clients Connected\n"); printf("--- TCP Clients Connected\n");

View file

@ -57,7 +57,7 @@ int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
struct evt_core_fdinfo* fdtarget = NULL; struct evt_core_fdinfo* fdtarget = NULL;
int port = url_get_port_int (fdinfo->url); int port = url_get_port_int (fdinfo->url);
int pos = port - 7500, removed = 0; int removed = 0;
char buffer[256]; char buffer[256];
sprintf(buffer, "tcp:read:127.0.0.1:%d", port); sprintf(buffer, "tcp:read:127.0.0.1:%d", port);
@ -78,24 +78,6 @@ int donar_server_stream_repair(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
return 1; return 1;
} }
struct donar_server_os_republish_params {
struct donar_server_ctx* dctx;
struct donar_params* dp;
};
/*
void republish_tor_os(struct evt_core_ctx* ctx, void* user_data) {
struct donar_server_os_republish_params* dsorp = user_data;
int err = 0;
printf("Republish Tor OS\n");
err = tor_ctl_add_onion (&dsorp->dctx->tctl, &dsorp->dctx->tos, dsorp->dctx->ports, dsorp->dp->tof);
if (err != 0) {
fprintf(stderr, "Unable to create Onion Services (error: %d)\n", err);
exit(EXIT_FAILURE);
}
printf("Republish Tor OS\n");
}*/
void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) { void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
struct algo_params ap = { struct algo_params ap = {
.is_waiting_bootstrap = dp->is_waiting_bootstrap, .is_waiting_bootstrap = dp->is_waiting_bootstrap,
@ -126,9 +108,6 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
ctx->tctl.os_endpoint = dp->my_ip_for_tor; ctx->tctl.os_endpoint = dp->my_ip_for_tor;
create_onion_services (&(ctx->tos), &(ctx->tctl), dp->tor_ip, dp->tor_port, ctx->ports, dp->links, dp->tof); create_onion_services (&(ctx->tos), &(ctx->tctl), dp->tor_ip, dp->tor_port, ctx->ports, dp->links, dp->tof);
ugly_global_tctl = &(ctx->tctl); ugly_global_tctl = &(ctx->tctl);
/*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp};
init_timer(&(ctx->evts));
set_timeout(&(ctx->evts), 1000, &dsorp, republish_tor_os); */
printf("--- Onion services created\n"); printf("--- Onion services created\n");
g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts)); g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts));

View file

@ -38,6 +38,8 @@ void evt_core_init(struct evt_core_ctx* ctx, uint8_t verbose) {
} }
ctx->verbose = verbose; ctx->verbose = verbose;
ctx->loop = 1; ctx->loop = 1;
ctx->blacklisted_fds_count = 0;
memset(ctx->blacklisted_fds, 0, EVT_CORE_MAX_EVENTS*sizeof(int));
ctx->catlist = g_hash_table_new_full(g_str_hash, g_str_equal,NULL, free_cat); ctx->catlist = g_hash_table_new_full(g_str_hash, g_str_equal,NULL, free_cat);
ctx->socklist = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free_fdinfo); ctx->socklist = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, free_fdinfo);
ctx->urltofd = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); ctx->urltofd = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);

View file

@ -89,15 +89,15 @@ int on_receive_measure_packet_err(struct evt_core_ctx* ctx, struct evt_core_fdin
sprintf(url, "timer:%d", fdinfo->fd); sprintf(url, "timer:%d", fdinfo->fd);
struct evt_core_fdinfo* assoc_timer = evt_core_get_from_url (ctx, url); struct evt_core_fdinfo* assoc_timer = evt_core_get_from_url (ctx, url);
if (assoc_timer != NULL) { if (assoc_timer != NULL && !mctx->mp.probe && !mctx->connectionless) {
if (mctx->role == MEASLAT_CLIENT) measure_summary (&mctx->mp, assoc_timer->other); if (mctx->role == MEASLAT_CLIENT && !mctx->mp.probe) measure_summary (&mctx->mp, assoc_timer->other);
evt_core_rm_fd (ctx, assoc_timer->fd); evt_core_rm_fd (ctx, assoc_timer->fd);
printf("Deleted associated timer %s\n", url); printf("Deleted associated timer %s\n", url);
} else { } else {
printf("No associated timer %s\n", url); printf("No associated timer %s\n", url);
} }
if (mctx->role == MEASLAT_CLIENT) exit(EXIT_FAILURE); if (mctx->role == MEASLAT_CLIENT && !mctx->mp.probe) exit(EXIT_FAILURE);
if (mctx->connectionless) return 1; // keep the NET FD if (mctx->connectionless) return 1; // keep the NET FD
else return 0; // delete the NET fd else return 0; // delete the NET fd
@ -111,7 +111,7 @@ void measlat_stop(
if (ms->mp_in->counter < mctx->mp.max_measure) return; if (ms->mp_in->counter < mctx->mp.max_measure) return;
if (ms->mp_out->counter < mctx->mp.max_measure) return; if (ms->mp_out->counter < mctx->mp.max_measure) return;
printf("[states] measurement %d+%d terminated\n", net_fd, timer_fd); printf("[states] measurement %d+%d terminated\n", net_fd, timer_fd);
if (mctx->role == MEASLAT_CLIENT) measure_summary (&(mctx->mp), ms); if (mctx->role == MEASLAT_CLIENT && !mctx->mp.probe) measure_summary (&(mctx->mp), ms);
evt_core_rm_fd(ctx, timer_fd); evt_core_rm_fd(ctx, timer_fd);
if (!(mctx->connectionless && mctx->role == MEASLAT_SERVER)) if (!(mctx->connectionless && mctx->role == MEASLAT_SERVER))
evt_core_rm_fd(ctx, net_fd); evt_core_rm_fd(ctx, net_fd);

View file

@ -93,7 +93,7 @@ int create_ip_server(char* host, char* service, int type) {
} }
if (cursor == NULL) { if (cursor == NULL) {
fprintf(stderr, "We failed to create socket or bind\n"); fprintf(stderr, "We failed to create socket or bind for %s:%s (%d)\n", host, service, type);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }