aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore
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
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/peerstore')
-rw-r--r--src/peerstore/gnunet-peerstore.c11
-rw-r--r--src/peerstore/gnunet-service-peerstore.c55
-rw-r--r--src/peerstore/peerstore_api.c6
3 files changed, 43 insertions, 29 deletions
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c
index 68ae1746f..25a4f0ff4 100644
--- a/src/peerstore/gnunet-peerstore.c
+++ b/src/peerstore/gnunet-peerstore.c
@@ -60,16 +60,15 @@ shutdown_task (void *cls)
60 * @param cfg configuration 60 * @param cfg configuration
61 */ 61 */
62static void 62static void
63run (void *cls, char *const *args, const char *cfgfile, 63run (void *cls,
64 char *const *args,
65 const char *cfgfile,
64 const struct GNUNET_CONFIGURATION_Handle *cfg) 66 const struct GNUNET_CONFIGURATION_Handle *cfg)
65{ 67{
66 68 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
67 peerstore_handle = NULL; 69 NULL);
68 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
69 NULL);
70 peerstore_handle = GNUNET_PEERSTORE_connect (cfg); 70 peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
71 GNUNET_assert (NULL != peerstore_handle); 71 GNUNET_assert (NULL != peerstore_handle);
72
73 ret = 0; 72 ret = 0;
74} 73}
75 74
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
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 14117a333..f1c5ccd32 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -213,7 +213,7 @@ struct GNUNET_PEERSTORE_IterateContext
213 * Task identifier for the function called 213 * Task identifier for the function called
214 * on iterate request timeout 214 * on iterate request timeout
215 */ 215 */
216 struct GNUNET_SCHEDULER_Task * timeout_task; 216 struct GNUNET_SCHEDULER_Task *timeout_task;
217 217
218}; 218};
219 219
@@ -340,7 +340,9 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error)
340 * @return #GNUNET_YES (continue to iterate) 340 * @return #GNUNET_YES (continue to iterate)
341 */ 341 */
342static int 342static int
343rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value) 343rewatch_it (void *cls,
344 const struct GNUNET_HashCode *key,
345 void *value)
344{ 346{
345 struct GNUNET_PEERSTORE_Handle *h = cls; 347 struct GNUNET_PEERSTORE_Handle *h = cls;
346 struct GNUNET_PEERSTORE_WatchContext *wc = value; 348 struct GNUNET_PEERSTORE_WatchContext *wc = value;