From f5439c2297f8c9db0af779df701a7974f8d94490 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Sun, 21 Feb 2021 11:46:16 +0100 Subject: TNG: Add queue update handling --- src/transport/gnunet-service-tng.c | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/transport/gnunet-service-tng.c') diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 2f6e17f3b..bd9acd0cf 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c @@ -1786,6 +1786,11 @@ struct Queue */ unsigned int queue_length; + /** + * Queue priority + */ + uint32_t priority; + /** * Network type offered by this queue. */ @@ -9574,6 +9579,50 @@ handle_add_queue_message (void *cls, } +/** + * @brief Handle updates to queues. + * + * @param cls the transport client. + * @param msg Message struct. + */ +static void +handle_update_queue_message (void *cls, + const struct + GNUNET_TRANSPORT_UpdateQueueMessage *msg) +{ + struct TransportClient *tc = cls; + struct Queue *target_queue = NULL; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received queue update message for %u with q_len %llu\n", + msg->qid, (unsigned long long) GNUNET_ntohll (msg->q_len)); + for (target_queue = tc->details.communicator.queue_head; + NULL != target_queue; + target_queue = target_queue->next_client) + { + if (msg->qid == target_queue->qid) + break; + } + if (NULL == target_queue) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Queue to update no longer exists! Discarding update.\n"); + return; + } + + target_queue->nt = msg->nt; + target_queue->mtu = ntohl (msg->mtu); + target_queue->cs = msg->cs; + target_queue->priority = ntohl (msg->priority); + /* The update message indicates how many _additional_ + * messages the queue should be able to handle + */ + target_queue->queue_length += GNUNET_ntohll (msg->q_len); + GNUNET_SERVICE_client_continue (tc->client); +} + + + /** * Communicator tells us that our request to create a queue "worked", that * is setting up the queue is now in process. @@ -10101,6 +10150,10 @@ GNUNET_SERVICE_MAIN ( GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, struct GNUNET_TRANSPORT_AddQueueMessage, NULL), + GNUNET_MQ_hd_fixed_size (update_queue_message, + GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE, + struct GNUNET_TRANSPORT_UpdateQueueMessage, + NULL), GNUNET_MQ_hd_fixed_size (del_queue_message, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, struct GNUNET_TRANSPORT_DelQueueMessage, -- cgit v1.2.3