/*
This file is part of GNUnet
(C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file datastore/datastore_api.c
* @brief Management for the datastore for files stored on a GNUnet node. Implements
* a priority queue for requests (with timeouts).
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_arm_service.h"
#include "gnunet_constants.h"
#include "gnunet_datastore_service.h"
#include "gnunet_statistics_service.h"
#include "datastore.h"
#define LOG(kind,...) GNUNET_log_from (kind, "datastore-api",__VA_ARGS__)
/**
* Collect an instane number of statistics? May cause excessive IPC.
*/
#define INSANE_STATISTICS GNUNET_NO
/**
* If a client stopped asking for more results, how many more do
* we receive from the DB before killing the connection? Trade-off
* between re-doing TCP handshakes and (needlessly) receiving
* useless results.
*/
#define MAX_EXCESS_RESULTS 8
/**
* Context for processing status messages.
*/
struct StatusContext
{
/**
* Continuation to call with the status.
*/
GNUNET_DATASTORE_ContinuationWithStatus cont;
/**
* Closure for cont.
*/
void *cont_cls;
};
/**
* Context for processing result messages.
*/
struct ResultContext
{
/**
* Function to call with the result.
*/
GNUNET_DATASTORE_DatumProcessor proc;
/**
* Closure for proc.
*/
void *proc_cls;
};
/**
* Context for a queue operation.
*/
union QueueContext
{
struct StatusContext sc;
struct ResultContext rc;
};
/**
* Entry in our priority queue.
*/
struct GNUNET_DATASTORE_QueueEntry
{
/**
* This is a linked list.
*/
struct GNUNET_DATASTORE_QueueEntry *next;
/**
* This is a linked list.
*/
struct GNUNET_DATASTORE_QueueEntry *prev;
/**
* Handle to the master context.
*/
struct GNUNET_DATASTORE_Handle