Add probinh
This commit is contained in:
parent
fde2f63d0c
commit
009f80509c
9 changed files with 43 additions and 14 deletions
15
src/donar.c
15
src/donar.c
|
@ -16,8 +16,14 @@ int main(int argc, char** argv) {
|
|||
struct donar_params dp = {0};
|
||||
donar_init_params (&dp);
|
||||
|
||||
while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bl:d:f:i:p:t:")) != -1) {
|
||||
while ((dp.opt = getopt(argc, argv, "nvcse:r:o:a:bl:d:f:i:p:t:q:k:")) != -1) {
|
||||
switch(dp.opt) {
|
||||
case 'q':
|
||||
dp.tor_port = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
dp.base_port = atoi(optarg);
|
||||
break;
|
||||
case 'n':
|
||||
dp.tof |= TOR_ONION_FLAG_NON_ANONYMOUS;
|
||||
break;
|
||||
|
@ -73,8 +79,9 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
if (!(dp.is_server ^ dp.is_client)) goto in_error;
|
||||
if (dp.algo == NULL) goto in_error;
|
||||
if (dp.bound_ip == NULL) dp.bound_ip = strdup("127.0.0.1");
|
||||
if (dp.tor_port == NULL) dp.tor_port = dp.is_client ? "9050" : "9051";
|
||||
if (dp.algo == NULL) goto in_error;
|
||||
|
||||
if (dp.is_server) {
|
||||
struct donar_server_ctx ctx;
|
||||
|
@ -91,8 +98,8 @@ in_error:
|
|||
dp.errored = 1;
|
||||
fprintf(stderr, "Usage as client : %s -c -a <algo> -o <onion service file> [-h] [-b] [-i <bound ip>] [-f <dump packets>] [-l <links>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n", argv[0]);
|
||||
fprintf(stderr, "Usage as server : %s -s -a <algo> [-h] [-b] [-n] [-i <bound ip>] [-l <links>] [-f <dump_packets>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n\n", argv[0]);
|
||||
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, exposed_ports=%d, remote_ports=%d, 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.onion_file, dp.links, dp.fresh_data, dp.redundant_data);
|
||||
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);
|
||||
|
||||
terminate:
|
||||
// @FIXME: Should be refactored in free_donar_params()
|
||||
|
|
|
@ -13,8 +13,8 @@ void init_socks5_client(struct donar_client_ctx* app_ctx, int pos) {
|
|||
}
|
||||
sprintf(target_host, "%s.onion", app_ctx->tos.keys[0].pub);
|
||||
|
||||
app_ctx->ports[pos] = 7500 + pos;
|
||||
socks5_create_dns_client (&app_ctx->evts, app_ctx->tor_ip, "9050", target_host, app_ctx->ports[pos]);
|
||||
app_ctx->ports[pos] = app_ctx->base_port + pos;
|
||||
socks5_create_dns_client (&app_ctx->evts, app_ctx->tor_ip, app_ctx->tor_port, target_host, app_ctx->ports[pos]);
|
||||
}
|
||||
|
||||
int on_socks5_success(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||
|
@ -136,6 +136,9 @@ void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) {
|
|||
.sr = donar_client_stream_repair
|
||||
};
|
||||
ctx->tor_ip = dp->tor_ip;
|
||||
ctx->tor_port = dp->tor_port;
|
||||
ctx->base_port = dp->base_port;
|
||||
|
||||
|
||||
evt_core_init (&(ctx->evts), dp->verbose);
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ struct donar_client_ctx {
|
|||
struct tor_os_str tos;
|
||||
struct evt_core_ctx evts;
|
||||
char *tor_ip;
|
||||
char *tor_port;
|
||||
uint16_t base_port;
|
||||
uint16_t ports[CLIENT_PORT_SIZE];
|
||||
struct {
|
||||
int fd;
|
||||
|
|
|
@ -158,6 +158,7 @@ void donar_init_params(struct donar_params* dp) {
|
|||
dp->links = 8;
|
||||
dp->fresh_data = 1;
|
||||
dp->redundant_data = 0;
|
||||
dp->base_port = 7500;
|
||||
strcpy(dp->tor_ip, "127.0.0.1");
|
||||
strcpy(dp->my_ip_for_tor, "127.13.3.7");
|
||||
dp->remote_ports = g_ptr_array_new_with_free_func (free_port);
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include "tor_ctl.h"
|
||||
|
||||
struct donar_params {
|
||||
int opt, is_server, is_client, is_waiting_bootstrap, errored, verbose, links, fresh_data, redundant_data;
|
||||
char *bound_ip, *port, *onion_file, *algo, *capture_file, *algo_specific_params, tor_ip[16], my_ip_for_tor[16];
|
||||
int opt, is_server, is_client, is_waiting_bootstrap, errored, verbose, links, fresh_data, redundant_data, base_port;
|
||||
char *bound_ip, *port, *onion_file, *algo, *capture_file, *algo_specific_params, tor_ip[16], my_ip_for_tor[16], *tor_port;
|
||||
GPtrArray *remote_ports, *exposed_ports;
|
||||
enum TOR_ONION_FLAGS tof;
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "donar_server.h"
|
||||
|
||||
void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, char* tor_ip, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) {
|
||||
void create_onion_services(struct tor_os_str* tos, struct tor_ctl* tctl, char* tor_ip, char *tor_port, uint16_t* ports, int ports_count, enum TOR_ONION_FLAGS tof) {
|
||||
tor_os_create (tos, "onion_services.pub", "onion_services.txt", 1);
|
||||
tor_os_read (tos);
|
||||
|
||||
int err = 0;
|
||||
err = tor_ctl_connect (tctl, tor_ip, "9051");
|
||||
err = tor_ctl_connect (tctl, tor_ip, tor_port);
|
||||
if (err < 0) {
|
||||
fprintf(stderr, "Unable to open Tor Socket\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -117,14 +117,14 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
|
|||
printf("--- Algorithm initialized\n");
|
||||
|
||||
for (uint16_t i = 0; i < dp->links ; i++) {
|
||||
ctx->ports[i] = 7500 + i;
|
||||
ctx->ports[i] = dp->base_port + i;
|
||||
}
|
||||
|
||||
init_tcp_servers(ctx, dp->links);
|
||||
printf("--- TCP servers are listening\n");
|
||||
|
||||
ctx->tctl.os_endpoint = dp->my_ip_for_tor;
|
||||
create_onion_services (&(ctx->tos), &(ctx->tctl), dp->tor_ip, 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);
|
||||
/*struct donar_server_os_republish_params dsorp = { .dctx = ctx, dp = dp};
|
||||
init_timer(&(ctx->evts));
|
||||
|
|
|
@ -154,11 +154,21 @@ int on_receive_measure_packet(struct evt_core_ctx* ctx, struct evt_core_fdinfo*
|
|||
// 4. Persist our measurement object if needed
|
||||
// It includes starting a timer.
|
||||
if (ms == &ms_transi) {
|
||||
if (ms->mp_in->counter != 1) {
|
||||
if (ms->mp_in->counter != 1) { // Guard against rando scanning the IPv4 range
|
||||
if (!(mctx->connectionless && mctx->role == MEASLAT_SERVER))
|
||||
evt_core_rm_fd (ctx, fdinfo->fd);
|
||||
return 1;
|
||||
}
|
||||
if (ms->mp_in->probe) { // Allow for probing without registering a timer
|
||||
int s = mctx->connectionless && mctx->role == MEASLAT_SERVER ?
|
||||
sendto(ms->fd, ms->mp_in, mctx->mp.payload_size, 0, (struct sockaddr*)&mctx->addr, mctx->addrlen) :
|
||||
send(ms->fd, ms->mp_in, mctx->mp.payload_size, 0);
|
||||
|
||||
if (!(mctx->connectionless && mctx->role == MEASLAT_SERVER))
|
||||
evt_core_rm_fd (ctx, fdinfo->fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
struct timespec next_tick = {0};
|
||||
struct measure_state ms_new = {0};
|
||||
measure_state_init(&mctx->mp, &ms_new);
|
||||
|
@ -495,8 +505,10 @@ int main(int argc, char** argv) {
|
|||
measure_params_init (&mctx.mp);
|
||||
|
||||
// 1. Parse parameters
|
||||
while ((opt = getopt(argc, argv, "vq:h:p:c:s:i:t:lnm:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "vq:h:p:c:s:i:t:lnm:b")) != -1) {
|
||||
switch(opt) {
|
||||
case 'b':
|
||||
mctx.mp.probe = 1;
|
||||
case 'v':
|
||||
mctx.verbose++;
|
||||
break;
|
||||
|
@ -539,6 +551,7 @@ int main(int argc, char** argv) {
|
|||
measure_state_init (&mctx.mp, &ms_transi);
|
||||
|
||||
mctx.addrlen = sizeof(mctx.addr);
|
||||
if (mctx.mp.probe) mctx.mp.max_measure = 1;
|
||||
if (mctx.transport == NULL) mctx.transport = "udp";
|
||||
if (strcmp(mctx.transport, "udp") == 0) mctx.connectionless = 1;
|
||||
if (mctx.host == NULL) mctx.host = "127.0.0.1";
|
||||
|
|
|
@ -44,6 +44,7 @@ void measure_state_init(struct measure_params* mp, struct measure_state* ms) {
|
|||
}
|
||||
memset(ms->mp_in, 0, mp->payload_size);
|
||||
|
||||
ms->mp_out->probe = mp->probe;
|
||||
char *my_msg = "Tu n'es pas tout a fait la misere,\nCar les levres les plus pauvres te denoncent\nPar un sourire.";
|
||||
size_t msg_len = strlen(my_msg);
|
||||
size_t cursor_msg = 0;
|
||||
|
|
|
@ -11,6 +11,7 @@ struct measure_params {
|
|||
uint64_t max_measure;
|
||||
uint64_t payload_size;
|
||||
uint64_t interval;
|
||||
uint8_t probe;
|
||||
uint8_t is_server;
|
||||
char* tag;
|
||||
};
|
||||
|
@ -28,6 +29,7 @@ struct measure_state {
|
|||
struct measure_packet {
|
||||
uint64_t counter;
|
||||
uint8_t flag;
|
||||
uint8_t probe;
|
||||
struct timespec emit_time;
|
||||
};
|
||||
#pragma pack()
|
||||
|
|
Loading…
Reference in a new issue