Effectively support -h and -b
This commit is contained in:
parent
b9d7ec48a2
commit
5e326563b1
3 changed files with 19 additions and 4 deletions
|
@ -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]));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue