/*
This file is part of GNUnet.
(C) 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 dht/gnunet-service-dht_clients.c
* @brief GNUnet DHT service's client management code
* @author Christian Grothoff
* @author Nathan Evans
*/
#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_statistics_service.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_clients.h"
#include "gnunet-service-dht_datacache.h"
#include "gnunet-service-dht_neighbours.h"
#include "dht.h"
/**
* Linked list of messages to send to clients.
*/
struct PendingMessage
{
/**
* Pointer to next item in the list
*/
struct PendingMessage *next;
/**
* Pointer to previous item in the list
*/
struct PendingMessage *prev;
/**
* Actual message to be sent, allocated at the end of the struct:
* // msg = (cast) &pm[1];
* // memcpy (&pm[1], data, len);
*/
const struct GNUNET_MessageHeader *msg;
};
/**
* Struct containing information about a client,
* handle to connect to it, and any pending messages
* that need to be sent to it.
*/
struct ClientList
{
/**
* Linked list of active clients
*/
struct ClientList *next;
/**
* Linked list of active clients
*/
struct ClientList *prev;
/**
* The handle to this client
*/
struct GNUNET_SERVER_Client *client_handle;
/**
* Handle to the current transmission request, NULL
* if none pending.
*/
struct GNUNET_SERVER_TransmitHandle *transmit_handle;
/**
* Linked list of pending messages for this client
*/
struct PendingMessage *pending_head;
/**
* Tail of linked list of pending messages for this client
*/
struct PendingMessage *pending_tail;
};
/**
* Entry in the DHT routing table for a client's GET request.
*/
struct ClientQueryRecord
{
/**
* The key this request was about
*/
GNUNET_HashCode key;
/**
* Client responsible for the request.
*/
struct ClientList *client;
/**
* Extended query (see gnunet_block_lib.h), allocated at the end of this struct.
*/
const void *xquery;
/**
* Replies we have already seen for this request.
*/
GNUNET_HashCode *seen_replies;
/**