aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/gnunet-service-peerstore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/peerstore/gnunet-service-peerstore.c
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r--src/peerstore/gnunet-service-peerstore.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index 3a2d928e3..048201c77 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -91,6 +91,11 @@ static struct ClientEntry *client_head;
91static struct ClientEntry *client_tail; 91static struct ClientEntry *client_tail;
92 92
93/** 93/**
94 * Task run to clean up expired records.
95 */
96static struct GNUNET_SCHEDULER_Task *expire_task;
97
98/**
94 * Are we in the process of shutting down the service? #GNUNET_YES / #GNUNET_NO 99 * Are we in the process of shutting down the service? #GNUNET_YES / #GNUNET_NO
95 */ 100 */
96static int in_shutdown; 101static int in_shutdown;
@@ -117,6 +122,11 @@ do_shutdown ()
117 GNUNET_CONTAINER_multihashmap_destroy (watchers); 122 GNUNET_CONTAINER_multihashmap_destroy (watchers);
118 watchers = NULL; 123 watchers = NULL;
119 } 124 }
125 if (NULL != expire_task)
126 {
127 GNUNET_SCHEDULER_cancel (expire_task);
128 expire_task = NULL;
129 }
120 GNUNET_SCHEDULER_shutdown (); 130 GNUNET_SCHEDULER_shutdown ();
121} 131}
122 132
@@ -147,21 +157,18 @@ static void
147cleanup_expired_records (void *cls) 157cleanup_expired_records (void *cls)
148{ 158{
149 int ret; 159 int ret;
150 const struct GNUNET_SCHEDULER_TaskContext *tc;
151 160
152 tc = GNUNET_SCHEDULER_get_task_context (); 161 expire_task = NULL;
153 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
154 return;
155 GNUNET_assert (NULL != db); 162 GNUNET_assert (NULL != db);
156 ret = 163 ret = db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
157 db->expire_records (db->cls, GNUNET_TIME_absolute_get (), 164 &expire_records_continuation, NULL);
158 expire_records_continuation, NULL);
159 if (GNUNET_OK != ret) 165 if (GNUNET_OK != ret)
160 { 166 {
161 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 167 GNUNET_assert (NULL == expire_task);
162 (GNUNET_TIME_UNIT_SECONDS, 168 expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
163 EXPIRED_RECORDS_CLEANUP_INTERVAL), 169 (GNUNET_TIME_UNIT_SECONDS,
164 &cleanup_expired_records, NULL); 170 EXPIRED_RECORDS_CLEANUP_INTERVAL),
171 &cleanup_expired_records, NULL);
165 } 172 }
166} 173}
167 174
@@ -173,14 +180,18 @@ cleanup_expired_records (void *cls)
173 * @param success count of records deleted or #GNUNET_SYSERR 180 * @param success count of records deleted or #GNUNET_SYSERR
174 */ 181 */
175static void 182static void
176expire_records_continuation (void *cls, int success) 183expire_records_continuation (void *cls,
184 int success)
177{ 185{
178 if (success > 0) 186 if (success > 0)
179 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); 187 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
180 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 188 "%d records expired.\n",
181 (GNUNET_TIME_UNIT_SECONDS, 189 success);
182 EXPIRED_RECORDS_CLEANUP_INTERVAL), 190 GNUNET_assert (NULL == expire_task);
183 &cleanup_expired_records, NULL); 191 expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
192 (GNUNET_TIME_UNIT_SECONDS,
193 EXPIRED_RECORDS_CLEANUP_INTERVAL),
194 &cleanup_expired_records, NULL);
184} 195}
185 196
186 197
@@ -565,18 +576,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
565 if (NULL == db) 576 if (NULL == db)
566 { 577 {
567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 578 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
568 _("Could not load database backend `%s'\n"), db_lib_name); 579 _("Could not load database backend `%s'\n"),
580 db_lib_name);
569 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 581 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
570 return; 582 return;
571 } 583 }
572 nc = GNUNET_SERVER_notification_context_create (server, 16); 584 nc = GNUNET_SERVER_notification_context_create (server, 16);
573 watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 585 watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
574 GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); 586 expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records,
587 NULL);
575 GNUNET_SERVER_add_handlers (server, handlers); 588 GNUNET_SERVER_add_handlers (server, handlers);
576 GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL); 589 GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL);
577 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 590 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
578 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 591 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
579 NULL); 592 NULL);
580} 593}
581 594
582 595