aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/datastore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/datastore_api.c')
-rw-r--r--src/datastore/datastore_api.c72
1 files changed, 54 insertions, 18 deletions
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index cb70cc1f3..fb1939cd9 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -143,23 +143,26 @@ transmit_drop (void *cls,
143void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, 143void GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h,
144 int drop) 144 int drop)
145{ 145{
146 GNUNET_assert (0 == h->message_size); 146 if (h->client != NULL)
147 GNUNET_assert (NULL == h->response_proc); 147 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
148 if ( (GNUNET_YES == drop) && 148 h->client = NULL;
149 (h->client != NULL) ) 149 if (GNUNET_YES == drop)
150 { 150 {
151 if (NULL != 151 h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
152 GNUNET_CLIENT_notify_transmit_ready (h->client, 152 if (h->client != NULL)
153 sizeof(struct GNUNET_MessageHeader), 153 {
154 GNUNET_TIME_UNIT_MINUTES, 154 if (NULL !=
155 GNUNET_YES, 155 GNUNET_CLIENT_notify_transmit_ready (h->client,
156 &transmit_drop, 156 sizeof(struct GNUNET_MessageHeader),
157 h)) 157 GNUNET_TIME_UNIT_MINUTES,
158 return; 158 GNUNET_YES,
159 &transmit_drop,
160 h))
161 return;
162 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
163 }
159 GNUNET_break (0); 164 GNUNET_break (0);
160 } 165 }
161 if (h->client != NULL)
162 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
163 GNUNET_ARM_stop_services (h->cfg, h->sched, "datastore", NULL); 166 GNUNET_ARM_stop_services (h->cfg, h->sched, "datastore", NULL);
164 GNUNET_free (h); 167 GNUNET_free (h);
165} 168}
@@ -445,6 +448,22 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
445} 448}
446 449
447 450
451/**
452 * Helper function that will initiate the transmission of a message to
453 * the datastore service. The message must already be prepared and
454 * stored in the buffer at the end of the handle. The message must be
455 * of a type that expects a "DataMessage" in response.
456 *
457 * @param h handle to the service with prepared message
458 * @param cont function to call with result
459 * @param cont_cls closure
460 * @param timeout timeout for the operation
461 */
462static void
463transmit_for_result (struct GNUNET_DATASTORE_Handle *h,
464 GNUNET_DATASTORE_Iterator cont,
465 void *cont_cls,
466 struct GNUNET_TIME_Relative timeout);
448 467
449 468
450/** 469/**
@@ -464,18 +483,35 @@ with_result_response_handler (void *cls,
464 GNUNET_DATASTORE_Iterator cont = h->response_proc; 483 GNUNET_DATASTORE_Iterator cont = h->response_proc;
465 const struct DataMessage *dm; 484 const struct DataMessage *dm;
466 size_t msize; 485 size_t msize;
486 struct GNUNET_TIME_Relative remaining;
467 487
468 h->message_size = 0;
469 if (msg == NULL) 488 if (msg == NULL)
470 { 489 {
490#if DEBUG_DATASTORE
491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 "Got disconnected from datastore\n");
493#endif
471 h->response_proc = NULL; 494 h->response_proc = NULL;
472 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); 495 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
473 h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg); 496 h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
474 cont (h->response_proc_cls, 497 remaining = GNUNET_TIME_absolute_get_remaining (h->timeout);
475 NULL, 0, NULL, 0, 0, 0, 498 if (remaining.value > 0)
476 GNUNET_TIME_UNIT_ZERO_ABS, 0); 499 {
500 transmit_for_result (h,
501 cont,
502 h->response_proc_cls,
503 remaining);
504 }
505 else
506 {
507 h->message_size = 0;
508 cont (h->response_proc_cls,
509 NULL, 0, NULL, 0, 0, 0,
510 GNUNET_TIME_UNIT_ZERO_ABS, 0);
511 }
477 return; 512 return;
478 } 513 }
514 h->message_size = 0;
479 if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END) 515 if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
480 { 516 {
481 GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); 517 GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));