From: Philipp Tölke Date: Wed, 8 Sep 2010 11:14:29 +0000 (+0000) Subject: Queue packet sent to the service-dns X-Git-Tag: initial-import-from-subversion-38251~20394 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=98d6e7934859f0f8652142a0a60868724a7a9155;p=oweals%2Fgnunet.git Queue packet sent to the service-dns --- diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 7c4217cd2..1ec1df77c 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -35,6 +35,7 @@ #include "gnunet_server_lib.h" #include "gnunet-service-dns-p.h" #include "gnunet_client_lib.h" +#include "gnunet_container_lib.h" /** * Final status code. @@ -53,6 +54,8 @@ struct vpn_cls { struct GNUNET_CLIENT_Connection *dns_connection; pid_t helper_pid; + + struct GNUNET_CONTAINER_SList *query_queue; }; static struct vpn_cls mycls; @@ -115,11 +118,31 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts size_t send_query(void* cls, size_t size, void* buf) { - struct query_packet* pkt = cls; - size_t len = ntohs(pkt->hdr.size); - memcpy(buf, cls, len); + struct GNUNET_CONTAINER_SList_Iterator *start = GNUNET_CONTAINER_slist_begin (mycls.query_queue); + + GNUNET_assert(GNUNET_CONTAINER_slist_count(mycls.query_queue) > 0); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "There are %d queries pending.\n", GNUNET_CONTAINER_slist_count(mycls.query_queue)); + + size_t len; + struct query_packet* pkt = (struct query_packet*)GNUNET_CONTAINER_slist_get(start, &len); + + GNUNET_assert(ntohs(pkt->hdr.size) == len); + GNUNET_assert(len <= size); + + memcpy(buf, pkt, len); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes.\n", len); - GNUNET_free(cls); + + GNUNET_CONTAINER_slist_erase(start); + GNUNET_CONTAINER_slist_iter_destroy(start); + + if (GNUNET_CONTAINER_slist_count(mycls.query_queue) > 0) { + start = GNUNET_CONTAINER_slist_begin (mycls.query_queue); + GNUNET_assert(GNUNET_CONTAINER_slist_end(start) != GNUNET_YES); + pkt = (struct query_packet*)GNUNET_CONTAINER_slist_get(start, &len); + GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); + } + return len; } @@ -159,11 +182,14 @@ static void message_token(void *cls, void *client, const struct GNUNET_MessageHe query->orig_from = pkt->ip_hdr.sadr; query->src_port = udp->udp_hdr.spt; memcpy(query->data, udp->data, ntohs(udp->udp_hdr.len) - 8); - struct GNUNET_CLIENT_TransmitHandle* th = GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, query); + + GNUNET_CONTAINER_slist_add_end (mycls.query_queue, GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, query, len); + + struct GNUNET_CLIENT_TransmitHandle* th = GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, len, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); if (th != NULL) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued sending of %d bytes.\n", len); else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Already queued!\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Already queued for %d bytes.\n", len); } } @@ -188,6 +214,9 @@ run (void *cls, mycls.sched = sched; mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL); + mycls.query_queue = GNUNET_CONTAINER_slist_create(); + GNUNET_assert(GNUNET_CONTAINER_slist_count(mycls.query_queue) == 0); + mycls.dns_connection = GNUNET_CLIENT_connect (sched, "gnunet-service-dns", cfg); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connection: %x\n", mycls.dns_connection); diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 7d32e1d73..d24d685b1 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -60,6 +60,7 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received query!\n"); struct query_packet* pkt = (struct query_packet*)message; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Of length %d\n", ntohs(pkt->hdr.size)); struct dns_pkt* dns = (struct dns_pkt*)pkt->data; pkt_printf_dns(dns);