diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-05-18 14:01:27 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-05-18 14:01:27 +0000 |
commit | 47ee00dc6c361eb6acc1c0b123b6bfba7eb01c05 (patch) | |
tree | f558ad93c1f44e7615aa1e748b87657080a8e5e4 /src/peerstore | |
parent | 4c1a6478b3ae43bb009addd982390a5db949913b (diff) | |
download | gnunet-47ee00dc6c361eb6acc1c0b123b6bfba7eb01c05.tar.gz gnunet-47ee00dc6c361eb6acc1c0b123b6bfba7eb01c05.zip |
peerstore: towards iterate functionality
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 1 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 27 | ||||
-rw-r--r-- | src/peerstore/plugin_peerstore_sqlite.c | 2 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api.c | 1 |
4 files changed, 20 insertions, 11 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index fa674e1ad..ea6268bf1 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -120,6 +120,7 @@ void handle_iterate (void *cls, | |||
120 | struct GNUNET_PEERSTORE_Record *record; | 120 | struct GNUNET_PEERSTORE_Record *record; |
121 | struct GNUNET_SERVER_TransmitContext *tc; | 121 | struct GNUNET_SERVER_TransmitContext *tc; |
122 | 122 | ||
123 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request from client.\n"); | ||
123 | record = PEERSTORE_parse_record_message(message); | 124 | record = PEERSTORE_parse_record_message(message); |
124 | if(NULL == record) | 125 | if(NULL == record) |
125 | { | 126 | { |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 81d6c78a6..d6acd2daf 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -211,7 +211,7 @@ handle_client_error (void *cls, enum GNUNET_MQ_Error error) | |||
211 | { | 211 | { |
212 | struct GNUNET_PEERSTORE_Handle *h = cls; | 212 | struct GNUNET_PEERSTORE_Handle *h = cls; |
213 | 213 | ||
214 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Received an error notification from MQ of type: %d\n", error); | 214 | LOG(GNUNET_ERROR_TYPE_ERROR, "Received an error notification from MQ of type: %d\n", error); |
215 | reconnect(h); | 215 | reconnect(h); |
216 | } | 216 | } |
217 | 217 | ||
@@ -342,7 +342,7 @@ void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
342 | sc = h->store_head; | 342 | sc = h->store_head; |
343 | if(NULL == sc) | 343 | if(NULL == sc) |
344 | { | 344 | { |
345 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unexpected store response, this should not happen.\n"); | 345 | LOG(GNUNET_ERROR_TYPE_ERROR, "Unexpected store response, this should not happen.\n"); |
346 | reconnect(h); | 346 | reconnect(h); |
347 | return; | 347 | return; |
348 | } | 348 | } |
@@ -389,13 +389,13 @@ void store_request_sent (void *cls) | |||
389 | void | 389 | void |
390 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 390 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) |
391 | { | 391 | { |
392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 392 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
393 | "Canceling store request.\n"); | 393 | "Canceling store request.\n"); |
394 | if(GNUNET_NO == sc->request_sent) | 394 | if(GNUNET_NO == sc->request_sent) |
395 | { | 395 | { |
396 | if(NULL != sc->ev) | 396 | if(NULL != sc->ev) |
397 | { | 397 | { |
398 | //GNUNET_MQ_discard(sc->ev); //FIXME: this should be GNUNET_MQ_send_cancel | 398 | GNUNET_MQ_send_cancel(sc->ev); |
399 | sc->ev = NULL; | 399 | sc->ev = NULL; |
400 | } | 400 | } |
401 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); | 401 | GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc); |
@@ -476,11 +476,12 @@ void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
476 | void *callback_cls; | 476 | void *callback_cls; |
477 | uint16_t msg_type; | 477 | uint16_t msg_type; |
478 | struct GNUNET_PEERSTORE_Record *record; | 478 | struct GNUNET_PEERSTORE_Record *record; |
479 | int continue_iter; | ||
479 | 480 | ||
480 | ic = h->iterate_head; | 481 | ic = h->iterate_head; |
481 | if(NULL == ic) | 482 | if(NULL == ic) |
482 | { | 483 | { |
483 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Unexpected iteration response, this should not happen.\n"); | 484 | LOG(GNUNET_ERROR_TYPE_ERROR, "Unexpected iteration response, this should not happen.\n"); |
484 | reconnect(h); | 485 | reconnect(h); |
485 | return; | 486 | return; |
486 | } | 487 | } |
@@ -498,19 +499,21 @@ void handle_iterate_result (void *cls, const struct GNUNET_MessageHeader *msg) | |||
498 | msg_type = ntohs(msg->type); | 499 | msg_type = ntohs(msg->type); |
499 | if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) | 500 | if(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END == msg_type) |
500 | { | 501 | { |
501 | if(NULL != callback) | ||
502 | callback(callback_cls, NULL, NULL); | ||
503 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); | 502 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); |
504 | GNUNET_free(ic); | 503 | GNUNET_free(ic); |
504 | if(NULL != callback) | ||
505 | callback(callback_cls, NULL, NULL); | ||
505 | return; | 506 | return; |
506 | } | 507 | } |
507 | if(NULL != callback) | 508 | if(NULL != callback) |
508 | { | 509 | { |
509 | record = PEERSTORE_parse_record_message(msg); | 510 | record = PEERSTORE_parse_record_message(msg); |
510 | if(NULL == record) | 511 | if(NULL == record) |
511 | callback(callback_cls, record, _("Received a malformed response from service.")); | 512 | continue_iter = callback(callback_cls, record, _("Received a malformed response from service.")); |
512 | else | 513 | else |
513 | callback(callback_cls, record, NULL); | 514 | continue_iter = callback(callback_cls, record, NULL); |
515 | if(GNUNET_NO == continue_iter) | ||
516 | ic->callback = NULL; | ||
514 | } | 517 | } |
515 | 518 | ||
516 | } | 519 | } |
@@ -524,6 +527,7 @@ void iterate_request_sent (void *cls) | |||
524 | { | 527 | { |
525 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; | 528 | struct GNUNET_PEERSTORE_IterateContext *ic = cls; |
526 | 529 | ||
530 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Iterate request sent to service.\n"); | ||
527 | ic->request_sent = GNUNET_YES; | 531 | ic->request_sent = GNUNET_YES; |
528 | ic->ev = NULL; | 532 | ic->ev = NULL; |
529 | } | 533 | } |
@@ -537,11 +541,12 @@ void iterate_request_sent (void *cls) | |||
537 | void | 541 | void |
538 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 542 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) |
539 | { | 543 | { |
544 | LOG(GNUNET_ERROR_TYPE_DEBUG, "User request cancel of iterate request.\n"); | ||
540 | if(GNUNET_NO == ic->request_sent) | 545 | if(GNUNET_NO == ic->request_sent) |
541 | { | 546 | { |
542 | if(NULL != ic->ev) | 547 | if(NULL != ic->ev) |
543 | { | 548 | { |
544 | //GNUNET_MQ_discard(ic->ev); //FIXME: this should be GNUNET_MQ_send_cancel | 549 | GNUNET_MQ_send_cancel(ic->ev); |
545 | ic->ev = NULL; | 550 | ic->ev = NULL; |
546 | } | 551 | } |
547 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); | 552 | GNUNET_CONTAINER_DLL_remove(ic->h->iterate_head, ic->h->iterate_tail, ic); |
@@ -587,6 +592,8 @@ GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, | |||
587 | ic->h = h; | 592 | ic->h = h; |
588 | ic->request_sent = GNUNET_NO; | 593 | ic->request_sent = GNUNET_NO; |
589 | GNUNET_CONTAINER_DLL_insert(h->iterate_head, h->iterate_tail, ic); | 594 | GNUNET_CONTAINER_DLL_insert(h->iterate_head, h->iterate_tail, ic); |
595 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
596 | "Sending an iterate request for sub system `%s'\n", sub_system); | ||
590 | GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ev); | 597 | GNUNET_MQ_notify_sent(ev, &iterate_request_sent, ev); |
591 | GNUNET_MQ_send(h->mq, ev); | 598 | GNUNET_MQ_send(h->mq, ev); |
592 | return ic; | 599 | return ic; |
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index 1ae8301b2..9d044aa07 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c | |||
@@ -124,6 +124,7 @@ peerstore_sqlite_iterate_records (void *cls, | |||
124 | int sret; | 124 | int sret; |
125 | struct GNUNET_PEERSTORE_Record *ret; | 125 | struct GNUNET_PEERSTORE_Record *ret; |
126 | 126 | ||
127 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Executing iterate request on sqlite db.\n"); | ||
127 | if(NULL == peer && NULL == key) | 128 | if(NULL == peer && NULL == key) |
128 | { | 129 | { |
129 | stmt = plugin->select_peerstoredata; | 130 | stmt = plugin->select_peerstoredata; |
@@ -161,6 +162,7 @@ peerstore_sqlite_iterate_records (void *cls, | |||
161 | } | 162 | } |
162 | while (SQLITE_ROW == (sret = sqlite3_step (stmt))) | 163 | while (SQLITE_ROW == (sret = sqlite3_step (stmt))) |
163 | { | 164 | { |
165 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Returning a matched record.\n"); | ||
164 | ret = GNUNET_new(struct GNUNET_PEERSTORE_Record); | 166 | ret = GNUNET_new(struct GNUNET_PEERSTORE_Record); |
165 | ret->sub_system = (char *)sqlite3_column_text(stmt, 0); | 167 | ret->sub_system = (char *)sqlite3_column_text(stmt, 0); |
166 | ret->peer = (struct GNUNET_PeerIdentity *)sqlite3_column_blob(stmt, 1); | 168 | ret->peer = (struct GNUNET_PeerIdentity *)sqlite3_column_blob(stmt, 1); |
diff --git a/src/peerstore/test_peerstore_api.c b/src/peerstore/test_peerstore_api.c index f13239abb..a26ed7969 100644 --- a/src/peerstore/test_peerstore_api.c +++ b/src/peerstore/test_peerstore_api.c | |||
@@ -82,7 +82,6 @@ run (void *cls, | |||
82 | struct GNUNET_PeerIdentity pid; | 82 | struct GNUNET_PeerIdentity pid; |
83 | char *val = "peerstore-test-value"; | 83 | char *val = "peerstore-test-value"; |
84 | size_t val_size = strlen(val); | 84 | size_t val_size = strlen(val); |
85 | struct GNUNET_PEERSTORE_StoreContext *sc; | ||
86 | 85 | ||
87 | ok = 0; | 86 | ok = 0; |
88 | memset (&pid, 32, sizeof (pid)); | 87 | memset (&pid, 32, sizeof (pid)); |