- * @param cls closure
- * @param msg message received, NULL on timeout or fatal error
- */
-static void
-with_result_response_handler (void *cls,
- const struct
- GNUNET_MessageHeader * msg)
-{
- struct GNUNET_DATASTORE_Handle *h = cls;
- GNUNET_DATASTORE_Iterator cont = h->response_proc;
- const struct DataMessage *dm;
- size_t msize;
- struct GNUNET_TIME_Relative remaining;
-
- if (msg == NULL)
- {
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got disconnected from datastore\n");
-#endif
- h->response_proc = NULL;
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
- remaining = GNUNET_TIME_absolute_get_remaining (h->timeout);
- if (remaining.value > 0)
- {
- transmit_for_result (h,
- cont,
- h->response_proc_cls,
- remaining);
- }
- else
- {
- h->message_size = 0;
- cont (h->response_proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- }
- return;
- }
- h->message_size = 0;
- if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
- {
- GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
- h->response_proc = NULL;
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of result set\n");
-#endif
- cont (h->response_proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- if ( (ntohs(msg->size) < sizeof(struct DataMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) )
- {
- GNUNET_break (0);
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
- h->response_proc = NULL;
- cont (h->response_proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- dm = (const struct DataMessage*) msg;
- msize = ntohl(dm->size);
- if (ntohs(msg->size) != msize + sizeof(struct DataMessage))
- {
- GNUNET_break (0);
- GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
- h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
- h->response_proc = NULL;
- cont (h->response_proc_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received result %llu with type %u and size %u with key %s\n",
- (unsigned long long) GNUNET_ntohll(dm->uid),
- ntohl(dm->type),
- msize,
- GNUNET_h2s(&dm->key));
-#endif
- cont (h->response_proc_cls,
- &dm->key,
- msize,
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- GNUNET_ntohll(dm->uid));
-}
-
-
-/**
- * Function called to trigger obtaining the next result
- * from the datastore.
- *