- * Type of a function to call when we receive a message
- * from the service.
- *
- * @param cls closure
- * @param msg message received, NULL on timeout or fatal error
- */
-static void
-process_result_message (void *cls,
- const struct GNUNET_MessageHeader * msg)
-{
- struct GNUNET_DATASTORE_QueueEntry *qe = cls;
- struct GNUNET_DATASTORE_Handle *h = qe->h;
- struct ResultContext rc = qe->qc.rc;
- const struct DataMessage *dm;
- int was_transmitted;
-
- h->in_receive = GNUNET_NO;
- if (msg == NULL)
- {
- was_transmitted = qe->was_transmitted;
- free_queue_entry (qe);
- if (was_transmitted == GNUNET_YES)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to receive response from database.\n"));
- do_disconnect (h);
- }
- if (rc.iter != NULL)
- rc.iter (rc.iter_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- GNUNET_assert (GNUNET_YES == qe->was_transmitted);
- GNUNET_assert (h->queue_head == qe);
- if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END)
- {
- GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader));
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received end of result set\n");
-#endif
- free_queue_entry (qe);
- if (rc.iter != NULL)
- rc.iter (rc.iter_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- process_queue (h);
- return;
- }
- if ( (ntohs(msg->size) < sizeof(struct DataMessage)) ||
- (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) ||
- (ntohs(msg->size) != sizeof(struct DataMessage) + ntohl (((const struct DataMessage*)msg)->size)) )
- {
- GNUNET_break (0);
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- if (rc.iter != NULL)
- rc.iter (rc.iter_cls,
- NULL, 0, NULL, 0, 0, 0,
- GNUNET_TIME_UNIT_ZERO_ABS, 0);
- return;
- }
- if (rc.iter == NULL)
- {
- /* abort iteration */
-#if DEBUG_DATASTORE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Aborting iteration via disconnect (client has cancelled)\n");
-#endif
- free_queue_entry (qe);
- h->retry_time = GNUNET_TIME_UNIT_ZERO;
- do_disconnect (h);
- return;
- }
- dm = (const struct DataMessage*) msg;
-#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),
- ntohl(dm->size),
- GNUNET_h2s(&dm->key));
-#endif
- rc.iter (rc.iter_cls,
- &dm->key,
- ntohl(dm->size),
- &dm[1],
- ntohl(dm->type),
- ntohl(dm->priority),
- ntohl(dm->anonymity),
- GNUNET_TIME_absolute_ntoh(dm->expiration),
- GNUNET_ntohll(dm->uid));
-}
-
-
-/**
- * Get a random value from the datastore.