diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-10-02 09:36:09 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-10-02 09:36:09 +0200 |
commit | 73f3dbe65643956dd1d872730cdd08c71cd076c5 (patch) | |
tree | 0183dd16ebc7fce573ee001dfe5396acd1affba2 /src | |
parent | 0f225ed0304398350d7b51a2567b2dc595476f31 (diff) | |
download | gnunet-73f3dbe65643956dd1d872730cdd08c71cd076c5.tar.gz gnunet-73f3dbe65643956dd1d872730cdd08c71cd076c5.zip |
disconnect CADET only after client count hits zero
Diffstat (limited to 'src')
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 18 | ||||
-rw-r--r-- | 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, | |||
355 | (SQLITE_OK != | 355 | (SQLITE_OK != |
356 | sq_prepare (plugin->dbh, | 356 | sq_prepare (plugin->dbh, |
357 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 357 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
358 | #if SQLITE_VERSION_NUMBER >= 3007000 | ||
359 | "INDEXED BY idx_repl_rvalue " | ||
360 | #endif | ||
361 | "WHERE repl=?2 AND " " (rvalue>=?1 OR " | 358 | "WHERE repl=?2 AND " " (rvalue>=?1 OR " |
362 | " NOT EXISTS (SELECT 1 FROM gn091 " | 359 | " NOT EXISTS (SELECT 1 FROM gn091 " |
363 | #if SQLITE_VERSION_NUMBER >= 3007000 | ||
364 | "INDEXED BY idx_repl_rvalue " | ||
365 | #endif | ||
366 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " | 360 | "WHERE repl=?2 AND rvalue>=?1 LIMIT 1) ) " |
367 | "ORDER BY rvalue ASC LIMIT 1", | 361 | "ORDER BY rvalue ASC LIMIT 1", |
368 | &plugin->selRepl)) || | 362 | &plugin->selRepl)) || |
369 | (SQLITE_OK != | 363 | (SQLITE_OK != |
370 | sq_prepare (plugin->dbh, | 364 | sq_prepare (plugin->dbh, |
371 | "SELECT MAX(repl) FROM gn091" | 365 | "SELECT MAX(repl) FROM gn091", |
372 | #if SQLITE_VERSION_NUMBER >= 3007000 | ||
373 | " INDEXED BY idx_repl_rvalue" | ||
374 | #endif | ||
375 | "", | ||
376 | &plugin->maxRepl)) || | 366 | &plugin->maxRepl)) || |
377 | (SQLITE_OK != | 367 | (SQLITE_OK != |
378 | sq_prepare (plugin->dbh, | 368 | sq_prepare (plugin->dbh, |
379 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 369 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
380 | #if SQLITE_VERSION_NUMBER >= 3007000 | ||
381 | "INDEXED BY idx_expire " | ||
382 | #endif | ||
383 | "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " | 370 | "WHERE NOT EXISTS (SELECT 1 FROM gn091 WHERE expire < ?1 LIMIT 1) OR (expire < ?1) " |
384 | "ORDER BY expire ASC LIMIT 1", | 371 | "ORDER BY expire ASC LIMIT 1", |
385 | &plugin->selExpi)) || | 372 | &plugin->selExpi)) || |
386 | (SQLITE_OK != | 373 | (SQLITE_OK != |
387 | sq_prepare (plugin->dbh, | 374 | sq_prepare (plugin->dbh, |
388 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 375 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
389 | #if SQLITE_VERSION_NUMBER >= 3007000 | ||
390 | "INDEXED BY idx_anon_type " | ||
391 | #endif | ||
392 | "WHERE _ROWID_ >= ? AND " | 376 | "WHERE _ROWID_ >= ? AND " |
393 | "anonLevel = 0 AND " | 377 | "anonLevel = 0 AND " |
394 | "type = ? " | 378 | "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 | |||
@@ -155,6 +155,17 @@ static struct Listener *listener_head; | |||
155 | static struct Listener *listener_tail; | 155 | static struct Listener *listener_tail; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Number of active clients. | ||
159 | */ | ||
160 | static unsigned int num_clients; | ||
161 | |||
162 | /** | ||
163 | * Are we in shutdown? if #GNUNET_YES and the number of clients | ||
164 | * drops to zero, disconnect from CADET. | ||
165 | */ | ||
166 | static int in_shutdown; | ||
167 | |||
168 | /** | ||
158 | * Counter for allocating unique IDs for clients, used to identify | 169 | * Counter for allocating unique IDs for clients, used to identify |
159 | * incoming operation requests from remote peers, that the client can | 170 | * incoming operation requests from remote peers, that the client can |
160 | * choose to accept or refuse. 0 must not be used (reserved for | 171 | * choose to accept or refuse. 0 must not be used (reserved for |
@@ -485,6 +496,7 @@ client_connect_cb (void *cls, | |||
485 | { | 496 | { |
486 | struct ClientState *cs; | 497 | struct ClientState *cs; |
487 | 498 | ||
499 | num_clients++; | ||
488 | cs = GNUNET_new (struct ClientState); | 500 | cs = GNUNET_new (struct ClientState); |
489 | cs->client = c; | 501 | cs->client = c; |
490 | cs->mq = mq; | 502 | cs->mq = mq; |
@@ -623,6 +635,16 @@ client_disconnect_cb (void *cls, | |||
623 | GNUNET_free (listener); | 635 | GNUNET_free (listener); |
624 | } | 636 | } |
625 | GNUNET_free (cs); | 637 | GNUNET_free (cs); |
638 | num_clients--; | ||
639 | if ( (GNUNET_YES == in_shutdown) && | ||
640 | (0 == num_clients) ) | ||
641 | { | ||
642 | if (NULL != cadet) | ||
643 | { | ||
644 | GNUNET_CADET_disconnect (cadet); | ||
645 | cadet = NULL; | ||
646 | } | ||
647 | } | ||
626 | } | 648 | } |
627 | 649 | ||
628 | 650 | ||
@@ -1917,10 +1939,14 @@ static void | |||
1917 | shutdown_task (void *cls) | 1939 | shutdown_task (void *cls) |
1918 | { | 1940 | { |
1919 | /* Delay actual shutdown to allow service to disconnect clients */ | 1941 | /* Delay actual shutdown to allow service to disconnect clients */ |
1920 | if (NULL != cadet) | 1942 | in_shutdown = GNUNET_YES; |
1943 | if (0 == num_clients) | ||
1921 | { | 1944 | { |
1922 | GNUNET_CADET_disconnect (cadet); | 1945 | if (NULL != cadet) |
1923 | cadet = NULL; | 1946 | { |
1947 | GNUNET_CADET_disconnect (cadet); | ||
1948 | cadet = NULL; | ||
1949 | } | ||
1924 | } | 1950 | } |
1925 | GNUNET_STATISTICS_destroy (_GSS_statistics, | 1951 | GNUNET_STATISTICS_destroy (_GSS_statistics, |
1926 | GNUNET_YES); | 1952 | GNUNET_YES); |