From 5e326563b1a752674bb18c0c5bad804df32fa384 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 28 Mar 2019 15:26:33 +0100 Subject: [PATCH] Effectively support -h and -b --- src/algo_rr.c | 19 +++++++++++++++++-- src/donar_client.h | 2 +- src/donar_server.h | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/algo_rr.c b/src/algo_rr.c index 4728a2a..324b84a 100644 --- a/src/algo_rr.c +++ b/src/algo_rr.c @@ -18,6 +18,8 @@ struct deferred_pkt { }; struct rr_ctx { + uint8_t link_count; + uint8_t is_rdy; uint8_t my_links; uint16_t my_links_ver; uint8_t remote_links; @@ -26,6 +28,7 @@ struct rr_ctx { uint16_t recv_id_late; uint16_t sent_id; uint8_t current_link; + struct algo_params ap; struct timespec emit_time; struct deferred_pkt real[PACKET_BUFFER_SIZE]; struct waited_pkt wait[PACKET_BUFFER_SIZE]; @@ -367,7 +370,8 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { sprintf(url, "tcp:write:127.0.0.1:%d", 7500 + sel_link); //@FIXME Hardcoded to_fdinfo = evt_core_get_from_url (ctx, url); if (to_fdinfo == NULL) continue; // Missing link - if (rr->my_links & (1 << sel_link)) { + if (rr->ap.is_waiting_bootstrap && !rr->is_rdy) goto not_ready; // Some links are down + if (!rr->ap.is_healing || rr->my_links & (1 << sel_link)) { rr->current_link = sel_link; mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo); rr_on_tcp_write(ctx, to_fdinfo); @@ -378,8 +382,9 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { } } +not_ready: // 4. A whole packet has been read, we will find someone to write it - fprintf(stderr, "No fd for URL %s in udp-read. Dropping packet :( \n", fdinfo->url); + fprintf(stderr, "Still bootstrapping or no link to forward data from %s in udp-read. Dropping packet :( \n", fdinfo->url); mv_buffer_wtof (app_ctx, fdinfo); return 0; @@ -391,8 +396,15 @@ co_error: int rr_on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) { struct buffer_packet* bp; struct algo_ctx* app_ctx = fdinfo->cat->app_ctx; + struct rr_ctx* rr = app_ctx->misc; int write_res = FDS_READY; + // 0. Show some information about circuits + uint8_t is_rdy = fdinfo->cat->socklist->len >= rr->link_count ? 1 : 0; + if (!rr->is_rdy && is_rdy) printf("=== Our %d requested circuits are now up ===\n", rr->link_count); + else if (rr->is_rdy && !is_rdy) printf("=== Only %d/%d circuits are available, results could be biased ===\n", fdinfo->cat->socklist->len, rr->link_count); + rr->is_rdy = is_rdy; + // 1. Get current write buffer OR a buffer from the waiting queue OR leave if ((bp = get_write_buffer(app_ctx, fdinfo)) == NULL) return 1; @@ -494,6 +506,9 @@ void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params* rr->sent_id = 1; rr->recv_id = 0; rr->recv_id_late = 0; + rr->link_count = 8; + rr->is_rdy = 0; + rr->ap = *ap; ctx->misc = rr; for (int i = 0; i < sizeof(ctx->bps) / sizeof(ctx->bps[0]); i++) { g_queue_push_tail(ctx->free_buffer, &(ctx->bps[i])); diff --git a/src/donar_client.h b/src/donar_client.h index 4abfb03..4493aa4 100644 --- a/src/donar_client.h +++ b/src/donar_client.h @@ -7,7 +7,7 @@ #include "socks5.h" #include "donar_init.h" -#define CLIENT_PORT_SIZE 10 +#define CLIENT_PORT_SIZE 8 struct donar_client_ctx { struct tor_os_str tos; diff --git a/src/donar_server.h b/src/donar_server.h index 0e761da..94eb42d 100644 --- a/src/donar_server.h +++ b/src/donar_server.h @@ -11,7 +11,7 @@ #include "algo_skel.h" #include "donar_init.h" -#define PORT_SIZE 10 +#define PORT_SIZE 8 struct donar_server_ctx { struct tor_os_str tos;