From 58c354d3adc37da2ccb7af1fbcb398f53a61a9ef Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 15 Aug 2013 11:09:13 +0000 Subject: [PATCH] -handle client disconnects in GNS --- src/gns/gnunet-service-gns.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 7a6f8e277..6b4e63914 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -26,8 +26,6 @@ * TODO: * - conversion of private to public records does NOT check if the * records are actually public - * - need to watch for client disconnects and abort operations on - * disconnect */ #include "platform.h" #include "gnunet_util_lib.h" @@ -550,6 +548,7 @@ handle_lookup (void *cls, GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr); clh = GNUNET_new (struct ClientLookupHandle); + GNUNET_SERVER_client_set_user_context (client, clh); GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh); clh->client = client; clh->request_id = sh_msg->id; @@ -581,6 +580,29 @@ handle_lookup (void *cls, } +/** + * One of our clients disconnected, clean up after it. + * + * @param cls NULL + * @param client the client that disconnected + */ +static void +notify_client_disconnect (void *cls, + struct GNUNET_SERVER_Client *client) +{ + struct ClientLookupHandle *clh; + + if (NULL == client) + return; + clh = GNUNET_SERVER_client_get_user_context (client, struct ClientLookupHandle); + if (NULL == clh) + return; + GNS_resolver_lookup_cancel (clh->lookup); + GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh); + GNUNET_free (clh); +} + + /** * Process GNS requests. * @@ -687,8 +709,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, GNS_resolver_init (namestore_handle, dht_handle, c, max_parallel_bg_queries); - - /* Schedule periodic put for our records. */ + GNUNET_SERVER_disconnect_notify (server, + ¬ify_client_disconnect, + NULL); + /* Schedule periodic put for our records. */ first_zone_iteration = GNUNET_YES; GNUNET_SERVER_add_handlers (server, handlers); statistics = GNUNET_STATISTICS_create ("gns", c); -- 2.25.1