From: Bart Polot Date: Tue, 6 Sep 2011 13:42:26 +0000 (+0000) Subject: Added cancellation of least priority packet on notify transmit ready X-Git-Tag: initial-import-from-subversion-38251~17211 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=224092cedfcffab0ef12bb452261e69eecb09322;p=oweals%2Fgnunet.git Added cancellation of least priority packet on notify transmit ready --- diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 615593621..8476be396 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -921,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) GNUNET_free (handle); } -/* end of mesh_api.c */ \ No newline at end of file +/* end of mesh_api.c */ diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 03c511adf..16957c8d9 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c @@ -23,7 +23,6 @@ * TODO: * - callbacks to client missing on certain events * - processing messages from service is incomplete - * - Check priorities to cancel traffic data * - Use separate message types for tunnel creation s -> c (+pi) and c -> s * * STRUCTURE: @@ -1347,12 +1346,42 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, void *notify_cls) { struct GNUNET_MESH_TransmitHandle *th; + struct GNUNET_MESH_TransmitHandle *least_priority_th; + uint32_t least_priority; size_t overhead; GNUNET_assert(NULL != notify); if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && tunnel->npackets > 0) - return NULL; /* queue full */ + { + /* queue full */ + if (0 == priority) + return NULL; + th = tunnel->mesh->th_tail; + least_priority = priority; + least_priority_th = NULL; + while (NULL != th) + { + if (th->priority < least_priority && th->tunnel->npackets > 1) + { + least_priority_th = th; + least_priority = th->priority; + } + th = th->prev; + } + if (NULL == least_priority_th) + return NULL; + GNUNET_assert(NULL != least_priority_th->notify); /* Cant be a cntrl msg */ + least_priority_th->notify(notify_cls, 0, NULL); + least_priority_th->tunnel->npackets--; + tunnel->mesh->npackets--; + GNUNET_CONTAINER_DLL_remove(tunnel->mesh->th_head, + tunnel->mesh->th_tail, + least_priority_th); + if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task) + GNUNET_SCHEDULER_cancel(least_priority_th->timeout_task); + GNUNET_free(least_priority_th); + } tunnel->npackets++; tunnel->mesh->npackets++; th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));