Show buffer states
This commit is contained in:
parent
cbf7e0883a
commit
e543c44674
3 changed files with 32 additions and 9 deletions
|
@ -113,7 +113,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo,
|
|||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||
struct rr_ctx* rr = app_ctx->misc;
|
||||
|
||||
printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id);
|
||||
//printf("Selected url %s for pkt %d to be queued for delivery\n", fdinfo->url, bp->ip.ap.str.id);
|
||||
|
||||
// 1. Update links I can use thanks to target feedback
|
||||
if (bp->ip.ap.str.id > rr->my_links_ver) {
|
||||
|
@ -130,7 +130,7 @@ void rr_pkt_register(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo,
|
|||
}
|
||||
|
||||
// 3. If packet arrived too early, we register a timer
|
||||
printf("%d < %d = %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_lt(rr->recv_id, bp->ip.ap.str.id - 1));
|
||||
//printf("%d < %d = %d\n", rr->recv_id, bp->ip.ap.str.id - 1, ring_lt(rr->recv_id, bp->ip.ap.str.id - 1));
|
||||
if (ring_lt(rr->recv_id, bp->ip.ap.str.id - 1)) {
|
||||
int64_t timeout = rr->mjit - (int64_t) bp->ip.ap.str.deltat;
|
||||
//printf("%ld - %ld = %ld\n", rr->mjit, (int64_t) bp->ip.ap.str.deltat, timeout);
|
||||
|
@ -161,7 +161,7 @@ void rr_deliver(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct
|
|||
struct rr_ctx* rr = app_ctx->misc;
|
||||
char url[255];
|
||||
|
||||
printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id);
|
||||
//printf("Selected url %s for pkt %d to be delivered\n", fdinfo->url, bp->ip.ap.str.id);
|
||||
|
||||
// 0. We update our cursor
|
||||
rr->recv_id = bp->ip.ap.str.id;
|
||||
|
@ -313,7 +313,7 @@ int rr_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|||
//printf("-- Trying %s\n", url);
|
||||
to_fdinfo = evt_core_get_from_url (ctx, url);
|
||||
if (to_fdinfo != NULL) {
|
||||
printf("Selected url %s for pkt %d to be sent on Tor\n", url, bp->ip.ap.str.id);
|
||||
//printf("Selected url %s for pkt %d to be sent on Tor\n", url, bp->ip.ap.str.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -376,7 +376,9 @@ int rr_on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|||
|
||||
printf("Timer reached for packet %d\n", pkt->id);
|
||||
|
||||
// !BLACKLIST LINK
|
||||
//rr->remote_links &= 0xffff ^ 1 << pkt->link_num;
|
||||
|
||||
while (ring_lt(rr->recv_id, pkt->id)) {
|
||||
rr->recv_id++;
|
||||
rr_pkt_unroll (ctx, app_ctx);
|
||||
|
|
|
@ -12,6 +12,15 @@ void free_naive(void* app_ctx) {
|
|||
free(ctx);
|
||||
}
|
||||
|
||||
void iterate(int* fd, GQueue* q, int* waiting_count) {
|
||||
fprintf(stderr, "Queue for fd=%d has length=%d\n", *fd, q->length);
|
||||
waiting_count += q->length;
|
||||
}
|
||||
|
||||
void iterate2(int* fd, struct buffer_packet *bp, gpointer user_data) {
|
||||
fprintf(stderr, "fd=%d has a used_buffer entry\n", *fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a buffer if available, NULL otherwise
|
||||
*/
|
||||
|
@ -25,6 +34,15 @@ struct buffer_packet* get_read_buffer(struct algo_ctx *app_ctx, struct evt_core_
|
|||
// 2. Get a new buffer otherwise
|
||||
bp = g_queue_pop_head(app_ctx->free_buffer);
|
||||
if (bp == NULL) {
|
||||
fprintf(stderr, "No more free buffer for fd=%d.\n", fdinfo->fd);
|
||||
int waiting_count = 0;
|
||||
g_hash_table_foreach(app_ctx->write_waiting, (GHFunc)iterate, &waiting_count);
|
||||
g_hash_table_foreach(app_ctx->used_buffer, (GHFunc)iterate2, NULL);
|
||||
fprintf(stderr, "total_buffers=%d, used_buffers=%d. free_buffer=%d, waiting_buffer=%d.\n",
|
||||
PACKET_BUFFER_SIZE,
|
||||
g_hash_table_size(app_ctx->used_buffer),
|
||||
app_ctx->free_buffer->length,
|
||||
waiting_count);
|
||||
// 2.1 If no buffer is available, we subscribe to be notified later
|
||||
g_queue_push_tail (app_ctx->read_waiting, &(fdinfo->fd));
|
||||
return NULL;
|
||||
|
@ -86,10 +104,13 @@ void mv_buffer_wtor(struct algo_ctx* app_ctx, struct evt_core_fdinfo* fdinfo, st
|
|||
void notify_read(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx) {
|
||||
struct evt_core_fdinfo* next_fdinfo = NULL;
|
||||
while (next_fdinfo == NULL) {
|
||||
int fd = GPOINTER_TO_INT(g_queue_pop_head(app_ctx->read_waiting));
|
||||
if (fd == 0) break;
|
||||
next_fdinfo = evt_core_get_from_fd (ctx, fd);
|
||||
if (strcmp(next_fdinfo->cat->name, "tcp-read") == 0 || strcmp(next_fdinfo->cat->name, "udp-read") == 0) {
|
||||
int* fd = g_queue_pop_head(app_ctx->read_waiting);
|
||||
if (fd == NULL) break;
|
||||
next_fdinfo = evt_core_get_from_fd (ctx, *fd);
|
||||
if (next_fdinfo == NULL) {
|
||||
fprintf(stderr, "Unable to find fdinfo for fd=%d\n", *fd);
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (strcmp(next_fdinfo->cat->name, "tcp-read") == 0 || strcmp(next_fdinfo->cat->name, "udp-read") == 0) {
|
||||
next_fdinfo->cat->cb(ctx, next_fdinfo);
|
||||
} else {
|
||||
fprintf(stderr, "A fd from category %s can't be stored in read_waiting\n", next_fdinfo->cat->name);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <glib-2.0/glib.h>
|
||||
#include <glib-2.0/gmodule.h>
|
||||
#include <glib-2.0/glib-object.h>
|
||||
#define PACKET_BUFFER_SIZE 100
|
||||
#define PACKET_BUFFER_SIZE 20
|
||||
|
||||
typedef void (*algo_ctx_free_misc)(void*);
|
||||
|
||||
|
|
Loading…
Reference in a new issue