diff options
Diffstat (limited to 'src/service/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/service/peerstore/gnunet-service-peerstore.c | 133 |
1 files changed, 93 insertions, 40 deletions
diff --git a/src/service/peerstore/gnunet-service-peerstore.c b/src/service/peerstore/gnunet-service-peerstore.c index 364900674..77523aa2e 100644 --- a/src/service/peerstore/gnunet-service-peerstore.c +++ b/src/service/peerstore/gnunet-service-peerstore.c | |||
@@ -100,6 +100,39 @@ do_shutdown () | |||
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | struct IterationContext | ||
104 | { | ||
105 | /** | ||
106 | * The record that was stored. | ||
107 | */ | ||
108 | struct GNUNET_PEERSTORE_Record *record; | ||
109 | |||
110 | /** | ||
111 | * The request ID | ||
112 | */ | ||
113 | uint32_t rid; | ||
114 | |||
115 | }; | ||
116 | |||
117 | struct StoreRecordContext | ||
118 | { | ||
119 | /** | ||
120 | * The record that was stored. | ||
121 | */ | ||
122 | struct GNUNET_PEERSTORE_Record *record; | ||
123 | |||
124 | /** | ||
125 | * The request ID | ||
126 | */ | ||
127 | uint32_t rid; | ||
128 | |||
129 | /** | ||
130 | * The client | ||
131 | */ | ||
132 | struct GNUNET_SERVICE_Client *client; | ||
133 | }; | ||
134 | |||
135 | |||
103 | /** | 136 | /** |
104 | * Task run during shutdown. | 137 | * Task run during shutdown. |
105 | * | 138 | * |
@@ -245,31 +278,37 @@ record_iterator (void *cls, | |||
245 | const struct GNUNET_PEERSTORE_Record *record, | 278 | const struct GNUNET_PEERSTORE_Record *record, |
246 | const char *emsg) | 279 | const char *emsg) |
247 | { | 280 | { |
248 | struct GNUNET_PEERSTORE_Record *cls_record = cls; | 281 | struct IterationContext *ic = cls; |
249 | struct GNUNET_MQ_Envelope *env; | 282 | struct GNUNET_MQ_Envelope *env; |
250 | 283 | ||
251 | if (NULL == record) | 284 | if (NULL == record) |
252 | { | 285 | { |
253 | /* No more records */ | 286 | /* No more records */ |
254 | struct GNUNET_MessageHeader *endmsg; | 287 | struct PeerstoreResultMessage *endmsg; |
255 | 288 | ||
256 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 289 | env = GNUNET_MQ_msg (endmsg, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); |
257 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); | 290 | endmsg->rid = ic->rid; |
258 | if (NULL == emsg) | 291 | if (NULL == emsg) |
259 | { | 292 | { |
260 | GNUNET_SERVICE_client_continue (cls_record->client); | 293 | endmsg->result = htonl (GNUNET_OK); |
294 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ic->record->client), env); | ||
295 | GNUNET_SERVICE_client_continue (ic->record->client); | ||
261 | } | 296 | } |
262 | else | 297 | else |
263 | { | 298 | { |
299 | endmsg->result = htonl (GNUNET_SYSERR); | ||
300 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ic->record->client), env); | ||
264 | GNUNET_break (0); | 301 | GNUNET_break (0); |
265 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); | 302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate: %s\n", emsg); |
266 | GNUNET_SERVICE_client_drop (cls_record->client); | 303 | GNUNET_SERVICE_client_drop (ic->record->client); |
267 | } | 304 | } |
268 | PEERSTORE_destroy_record (cls_record); | 305 | PEERSTORE_destroy_record (ic->record); |
306 | GNUNET_free (ic); | ||
269 | return; | 307 | return; |
270 | } | 308 | } |
271 | 309 | ||
272 | env = PEERSTORE_create_record_mq_envelope ( | 310 | env = PEERSTORE_create_record_mq_envelope ( |
311 | ic->rid, | ||
273 | record->sub_system, | 312 | record->sub_system, |
274 | &record->peer, | 313 | &record->peer, |
275 | record->key, | 314 | record->key, |
@@ -278,7 +317,7 @@ record_iterator (void *cls, | |||
278 | record->expiry, | 317 | record->expiry, |
279 | 0, | 318 | 0, |
280 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 319 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
281 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (cls_record->client), env); | 320 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ic->record->client), env); |
282 | } | 321 | } |
283 | 322 | ||
284 | 323 | ||
@@ -300,6 +339,7 @@ watch_notifier_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
300 | 339 | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
302 | env = PEERSTORE_create_record_mq_envelope ( | 341 | env = PEERSTORE_create_record_mq_envelope ( |
342 | 0, | ||
303 | record->sub_system, | 343 | record->sub_system, |
304 | &record->peer, | 344 | &record->peer, |
305 | record->key, | 345 | record->key, |
@@ -415,27 +455,28 @@ check_iterate (void *cls, const struct StoreRecordMessage *srm) | |||
415 | static void | 455 | static void |
416 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) | 456 | handle_iterate (void *cls, const struct StoreRecordMessage *srm) |
417 | { | 457 | { |
418 | struct GNUNET_SERVICE_Client *client = cls; | 458 | struct IterationContext *ic = GNUNET_new (struct IterationContext); |
419 | struct GNUNET_PEERSTORE_Record *record; | ||
420 | 459 | ||
421 | record = PEERSTORE_parse_record_message (srm); | 460 | ic->record = PEERSTORE_parse_record_message (srm); |
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
423 | "Iterate request: ss `%s', peer `%s', key `%s'\n", | 462 | "Iterate request: ss `%s', peer `%s', key `%s'\n", |
424 | record->sub_system, | 463 | ic->record->sub_system, |
425 | GNUNET_i2s (&record->peer), | 464 | GNUNET_i2s (&ic->record->peer), |
426 | (NULL == record->key) ? "NULL" : record->key); | 465 | (NULL == ic->record->key) ? "NULL" : ic->record->key); |
427 | record->client = client; | 466 | ic->record->client = cls; |
467 | ic->rid = srm->rid; | ||
428 | if (GNUNET_OK != | 468 | if (GNUNET_OK != |
429 | db->iterate_records (db->cls, | 469 | db->iterate_records (db->cls, |
430 | record->sub_system, | 470 | ic->record->sub_system, |
431 | (ntohs (srm->peer_set)) ? &record->peer : NULL, | 471 | (ntohs (srm->peer_set)) ? &ic->record->peer : NULL, |
432 | record->key, | 472 | ic->record->key, |
433 | &record_iterator, | 473 | &record_iterator, |
434 | record)) | 474 | ic)) |
435 | { | 475 | { |
436 | GNUNET_break (0); | 476 | GNUNET_break (0); |
437 | GNUNET_SERVICE_client_drop (client); | 477 | GNUNET_SERVICE_client_drop (ic->record->client); |
438 | PEERSTORE_destroy_record (record); | 478 | PEERSTORE_destroy_record (ic->record); |
479 | GNUNET_free (ic); | ||
439 | } | 480 | } |
440 | } | 481 | } |
441 | 482 | ||
@@ -449,19 +490,28 @@ handle_iterate (void *cls, const struct StoreRecordMessage *srm) | |||
449 | static void | 490 | static void |
450 | store_record_continuation (void *cls, int success) | 491 | store_record_continuation (void *cls, int success) |
451 | { | 492 | { |
452 | struct GNUNET_PEERSTORE_Record *record = cls; | 493 | struct StoreRecordContext *src = cls; |
494 | struct PeerstoreResultMessage *msg; | ||
495 | struct GNUNET_MQ_Envelope *env; | ||
453 | 496 | ||
454 | if (GNUNET_OK == success) | 497 | if (GNUNET_OK == success) |
455 | { | 498 | { |
456 | watch_notifier (record); | 499 | |
457 | GNUNET_SERVICE_client_continue (record->client); | 500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); |
501 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT); | ||
502 | msg->rid = src->rid; | ||
503 | msg->result = htonl (success); | ||
504 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (src->client), env); | ||
505 | watch_notifier (src->record); | ||
506 | GNUNET_SERVICE_client_continue (src->client); | ||
458 | } | 507 | } |
459 | else | 508 | else |
460 | { | 509 | { |
461 | GNUNET_break (0); | 510 | GNUNET_break (0); |
462 | GNUNET_SERVICE_client_drop (record->client); | 511 | GNUNET_SERVICE_client_drop (src->record->client); |
463 | } | 512 | } |
464 | PEERSTORE_destroy_record (record); | 513 | PEERSTORE_destroy_record (src->record); |
514 | GNUNET_free (src); | ||
465 | } | 515 | } |
466 | 516 | ||
467 | 517 | ||
@@ -504,35 +554,38 @@ static void | |||
504 | handle_store (void *cls, const struct StoreRecordMessage *srm) | 554 | handle_store (void *cls, const struct StoreRecordMessage *srm) |
505 | { | 555 | { |
506 | struct GNUNET_SERVICE_Client *client = cls; | 556 | struct GNUNET_SERVICE_Client *client = cls; |
507 | struct GNUNET_PEERSTORE_Record *record; | 557 | struct StoreRecordContext *src = GNUNET_new (struct StoreRecordContext); |
508 | 558 | src->record = PEERSTORE_parse_record_message (srm); | |
509 | record = PEERSTORE_parse_record_message (srm); | ||
510 | GNUNET_log ( | 559 | GNUNET_log ( |
511 | GNUNET_ERROR_TYPE_DEBUG, | 560 | GNUNET_ERROR_TYPE_DEBUG, |
512 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", | 561 | "Received a store request. Sub system `%s' Peer `%s Key `%s' Options: %u.\n", |
513 | record->sub_system, | 562 | src->record->sub_system, |
514 | GNUNET_i2s (&record->peer), | 563 | GNUNET_i2s (&src->record->peer), |
515 | record->key, | 564 | src->record->key, |
516 | (uint32_t) ntohl (srm->options)); | 565 | (uint32_t) ntohl (srm->options)); |
517 | record->client = client; | 566 | src->record->client = client; |
567 | src->rid = srm->rid; | ||
568 | src->client = client; | ||
518 | if (GNUNET_OK != db->store_record (db->cls, | 569 | if (GNUNET_OK != db->store_record (db->cls, |
519 | record->sub_system, | 570 | src->record->sub_system, |
520 | &record->peer, | 571 | &src->record->peer, |
521 | record->key, | 572 | src->record->key, |
522 | record->value, | 573 | src->record->value, |
523 | record->value_size, | 574 | src->record->value_size, |
524 | record->expiry, | 575 | src->record->expiry, |
525 | ntohl (srm->options), | 576 | ntohl (srm->options), |
526 | &store_record_continuation, | 577 | &store_record_continuation, |
527 | record)) | 578 | src)) |
528 | { | 579 | { |
529 | GNUNET_break (0); | 580 | GNUNET_break (0); |
530 | PEERSTORE_destroy_record (record); | 581 | PEERSTORE_destroy_record (src->record); |
582 | GNUNET_free (src); | ||
531 | GNUNET_SERVICE_client_drop (client); | 583 | GNUNET_SERVICE_client_drop (client); |
532 | return; | 584 | return; |
533 | } | 585 | } |
534 | } | 586 | } |
535 | 587 | ||
588 | |||
536 | static void | 589 | static void |
537 | store_hello_continuation (void *cls, int success) | 590 | store_hello_continuation (void *cls, int success) |
538 | { | 591 | { |