aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/peerstore_api.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-05-31 21:48:01 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-05-31 21:48:01 +0000
commit805d4a3556dee6d13ad5a9439b7a4a9ef3f9ab46 (patch)
tree63473a907807a2aadb7780353b4ad34ee6a041fa /src/peerstore/peerstore_api.c
parent95cdeb5c0bb1f14f3959863e6bf4675db48ea177 (diff)
downloadgnunet-805d4a3556dee6d13ad5a9439b7a4a9ef3f9ab46.tar.gz
gnunet-805d4a3556dee6d13ad5a9439b7a4a9ef3f9ab46.zip
peerstore: watch functionality
Diffstat (limited to 'src/peerstore/peerstore_api.c')
-rw-r--r--src/peerstore/peerstore_api.c68
1 files changed, 16 insertions, 52 deletions
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index c9a68f4bf..8748625b7 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -263,7 +263,6 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h);
263 */ 263 */
264static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { 264static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
265 {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)}, 265 {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)},
266 {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL, sizeof(struct GNUNET_MessageHeader)},
267 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0}, 266 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0},
268 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)}, 267 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)},
269 {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0}, 268 {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0},
@@ -386,7 +385,6 @@ void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
386{ 385{
387 struct GNUNET_PEERSTORE_Handle *h = cls; 386 struct GNUNET_PEERSTORE_Handle *h = cls;
388 struct GNUNET_PEERSTORE_StoreContext *sc; 387 struct GNUNET_PEERSTORE_StoreContext *sc;
389 uint16_t msg_type;
390 GNUNET_PEERSTORE_Continuation cont; 388 GNUNET_PEERSTORE_Continuation cont;
391 void *cont_cls; 389 void *cont_cls;
392 390
@@ -409,13 +407,7 @@ void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
409 return; 407 return;
410 } 408 }
411 if(NULL != cont) /* Run continuation */ 409 if(NULL != cont) /* Run continuation */
412 { 410 cont(cont_cls, GNUNET_OK);
413 msg_type = ntohs(msg->type);
414 if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK == msg_type)
415 cont(cont_cls, GNUNET_OK);
416 else if(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_FAIL == msg_type)
417 cont(cont_cls, GNUNET_SYSERR);
418 }
419 411
420} 412}
421 413
@@ -681,54 +673,26 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h,
681 */ 673 */
682void handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg) 674void handle_watch_result (void *cls, const struct GNUNET_MessageHeader *msg)
683{ 675{
684 /*struct GNUNET_PEERSTORE_Handle *h = cls; 676 struct GNUNET_PEERSTORE_Handle *h = cls;
685 struct GNUNET_PEERSTORE_WatchContext *wc;
686 GNUNET_PEERSTORE_Processor callback;
687 void *callback_cls;
688
689
690
691 struct GNUNET_PEERSTORE_IterateContext *ic;
692 uint16_t msg_type;
693 struct GNUNET_PEERSTORE_Record *record; 677 struct GNUNET_PEERSTORE_Record *record;
694 int continue_iter; 678 struct GNUNET_HashCode keyhash;
679 struct GNUNET_PEERSTORE_WatchContext *wc;
695 680
696 ic = h->iterate_head; 681 if(NULL == msg)
697 if(NULL == ic)
698 {
699 LOG(GNUNET_ERROR_TYPE_ERROR, "Unexpected iteration response, this should not happen.\n");
700 reconnect(h);
701 return;
702 }
703 callback = ic->callback;
704 callback_cls = ic->callback_cls;
705 if(NULL == msg) * Connection error *
706 { 682 {
707 683 LOG(GNUNET_ERROR_TYPE_ERROR,
708 if(NULL != callback) 684 "Problem receiving a watch response, no way to determine which request.\n");
709 callback(callback_cls, NULL,
710 _("Error communicating with `PEERSTORE' service."));
711 reconnect(h); 685 reconnect(h);
712 return; 686 return;
713 } 687 }
714 msg_type = ntohs(msg->type); 688 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received a watch record from service.\n");
715 if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) 689 record = PEERSTORE_parse_record_message(msg);
716 { 690 PEERSTORE_hash_key(record->sub_system,
717 GNUNET_PEERSTORE_iterate_cancel(ic); 691 record->peer, record->key, &keyhash);
718 if(NULL != callback) 692 wc = GNUNET_CONTAINER_multihashmap_get(h->watches, &keyhash);
719 callback(callback_cls, NULL, NULL); 693 if(NULL != wc->callback)
720 return; 694 wc->callback(wc->callback_cls, record, NULL);
721 } 695 /* TODO: destroy record */
722 if(NULL != callback)
723 {
724 record = PEERSTORE_parse_record_message(msg);
725 if(NULL == record)
726 continue_iter = callback(callback_cls, record, _("Received a malformed response from service."));
727 else
728 continue_iter = callback(callback_cls, record, NULL);
729 if(GNUNET_NO == continue_iter)
730 ic->callback = NULL;
731 }*/
732} 696}
733 697
734/** 698/**
@@ -809,7 +773,7 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h,
809 if(NULL == h->watches) 773 if(NULL == h->watches)
810 h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO); 774 h->watches = GNUNET_CONTAINER_multihashmap_create(5, GNUNET_NO);
811 GNUNET_CONTAINER_multihashmap_put(h->watches, &wc->keyhash, 775 GNUNET_CONTAINER_multihashmap_put(h->watches, &wc->keyhash,
812 wc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 776 wc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
813 LOG(GNUNET_ERROR_TYPE_DEBUG, 777 LOG(GNUNET_ERROR_TYPE_DEBUG,
814 "Sending a watch request for sub system `%s'.\n", sub_system); 778 "Sending a watch request for sub system `%s'.\n", sub_system);
815 GNUNET_MQ_notify_sent(ev, &watch_request_sent, wc); 779 GNUNET_MQ_notify_sent(ev, &watch_request_sent, wc);