Inform users that circuit is up on naive
This commit is contained in:
parent
044989b8d5
commit
347ea4f6cd
5 changed files with 25 additions and 19 deletions
|
@ -86,6 +86,11 @@ int on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||
int write_res = FDS_READY;
|
||||
|
||||
if (!app_ctx->is_rdy && strcmp(fdinfo->url, "tcp:write:127.0.0.1:7500") == 0) {
|
||||
app_ctx->is_rdy = 1;
|
||||
printf("=== Requested circuit is up ===\n");
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
|
@ -203,6 +208,8 @@ void algo_naive(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_para
|
|||
ctx->application_waiting = g_hash_table_new (NULL, NULL);
|
||||
ctx->used_buffer = g_hash_table_new(g_int_hash, g_int_equal);
|
||||
ctx->write_waiting = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, naive_free_simple);
|
||||
ctx->ap = *ap;
|
||||
ctx->is_rdy = 0;
|
||||
for (int i = 0; i < sizeof(ctx->bps) / sizeof(ctx->bps[0]); i++) {
|
||||
g_queue_push_tail(ctx->free_buffer, &(ctx->bps[i]));
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ 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;
|
||||
|
@ -28,7 +26,6 @@ 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];
|
||||
|
@ -370,8 +367,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->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)) {
|
||||
if (app_ctx->ap.is_waiting_bootstrap && !app_ctx->is_rdy) goto not_ready; // Some links are down
|
||||
if (!app_ctx->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);
|
||||
|
@ -400,10 +397,10 @@ int rr_on_tcp_write(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|||
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;
|
||||
uint8_t is_rdy = fdinfo->cat->socklist->len >= app_ctx->link_count ? 1 : 0;
|
||||
if (!app_ctx->is_rdy && is_rdy) printf("=== Our %d requested circuits are now up ===\n", app_ctx->link_count);
|
||||
else if (app_ctx->is_rdy && !is_rdy) printf("=== Only %d/%d circuits are available, results could be biased ===\n", fdinfo->cat->socklist->len, app_ctx->link_count);
|
||||
app_ctx->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;
|
||||
|
@ -497,6 +494,9 @@ void algo_rr(struct evt_core_ctx* evt, struct algo_skel* as, struct algo_params*
|
|||
ctx->application_waiting = g_hash_table_new (NULL, NULL);
|
||||
ctx->used_buffer = g_hash_table_new(g_int_hash, g_int_equal);
|
||||
ctx->write_waiting = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, naive_free_simple);
|
||||
ctx->link_count = 8;
|
||||
ctx->is_rdy = 0;
|
||||
ctx->ap = *ap;
|
||||
struct rr_ctx* rr = malloc(sizeof(struct rr_ctx));
|
||||
if (rr == NULL) goto init_err;
|
||||
memset(rr, 0, sizeof(struct rr_ctx));
|
||||
|
@ -506,9 +506,6 @@ 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]));
|
||||
|
|
|
@ -10,4 +10,3 @@ void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struc
|
|||
fprintf(stderr, "Algorithm %s has not been found\n", name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
#include "utils.h"
|
||||
#include "url.h"
|
||||
|
||||
struct algo_params {
|
||||
uint8_t is_waiting_bootstrap;
|
||||
uint8_t is_healing;
|
||||
};
|
||||
|
||||
struct algo_skel {
|
||||
struct evt_core_cat on_udp_read;
|
||||
struct evt_core_cat on_tcp_read;
|
||||
|
@ -16,11 +21,6 @@ struct algo_skel {
|
|||
struct evt_core_cat on_tcp_co;
|
||||
};
|
||||
|
||||
struct algo_params {
|
||||
uint8_t is_waiting_bootstrap;
|
||||
uint8_t is_healing;
|
||||
};
|
||||
|
||||
typedef void (*algo_init)(struct evt_core_ctx* ctx, struct algo_skel* as, struct algo_params* ap);
|
||||
|
||||
void init_algo(struct evt_core_ctx* ctx, struct algo_skel* as, char* name, struct algo_params* ap);
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#pragma once
|
||||
#include "algo_skel.h"
|
||||
#include <glib-2.0/glib.h>
|
||||
#include <glib-2.0/gmodule.h>
|
||||
#include <glib-2.0/glib-object.h>
|
||||
#include "algo_skel.h"
|
||||
#define PACKET_BUFFER_SIZE 20
|
||||
|
||||
typedef void (*algo_ctx_free_misc)(void*);
|
||||
|
||||
struct algo_ctx {
|
||||
uint8_t link_count;
|
||||
uint8_t is_rdy;
|
||||
struct algo_params ap;
|
||||
int ref_count;
|
||||
struct buffer_packet bps[PACKET_BUFFER_SIZE];
|
||||
GQueue* free_buffer; // Available buffers
|
||||
|
|
Loading…
Reference in a new issue