From 73f3dbe65643956dd1d872730cdd08c71cd076c5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 2 Oct 2017 09:36:09 +0200 Subject: [PATCH] disconnect CADET only after client count hits zero --- src/datastore/plugin_datastore_sqlite.c | 18 +------------- src/set/gnunet-service-set.c | 32 ++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 2d539cb19..cc56f5959 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -355,40 +355,24 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT " RESULT_COLUMNS " FROM gn091 " -#if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_repl_rvalue " -#endif "WHERE repl=?2 AND " " (rvalue>=?1 OR " " NOT EXISTS (SELECT 1 FROM gn091 " -#if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_repl_rvalue " -#endif "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " "ORDER BY rvalue ASC LIMIT 1", &plugin->selRepl)) || (SQLITE_OK != sq_prepare (plugin->dbh, - "SELECT MAX(repl) FROM gn091" -#if SQLITE_VERSION_NUMBER >= 3007000 - " INDEXED BY idx_repl_rvalue" -#endif - "", + "SELECT MAX(repl) FROM gn091", &plugin->maxRepl)) || (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT " RESULT_COLUMNS " FROM gn091 " -#if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_expire " -#endif "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " "ORDER BY expire ASC LIMIT 1", &plugin->selExpi)) || (SQLITE_OK != sq_prepare (plugin->dbh, "SELECT " RESULT_COLUMNS " FROM gn091 " -#if SQLITE_VERSION_NUMBER >= 3007000 - "INDEXED BY idx_anon_type " -#endif "WHERE _ROWID_ >= ? AND " "anonLevel = 0 AND " "type = ? " diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index f98d43a7d..056f70f32 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c @@ -154,6 +154,17 @@ static struct Listener *listener_head; */ static struct Listener *listener_tail; +/** + * Number of active clients. + */ +static unsigned int num_clients; + +/** + * Are we in shutdown? if #GNUNET_YES and the number of clients + * drops to zero, disconnect from CADET. + */ +static int in_shutdown; + /** * Counter for allocating unique IDs for clients, used to identify * incoming operation requests from remote peers, that the client can @@ -485,6 +496,7 @@ client_connect_cb (void *cls, { struct ClientState *cs; + num_clients++; cs = GNUNET_new (struct ClientState); cs->client = c; cs->mq = mq; @@ -623,6 +635,16 @@ client_disconnect_cb (void *cls, GNUNET_free (listener); } GNUNET_free (cs); + num_clients--; + if ( (GNUNET_YES == in_shutdown) && + (0 == num_clients) ) + { + if (NULL != cadet) + { + GNUNET_CADET_disconnect (cadet); + cadet = NULL; + } + } } @@ -1917,10 +1939,14 @@ static void shutdown_task (void *cls) { /* Delay actual shutdown to allow service to disconnect clients */ - if (NULL != cadet) + in_shutdown = GNUNET_YES; + if (0 == num_clients) { - GNUNET_CADET_disconnect (cadet); - cadet = NULL; + if (NULL != cadet) + { + GNUNET_CADET_disconnect (cadet); + cadet = NULL; + } } GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES); -- 2.25.1