diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:57:59 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-04 11:57:59 +0200 |
commit | 58002acac13b2eef407a20ee3ddc5f458cd5e483 (patch) | |
tree | 8285fc1b32a8c9ac55f970667e7d29b791b6758e /src/peerstore/gnunet-service-peerstore.c | |
parent | 9ce956ea4c93f038995a21c6c1c0133eee6bff75 (diff) | |
download | gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.tar.gz gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.zip |
nicer loop structure
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 264 |
1 files changed, 112 insertions, 152 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 9bce542b9..ed1c35535 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,7 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Interval for expired records cleanup (in seconds) | 34 | * Interval for expired records cleanup (in seconds) |
35 | */ | 35 | */ |
36 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ | 36 | #define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */ |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Our configuration. | 39 | * Our configuration. |
@@ -79,9 +79,7 @@ do_shutdown () | |||
79 | { | 79 | { |
80 | if (NULL != db_lib_name) | 80 | if (NULL != db_lib_name) |
81 | { | 81 | { |
82 | GNUNET_break (NULL == | 82 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db)); |
83 | GNUNET_PLUGIN_unload (db_lib_name, | ||
84 | db)); | ||
85 | GNUNET_free (db_lib_name); | 83 | GNUNET_free (db_lib_name); |
86 | db_lib_name = NULL; | 84 | db_lib_name = NULL; |
87 | } | 85 | } |
@@ -108,15 +106,14 @@ static void | |||
108 | shutdown_task (void *cls) | 106 | shutdown_task (void *cls) |
109 | { | 107 | { |
110 | in_shutdown = GNUNET_YES; | 108 | in_shutdown = GNUNET_YES; |
111 | if (0 == num_clients) /* Only when no connected clients. */ | 109 | if (0 == num_clients) /* Only when no connected clients. */ |
112 | do_shutdown (); | 110 | do_shutdown (); |
113 | } | 111 | } |
114 | 112 | ||
115 | 113 | ||
116 | /* Forward declaration */ | 114 | /* Forward declaration */ |
117 | static void | 115 | static void |
118 | expire_records_continuation (void *cls, | 116 | expire_records_continuation (void *cls, int success); |
119 | int success); | ||
120 | 117 | ||
121 | 118 | ||
122 | /** | 119 | /** |
@@ -131,16 +128,16 @@ cleanup_expired_records (void *cls) | |||
131 | GNUNET_assert (NULL != db); | 128 | GNUNET_assert (NULL != db); |
132 | ret = db->expire_records (db->cls, | 129 | ret = db->expire_records (db->cls, |
133 | GNUNET_TIME_absolute_get (), | 130 | GNUNET_TIME_absolute_get (), |
134 | &expire_records_continuation, | 131 | &expire_records_continuation, |
135 | NULL); | 132 | NULL); |
136 | if (GNUNET_OK != ret) | 133 | if (GNUNET_OK != ret) |
137 | { | 134 | { |
138 | GNUNET_assert (NULL == expire_task); | 135 | GNUNET_assert (NULL == expire_task); |
139 | expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 136 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
140 | (GNUNET_TIME_UNIT_SECONDS, | 137 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
141 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 138 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
142 | &cleanup_expired_records, | 139 | &cleanup_expired_records, |
143 | NULL); | 140 | NULL); |
144 | } | 141 | } |
145 | } | 142 | } |
146 | 143 | ||
@@ -152,19 +149,16 @@ cleanup_expired_records (void *cls) | |||
152 | * @param success count of records deleted or #GNUNET_SYSERR | 149 | * @param success count of records deleted or #GNUNET_SYSERR |
153 | */ | 150 | */ |
154 | static void | 151 | static void |
155 | expire_records_continuation (void *cls, | 152 | expire_records_continuation (void *cls, int success) |
156 | int success) | ||
157 | { | 153 | { |
158 | if (success > 0) | 154 | if (success > 0) |
159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success); |
160 | "%d records expired.\n", | ||
161 | success); | ||
162 | GNUNET_assert (NULL == expire_task); | 156 | GNUNET_assert (NULL == expire_task); |
163 | expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 157 | expire_task = GNUNET_SCHEDULER_add_delayed ( |
164 | (GNUNET_TIME_UNIT_SECONDS, | 158 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
165 | EXPIRED_RECORDS_CLEANUP_INTERVAL), | 159 | EXPIRED_RECORDS_CLEANUP_INTERVAL), |
166 | &cleanup_expired_records, | 160 | &cleanup_expired_records, |
167 | NULL); | 161 | NULL); |
168 | } | 162 | } |
169 | 163 | ||
170 | 164 | ||
@@ -195,15 +189,12 @@ client_connect_cb (void *cls, | |||
195 | * @return #GNUNET_OK to continue iterating | 189 | * @return #GNUNET_OK to continue iterating |
196 | */ | 190 | */ |
197 | static int | 191 | static int |
198 | client_disconnect_it (void *cls, | 192 | client_disconnect_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
199 | const struct GNUNET_HashCode *key, | ||
200 | void *value) | ||
201 | { | 193 | { |
202 | if (value == cls) | 194 | if (value == cls) |
203 | { | 195 | { |
204 | GNUNET_CONTAINER_multihashmap_remove (watchers, | 196 | GNUNET_assert (GNUNET_YES == |
205 | key, | 197 | GNUNET_CONTAINER_multihashmap_remove (watchers, key, value)); |
206 | value); | ||
207 | num_clients++; | 198 | num_clients++; |
208 | } | 199 | } |
209 | return GNUNET_OK; | 200 | return GNUNET_OK; |
@@ -221,15 +212,13 @@ client_disconnect_cb (void *cls, | |||
221 | struct GNUNET_SERVICE_Client *client, | 212 | struct GNUNET_SERVICE_Client *client, |
222 | void *app_cls) | 213 | void *app_cls) |
223 | { | 214 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "A client disconnected, cleaning up.\n"); |
225 | "A client disconnected, cleaning up.\n"); | ||
226 | if (NULL != watchers) | 216 | if (NULL != watchers) |
227 | GNUNET_CONTAINER_multihashmap_iterate (watchers, | 217 | GNUNET_CONTAINER_multihashmap_iterate (watchers, |
228 | &client_disconnect_it, | 218 | &client_disconnect_it, |
229 | client); | 219 | client); |
230 | num_clients--; | 220 | num_clients--; |
231 | if ( (0 == num_clients) && | 221 | if ((0 == num_clients) && in_shutdown) |
232 | in_shutdown) | ||
233 | do_shutdown (); | 222 | do_shutdown (); |
234 | } | 223 | } |
235 | 224 | ||
@@ -255,10 +244,8 @@ record_iterator (void *cls, | |||
255 | /* No more records */ | 244 | /* No more records */ |
256 | struct GNUNET_MessageHeader *endmsg; | 245 | struct GNUNET_MessageHeader *endmsg; |
257 | 246 | ||
258 | env = GNUNET_MQ_msg (endmsg, | 247 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); |
259 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 248 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); |
260 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), | ||
261 | env); | ||
262 | if (NULL == emsg) | 249 | if (NULL == emsg) |
263 | { | 250 | { |
264 | GNUNET_SERVICE_client_continue (cls_record->client); | 251 | GNUNET_SERVICE_client_continue (cls_record->client); |
@@ -266,25 +253,23 @@ record_iterator (void *cls, | |||
266 | else | 253 | else |
267 | { | 254 | { |
268 | GNUNET_break (0); | 255 | GNUNET_break (0); |
269 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 256 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); |
270 | "Failed to iterate: %s\n", | ||
271 | emsg); | ||
272 | GNUNET_SERVICE_client_drop (cls_record->client); | 257 | GNUNET_SERVICE_client_drop (cls_record->client); |
273 | } | 258 | } |
274 | PEERSTORE_destroy_record (cls_record); | 259 | PEERSTORE_destroy_record (cls_record); |
275 | return; | 260 | return; |
276 | } | 261 | } |
277 | 262 | ||
278 | env = PEERSTORE_create_record_mq_envelope (record->sub_system, | 263 | env = PEERSTORE_create_record_mq_envelope ( |
279 | &record->peer, | 264 | record->sub_system, |
280 | record->key, | 265 | &record->peer, |
281 | record->value, | 266 | record->key, |
282 | record->value_size, | 267 | record->value, |
283 | record->expiry, | 268 | record->value_size, |
284 | 0, | 269 | record->expiry, |
285 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 270 | 0, |
286 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), | 271 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
287 | env); | 272 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); |
288 | } | 273 | } |
289 | 274 | ||
290 | 275 | ||
@@ -298,26 +283,23 @@ record_iterator (void *cls, | |||
298 | * @return #GNUNET_YES to continue iterating | 283 | * @return #GNUNET_YES to continue iterating |
299 | */ | 284 | */ |
300 | static int | 285 | static int |
301 | watch_notifier_it (void *cls, | 286 | watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) |
302 | const struct GNUNET_HashCode *key, | ||
303 | void *value) | ||
304 | { | 287 | { |
305 | struct GNUNET_PEERSTORE_Record *record = cls; | 288 | struct GNUNET_PEERSTORE_Record *record = cls; |
306 | struct GNUNET_SERVICE_Client *client = value; | 289 | struct GNUNET_SERVICE_Client *client = value; |
307 | struct GNUNET_MQ_Envelope *env; | 290 | struct GNUNET_MQ_Envelope *env; |
308 | 291 | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
310 | "Found a watcher to update.\n"); | 293 | env = PEERSTORE_create_record_mq_envelope ( |
311 | env = PEERSTORE_create_record_mq_envelope (record->sub_system, | 294 | record->sub_system, |
312 | &record->peer, | 295 | &record->peer, |
313 | record->key, | 296 | record->key, |
314 | record->value, | 297 | record->value, |
315 | record->value_size, | 298 | record->value_size, |
316 | record->expiry, | 299 | record->expiry, |
317 | 0, | 300 | 0, |
318 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 301 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
319 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 302 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
320 | env); | ||
321 | return GNUNET_YES; | 303 | return GNUNET_YES; |
322 | } | 304 | } |
323 | 305 | ||
@@ -332,10 +314,7 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
332 | { | 314 | { |
333 | struct GNUNET_HashCode keyhash; | 315 | struct GNUNET_HashCode keyhash; |
334 | 316 | ||
335 | PEERSTORE_hash_key (record->sub_system, | 317 | PEERSTORE_hash_key (record->sub_system, &record->peer, record->key, &keyhash); |
336 | &record->peer, | ||
337 | record->key, | ||
338 | &keyhash); | ||
339 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, | 318 | GNUNET_CONTAINER_multihashmap_get_multiple (watchers, |
340 | &keyhash, | 319 | &keyhash, |
341 | &watch_notifier_it, | 320 | &watch_notifier_it, |
@@ -350,17 +329,13 @@ watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
350 | * @param hm the actual message | 329 | * @param hm the actual message |
351 | */ | 330 | */ |
352 | static void | 331 | static void |
353 | handle_watch_cancel (void *cls, | 332 | handle_watch_cancel (void *cls, const struct StoreKeyHashMessage *hm) |
354 | const struct StoreKeyHashMessage *hm) | ||
355 | { | 333 | { |
356 | struct GNUNET_SERVICE_Client *client = cls; | 334 | struct GNUNET_SERVICE_Client *client = cls; |
357 | 335 | ||
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch cancel request.\n"); |
359 | "Received a watch cancel request.\n"); | ||
360 | if (GNUNET_OK != | 337 | if (GNUNET_OK != |
361 | GNUNET_CONTAINER_multihashmap_remove (watchers, | 338 | GNUNET_CONTAINER_multihashmap_remove (watchers, &hm->keyhash, client)) |
362 | &hm->keyhash, | ||
363 | client)) | ||
364 | { | 339 | { |
365 | GNUNET_break (0); | 340 | GNUNET_break (0); |
366 | GNUNET_SERVICE_client_drop (client); | 341 | GNUNET_SERVICE_client_drop (client); |
@@ -378,13 +353,11 @@ handle_watch_cancel (void *cls, | |||
378 | * @param hm the actual message | 353 | * @param hm the actual message |
379 | */ | 354 | */ |
380 | static void | 355 | static void |
381 | handle_watch (void *cls, | 356 | handle_watch (void *cls, const struct StoreKeyHashMessage *hm) |
382 | const struct StoreKeyHashMessage *hm) | ||
383 | { | 357 | { |
384 | struct GNUNET_SERVICE_Client *client = cls; | 358 | struct GNUNET_SERVICE_Client *client = cls; |
385 | 359 | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a watch request.\n"); |
387 | "Received a watch request.\n"); | ||
388 | num_clients--; /* do not count watchers */ | 361 | num_clients--; /* do not count watchers */ |
389 | GNUNET_SERVICE_client_mark_monitor (client); | 362 | GNUNET_SERVICE_client_mark_monitor (client); |
390 | GNUNET_CONTAINER_multihashmap_put (watchers, | 363 | GNUNET_CONTAINER_multihashmap_put (watchers, |
@@ -403,8 +376,7 @@ handle_watch (void *cls, | |||
403 | * @return #GNUNET_OK if @a srm is well-formed | 376 | * @return #GNUNET_OK if @a srm is well-formed |
404 | */ | 377 | */ |
405 | static int | 378 | static int |
406 | check_iterate (void *cls, | 379 | check_iterate (void *cls, const struct StoreRecordMessage *srm) |
407 | const struct StoreRecordMessage *srm) | ||
408 | { | 380 | { |
409 | struct GNUNET_PEERSTORE_Record *record; | 381 | struct GNUNET_PEERSTORE_Record *record; |
410 | 382 | ||
@@ -432,8 +404,7 @@ check_iterate (void *cls, | |||
432 | * @param srm the actual message | 404 | * @param srm the actual message |
433 | */ | 405 | */ |
434 | static void | 406 | static void |
435 | handle_iterate (void *cls, | 407 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) |
436 | const struct StoreRecordMessage *srm) | ||
437 | { | 408 | { |
438 | struct GNUNET_SERVICE_Client *client = cls; | 409 | struct GNUNET_SERVICE_Client *client = cls; |
439 | struct GNUNET_PEERSTORE_Record *record; | 410 | struct GNUNET_PEERSTORE_Record *record; |
@@ -467,8 +438,7 @@ handle_iterate (void *cls, | |||
467 | * @param success result | 438 | * @param success result |
468 | */ | 439 | */ |
469 | static void | 440 | static void |
470 | store_record_continuation (void *cls, | 441 | store_record_continuation (void *cls, int success) |
471 | int success) | ||
472 | { | 442 | { |
473 | struct GNUNET_PEERSTORE_Record *record = cls; | 443 | struct GNUNET_PEERSTORE_Record *record = cls; |
474 | 444 | ||
@@ -494,8 +464,7 @@ store_record_continuation (void *cls, | |||
494 | * @return #GNUNET_OK if @a srm is well-formed | 464 | * @return #GNUNET_OK if @a srm is well-formed |
495 | */ | 465 | */ |
496 | static int | 466 | static int |
497 | check_store (void *cls, | 467 | check_store (void *cls, const struct StoreRecordMessage *srm) |
498 | const struct StoreRecordMessage *srm) | ||
499 | { | 468 | { |
500 | struct GNUNET_PEERSTORE_Record *record; | 469 | struct GNUNET_PEERSTORE_Record *record; |
501 | 470 | ||
@@ -505,8 +474,7 @@ check_store (void *cls, | |||
505 | GNUNET_break (0); | 474 | GNUNET_break (0); |
506 | return GNUNET_SYSERR; | 475 | return GNUNET_SYSERR; |
507 | } | 476 | } |
508 | if ( (NULL == record->sub_system) || | 477 | if ((NULL == record->sub_system) || (NULL == record->key)) |
509 | (NULL == record->key) ) | ||
510 | { | 478 | { |
511 | GNUNET_break (0); | 479 | GNUNET_break (0); |
512 | PEERSTORE_destroy_record (record); | 480 | PEERSTORE_destroy_record (record); |
@@ -524,31 +492,30 @@ check_store (void *cls, | |||
524 | * @param srm the actual message | 492 | * @param srm the actual message |
525 | */ | 493 | */ |
526 | static void | 494 | static void |
527 | handle_store (void *cls, | 495 | handle_store (void *cls, const struct StoreRecordMessage *srm) |
528 | const struct StoreRecordMessage *srm) | ||
529 | { | 496 | { |
530 | struct GNUNET_SERVICE_Client *client = cls; | 497 | struct GNUNET_SERVICE_Client *client = cls; |
531 | struct GNUNET_PEERSTORE_Record *record; | 498 | struct GNUNET_PEERSTORE_Record *record; |
532 | 499 | ||
533 | record = PEERSTORE_parse_record_message (srm); | 500 | record = PEERSTORE_parse_record_message (srm); |
534 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 501 | GNUNET_log ( |
535 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", | 502 | GNUNET_ERROR_TYPE_INFO, |
536 | record->sub_system, | 503 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", |
537 | GNUNET_i2s (&record->peer), | 504 | record->sub_system, |
538 | record->key, | 505 | GNUNET_i2s (&record->peer), |
539 | (uint32_t) ntohl (srm->options)); | 506 | record->key, |
507 | (uint32_t) ntohl (srm->options)); | ||
540 | record->client = client; | 508 | record->client = client; |
541 | if (GNUNET_OK != | 509 | if (GNUNET_OK != db->store_record (db->cls, |
542 | db->store_record (db->cls, | 510 | record->sub_system, |
543 | record->sub_system, | 511 | &record->peer, |
544 | &record->peer, | 512 | record->key, |
545 | record->key, | 513 | record->value, |
546 | record->value, | 514 | record->value_size, |
547 | record->value_size, | 515 | record->expiry, |
548 | record->expiry, | 516 | ntohl (srm->options), |
549 | ntohl (srm->options), | 517 | &store_record_continuation, |
550 | &store_record_continuation, | 518 | record)) |
551 | record)) | ||
552 | { | 519 | { |
553 | GNUNET_break (0); | 520 | GNUNET_break (0); |
554 | PEERSTORE_destroy_record (record); | 521 | PEERSTORE_destroy_record (record); |
@@ -574,11 +541,10 @@ run (void *cls, | |||
574 | 541 | ||
575 | in_shutdown = GNUNET_NO; | 542 | in_shutdown = GNUNET_NO; |
576 | cfg = c; | 543 | cfg = c; |
577 | if (GNUNET_OK != | 544 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
578 | GNUNET_CONFIGURATION_get_value_string (cfg, | 545 | "peerstore", |
579 | "peerstore", | 546 | "DATABASE", |
580 | "DATABASE", | 547 | &database)) |
581 | &database)) | ||
582 | { | 548 | { |
583 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
584 | "peerstore", | 550 | "peerstore", |
@@ -586,56 +552,50 @@ run (void *cls, | |||
586 | GNUNET_SCHEDULER_shutdown (); | 552 | GNUNET_SCHEDULER_shutdown (); |
587 | return; | 553 | return; |
588 | } | 554 | } |
589 | GNUNET_asprintf (&db_lib_name, | 555 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_peerstore_%s", database); |
590 | "libgnunet_plugin_peerstore_%s", | 556 | db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); |
591 | database); | ||
592 | db = GNUNET_PLUGIN_load (db_lib_name, | ||
593 | (void *) cfg); | ||
594 | GNUNET_free (database); | 557 | GNUNET_free (database); |
595 | if (NULL == db) | 558 | if (NULL == db) |
596 | { | 559 | { |
597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
598 | _("Could not load database backend `%s'\n"), | 561 | _ ("Could not load database backend `%s'\n"), |
599 | db_lib_name); | 562 | db_lib_name); |
600 | GNUNET_SCHEDULER_shutdown (); | 563 | GNUNET_SCHEDULER_shutdown (); |
601 | return; | 564 | return; |
602 | } | 565 | } |
603 | watchers = GNUNET_CONTAINER_multihashmap_create (10, | 566 | watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
604 | GNUNET_NO); | 567 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL); |
605 | expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records, | 568 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
606 | NULL); | ||
607 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
608 | NULL); | ||
609 | } | 569 | } |
610 | 570 | ||
611 | 571 | ||
612 | /** | 572 | /** |
613 | * Define "main" method using service macro. | 573 | * Define "main" method using service macro. |
614 | */ | 574 | */ |
615 | GNUNET_SERVICE_MAIN | 575 | GNUNET_SERVICE_MAIN ( |
616 | ("peerstore", | 576 | "peerstore", |
617 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, | 577 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, |
618 | &run, | 578 | &run, |
619 | &client_connect_cb, | 579 | &client_connect_cb, |
620 | &client_disconnect_cb, | 580 | &client_disconnect_cb, |
621 | NULL, | 581 | NULL, |
622 | GNUNET_MQ_hd_var_size (store, | 582 | GNUNET_MQ_hd_var_size (store, |
623 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, | 583 | GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, |
624 | struct StoreRecordMessage, | 584 | struct StoreRecordMessage, |
625 | NULL), | 585 | NULL), |
626 | GNUNET_MQ_hd_var_size (iterate, | 586 | GNUNET_MQ_hd_var_size (iterate, |
627 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, | 587 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE, |
628 | struct StoreRecordMessage, | 588 | struct StoreRecordMessage, |
629 | NULL), | 589 | NULL), |
630 | GNUNET_MQ_hd_fixed_size (watch, | 590 | GNUNET_MQ_hd_fixed_size (watch, |
631 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, | 591 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH, |
632 | struct StoreKeyHashMessage, | 592 | struct StoreKeyHashMessage, |
633 | NULL), | 593 | NULL), |
634 | GNUNET_MQ_hd_fixed_size (watch_cancel, | 594 | GNUNET_MQ_hd_fixed_size (watch_cancel, |
635 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, | 595 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_CANCEL, |
636 | struct StoreKeyHashMessage, | 596 | struct StoreKeyHashMessage, |
637 | NULL), | 597 | NULL), |
638 | GNUNET_MQ_handler_end ()); | 598 | GNUNET_MQ_handler_end ()); |
639 | 599 | ||
640 | 600 | ||
641 | /* end of gnunet-service-peerstore.c */ | 601 | /* end of gnunet-service-peerstore.c */ |