aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/peerstore_api.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-06-03 13:50:37 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-06-03 13:50:37 +0000
commita04d70028c0615e7910f68328db9c61bba67128b (patch)
tree8d27cc7e8ad6b25cf01ac2cbae6f2839deec00f8 /src/peerstore/peerstore_api.c
parenteb985bf2eae6054292e3cbffbfeb4aaea3e394d5 (diff)
downloadgnunet-a04d70028c0615e7910f68328db9c61bba67128b.tar.gz
gnunet-a04d70028c0615e7910f68328db9c61bba67128b.zip
peerstore: fixes in watch functionality
Diffstat (limited to 'src/peerstore/peerstore_api.c')
-rw-r--r--src/peerstore/peerstore_api.c78
1 files changed, 12 insertions, 66 deletions
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index 8748625b7..62b4c3705 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -117,12 +117,6 @@ struct GNUNET_PEERSTORE_StoreContext
117 */ 117 */
118 void *cont_cls; 118 void *cont_cls;
119 119
120 /**
121 * #GNUNET_YES / #GNUNET_NO
122 * if sent, cannot be canceled
123 */
124 int request_sent;
125
126}; 120};
127 121
128/** 122/**
@@ -227,14 +221,6 @@ struct GNUNET_PEERSTORE_WatchContext
227/******************************************************************************/ 221/******************************************************************************/
228 222
229/** 223/**
230 * When a response for store request is received
231 *
232 * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
233 * @param msg message received, NULL on timeout or fatal error
234 */
235void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg);
236
237/**
238 * When a response for iterate request is received 224 * When a response for iterate request is received
239 * 225 *
240 * @param cls a 'struct GNUNET_PEERSTORE_Handle *' 226 * @param cls a 'struct GNUNET_PEERSTORE_Handle *'
@@ -262,7 +248,6 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h);
262 * MQ message handlers 248 * MQ message handlers
263 */ 249 */
264static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { 250static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
265 {&handle_store_result, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK, sizeof(struct GNUNET_MessageHeader)},
266 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0}, 251 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD, 0},
267 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)}, 252 {&handle_iterate_result, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END, sizeof(struct GNUNET_MessageHeader)},
268 {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0}, 253 {&handle_watch_result, GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD, 0},
@@ -376,42 +361,6 @@ GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
376/******************************************************************************/ 361/******************************************************************************/
377 362
378/** 363/**
379 * When a response for store request is received
380 *
381 * @param cls a 'struct GNUNET_PEERSTORE_Handle *'
382 * @param msg message received, NULL on timeout or fatal error
383 */
384void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
385{
386 struct GNUNET_PEERSTORE_Handle *h = cls;
387 struct GNUNET_PEERSTORE_StoreContext *sc;
388 GNUNET_PEERSTORE_Continuation cont;
389 void *cont_cls;
390
391 sc = h->store_head;
392 if(NULL == sc)
393 {
394 LOG(GNUNET_ERROR_TYPE_ERROR, "Unexpected store response, this should not happen.\n");
395 reconnect(h);
396 return;
397 }
398 cont = sc->cont;
399 cont_cls = sc->cont_cls;
400 GNUNET_CONTAINER_DLL_remove(h->store_head, h->store_tail, sc);
401 GNUNET_free(sc);
402 if(NULL == msg) /* Connection error */
403 {
404 if(NULL != cont)
405 cont(cont_cls, GNUNET_SYSERR);
406 reconnect(h);
407 return;
408 }
409 if(NULL != cont) /* Run continuation */
410 cont(cont_cls, GNUNET_OK);
411
412}
413
414/**
415 * Callback after MQ envelope is sent 364 * Callback after MQ envelope is sent
416 * 365 *
417 * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *' 366 * @param cls a 'struct GNUNET_PEERSTORE_StoreContext *'
@@ -419,9 +368,15 @@ void handle_store_result (void *cls, const struct GNUNET_MessageHeader *msg)
419void store_request_sent (void *cls) 368void store_request_sent (void *cls)
420{ 369{
421 struct GNUNET_PEERSTORE_StoreContext *sc = cls; 370 struct GNUNET_PEERSTORE_StoreContext *sc = cls;
371 GNUNET_PEERSTORE_Continuation cont;
372 void *cont_cls;
422 373
423 sc->request_sent = GNUNET_YES;
424 sc->ev = NULL; 374 sc->ev = NULL;
375 cont = sc->cont;
376 cont_cls = sc->cont_cls;
377 GNUNET_PEERSTORE_store_cancel(sc);
378 if(NULL != cont)
379 cont(cont_cls, GNUNET_OK);
425} 380}
426 381
427/** 382/**
@@ -434,21 +389,13 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc)
434{ 389{
435 LOG(GNUNET_ERROR_TYPE_DEBUG, 390 LOG(GNUNET_ERROR_TYPE_DEBUG,
436 "Canceling store request.\n"); 391 "Canceling store request.\n");
437 if(GNUNET_NO == sc->request_sent) 392 if(NULL != sc->ev)
438 { 393 {
439 if(NULL != sc->ev) 394 GNUNET_MQ_send_cancel(sc->ev);
440 { 395 sc->ev = NULL;
441 GNUNET_MQ_send_cancel(sc->ev);
442 sc->ev = NULL;
443 }
444 GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc);
445 GNUNET_free(sc);
446 }
447 else
448 { /* request already sent, will have to wait for response */
449 sc->cont = NULL;
450 } 396 }
451 397 GNUNET_CONTAINER_DLL_remove(sc->h->store_head, sc->h->store_tail, sc);
398 GNUNET_free(sc);
452} 399}
453 400
454/** 401/**
@@ -493,7 +440,6 @@ GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h,
493 sc->cont = cont; 440 sc->cont = cont;
494 sc->cont_cls = cont_cls; 441 sc->cont_cls = cont_cls;
495 sc->h = h; 442 sc->h = h;
496 sc->request_sent = GNUNET_NO;
497 GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc); 443 GNUNET_CONTAINER_DLL_insert(h->store_head, h->store_tail, sc);
498 GNUNET_MQ_notify_sent(ev, &store_request_sent, sc); 444 GNUNET_MQ_notify_sent(ev, &store_request_sent, sc);
499 GNUNET_MQ_send(h->mq, ev); 445 GNUNET_MQ_send(h->mq, ev);