From a79ea321245662f933dc8f9208b26d85d79cbe6c Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 25 Jul 2012 15:31:07 +0000 Subject: [PATCH] Eliminate mesh priority option --- src/dns/gnunet-service-dns.c | 2 +- src/exit/gnunet-daemon-exit.c | 5 +- src/include/gnunet_mesh_service.h | 4 +- src/mesh/mesh_api.c | 83 +++++++++---------------------- src/pt/gnunet-daemon-pt.c | 6 +-- src/stream/stream_api.c | 12 ++--- src/vpn/gnunet-service-vpn.c | 2 - 7 files changed, 36 insertions(+), 78 deletions(-) diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 10fc00282..76ea1390f 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c @@ -1027,7 +1027,7 @@ do_dns_read (struct GNUNET_NETWORK_Handle *dnsout) if (ts->th != NULL) GNUNET_MESH_notify_transmit_ready_cancel (ts->th); ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, - GNUNET_NO, 0, + GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, NULL, sizeof (struct GNUNET_MessageHeader) + r, diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index 337fca481..4f583c5bd 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c @@ -535,7 +535,6 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) { s->th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO /* corking */, - 0 /* priority */, GNUNET_TIME_UNIT_FOREVER_REL, NULL, tnq->len, @@ -553,7 +552,6 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) if (NULL != (tnq = s->head)) s->th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO /* corking */, - 0 /* priority */, GNUNET_TIME_UNIT_FOREVER_REL, NULL, tnq->len, @@ -582,7 +580,8 @@ send_packet_to_mesh_tunnel (struct GNUNET_MESH_Tunnel *mesh_tunnel, GNUNET_assert (NULL != s); GNUNET_CONTAINER_DLL_insert_tail (s->head, s->tail, tnq); if (NULL == s->th) - s->th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, GNUNET_NO /* cork */, 0 /* priority */, + s->th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, + GNUNET_NO /* cork */, GNUNET_TIME_UNIT_FOREVER_REL, NULL, tnq->len, &send_to_peer_notify_callback, diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 044fe1cee..b674e5d76 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -377,10 +377,11 @@ struct GNUNET_MESH_TransmitHandle; /** * Ask the mesh to call "notify" once it is ready to transmit the * given number of bytes to the specified tunnel or target. + * Only one call can be active at any time, to issue another request, + * wait for the callback or cancel the current request. * * @param tunnel tunnel to use for transmission * @param cork is corking allowed for this transmission? - * @param priority how important is the message? * @param maxdelay how long can the message wait? * @param target destination for the message * NULL for multicast to all tunnel targets @@ -396,7 +397,6 @@ struct GNUNET_MESH_TransmitHandle; */ struct GNUNET_MESH_TransmitHandle * GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, - uint32_t priority, struct GNUNET_TIME_Relative maxdelay, const struct GNUNET_PeerIdentity *target, size_t notify_size, diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index f02c17a2a..8117b9354 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -102,12 +102,6 @@ struct GNUNET_MESH_TransmitHandle */ GNUNET_SCHEDULER_TaskIdentifier timeout_task; - /** - * Priority of the message. The queue is sorted by priority, - * control messages have the maximum priority (UINT32_MAX). - */ - uint32_t priority; - /** * Target of the message, 0 for multicast. This field * is only valid if 'notify' is non-NULL. @@ -146,9 +140,13 @@ struct GNUNET_MESH_Handle const GNUNET_MESH_ApplicationType *applications; /** - * Double linked list of the tunnels this client is connected to. + * Double linked list of the tunnels this client is connected to, head. */ struct GNUNET_MESH_Tunnel *tunnels_head; + + /** + * Double linked list of the tunnels this client is connected to, tail. + */ struct GNUNET_MESH_Tunnel *tunnels_tail; /** @@ -172,18 +170,29 @@ struct GNUNET_MESH_Handle void *cls; /** - * Messages to send to the service + * Messages to send to the service, head. */ struct GNUNET_MESH_TransmitHandle *th_head; + + /** + * Messages to send to the service, tail. + */ struct GNUNET_MESH_TransmitHandle *th_tail; /** * tid of the next tunnel to create (to avoid reusing IDs often) */ MESH_TunnelNumber next_tid; + + /** + * Number of handlers in the handlers array. + */ unsigned int n_handlers; + + /** + * Number of applications in the applications array. + */ unsigned int n_applications; - unsigned int max_queue_size; /** * Have we started the task to receive messages from the service @@ -191,11 +200,6 @@ struct GNUNET_MESH_Handle */ int in_receive; - /** - * Number of packets queued - */ - unsigned int npackets; - /** * Configuration given by the client, in case of reconnection */ @@ -587,7 +591,7 @@ add_to_queue (struct GNUNET_MESH_Handle *h, struct GNUNET_MESH_TransmitHandle *p; p = h->th_head; - while ((NULL != p) && (th->priority <= p->priority)) + while ((NULL != p)) p = p->next; if (NULL == p) p = h->th_tail; @@ -1253,7 +1257,6 @@ send_callback (void *cls, size_t size, void *buf) GNUNET_SCHEDULER_cancel (th->timeout_task); if (NULL != th->notify) { - th->tunnel->mesh->npackets--; th->tunnel->npackets--; } GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); @@ -1302,7 +1305,6 @@ send_packet (struct GNUNET_MESH_Handle *h, msize = ntohs (msg->size); th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); - th->priority = UINT32_MAX; th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; th->size = msize; th->tunnel = tunnel; @@ -1413,7 +1415,6 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) /* Make sure it is an allowed packet (everything else should have been * already canceled). */ - GNUNET_break (UINT32_MAX == th->priority); GNUNET_break (NULL == th->notify); msg = (struct GNUNET_MessageHeader *) &th[1]; switch (ntohs(msg->type)) @@ -1825,15 +1826,14 @@ GNUNET_MESH_peer_unblacklist (struct GNUNET_MESH_Tunnel *tunnel, /** * Ask the mesh to call "notify" once it is ready to transmit the - * given number of bytes to the specified "target". If we are not yet - * connected to the specified peer, a call to this function will cause - * us to try to establish a connection. + * given number of bytes to the specified tunnel or target. + * Only one call can be active at any time, to issue another request, + * wait for the callback or cancel the current request. * * @param tunnel tunnel to use for transmission * @param cork is corking allowed for this transmission? - * @param priority how important is the message? * @param maxdelay how long can the message wait? - * @param target destination for the message, + * @param target destination for the message * NULL for multicast to all tunnel targets * @param notify_size how many bytes of buffer space does notify want? * @param notify function to call when buffer space is available; @@ -1847,7 +1847,6 @@ GNUNET_MESH_peer_unblacklist (struct GNUNET_MESH_Tunnel *tunnel, */ struct GNUNET_MESH_TransmitHandle * GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, - uint32_t priority, struct GNUNET_TIME_Relative maxdelay, const struct GNUNET_PeerIdentity *target, size_t notify_size, @@ -1855,8 +1854,6 @@ 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 != tunnel); @@ -1866,42 +1863,10 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, else LOG (GNUNET_ERROR_TYPE_DEBUG, " target multicast\n"); GNUNET_assert (NULL != notify); - if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && - tunnel->npackets > 0) - { - /* 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; - /* Can't be a control message */ - GNUNET_assert (NULL != least_priority_th->notify); - 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); - } + GNUNET_assert (0 == tunnel->npackets); tunnel->npackets++; - tunnel->mesh->npackets++; th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); th->tunnel = tunnel; - th->priority = priority; th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); th->target = GNUNET_PEER_intern (target); if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c index 702b8a95c..2658ae165 100644 --- a/src/pt/gnunet-daemon-pt.c +++ b/src/pt/gnunet-daemon-pt.c @@ -550,7 +550,7 @@ transmit_dns_request_to_mesh (void *cls, if (mlen > size) { mesh_th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, - GNUNET_NO, 0, + GNUNET_NO, TIMEOUT, NULL, mlen, &transmit_dns_request_to_mesh, @@ -569,7 +569,7 @@ transmit_dns_request_to_mesh (void *cls, rc = transmit_queue_head; if (NULL != rc) mesh_th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, - GNUNET_NO, 0, + GNUNET_NO, TIMEOUT, NULL, ntohs (rc->mesh_message->size), &transmit_dns_request_to_mesh, @@ -668,7 +668,7 @@ dns_pre_request_handler (void *cls, rc); if (NULL == mesh_th) mesh_th = GNUNET_MESH_notify_transmit_ready (mesh_tunnel, - GNUNET_NO, 0, + GNUNET_NO, TIMEOUT, NULL, mlen, &transmit_dns_request_to_mesh, diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 930bd63e7..49227ccec 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c @@ -583,8 +583,7 @@ send_message_notify (void *cls, size_t size, void *buf) socket->retries); socket->transmit_handle = GNUNET_MESH_notify_transmit_ready (socket->tunnel, - 0, /* Corking */ - 1, /* Priority */ + GNUNET_NO, /* Corking */ /* FIXME: exponential backoff */ socket->retransmit_timeout, &socket->other_peer, @@ -611,8 +610,7 @@ send_message_notify (void *cls, size_t size, void *buf) socket->retries = 0; socket->transmit_handle = GNUNET_MESH_notify_transmit_ready (socket->tunnel, - 0, /* Corking */ - 1, /* Priority */ + GNUNET_NO, /* Corking */ /* FIXME: exponential backoff */ socket->retransmit_timeout, &socket->other_peer, @@ -662,8 +660,7 @@ queue_message (struct GNUNET_STREAM_Socket *socket, socket->retries = 0; socket->transmit_handle = GNUNET_MESH_notify_transmit_ready (socket->tunnel, - 0, /* Corking */ - 1, /* Priority */ + GNUNET_NO, /* Corking */ socket->retransmit_timeout, &socket->other_peer, ntohs (message->header.size), @@ -792,8 +789,7 @@ ack_task (void *cls, /* Request MESH for sending ACK */ socket->ack_transmit_handle = GNUNET_MESH_notify_transmit_ready (socket->tunnel, - 0, /* Corking */ - 1, /* Priority */ + GNUNET_NO, /* Corking */ socket->retransmit_timeout, &socket->other_peer, ntohs (ack_msg->header.header.size), diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index b8801e5d4..6138e9c1e 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -689,7 +689,6 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) if (NULL != (tnq = ts->tmq_head)) ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, GNUNET_NO /* cork */, - 42 /* priority */, GNUNET_TIME_UNIT_FOREVER_REL, NULL, tnq->len, @@ -742,7 +741,6 @@ send_to_tunnel (struct TunnelMessageQueueEntry *tnq, if (NULL == ts->th) ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, GNUNET_NO /* cork */, - 42 /* priority */, GNUNET_TIME_UNIT_FOREVER_REL, NULL, tnq->len, -- 2.25.1