/*
This file is part of GNUnet.
(C) 2009, 2010 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 core/core_api.c
* @brief core service; this is the main API for encrypted P2P
* communications
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_core_service.h"
#include "core.h"
#define LOG(kind,...) GNUNET_log_from (kind, "core-api",__VA_ARGS__)
/**
* Information we track for each peer.
*/
struct PeerRecord
{
/**
* We generally do NOT keep peer records in a DLL; this
* DLL is only used IF this peer's 'pending_head' message
* is ready for transmission.
*/
struct PeerRecord *prev;
/**
* We generally do NOT keep peer records in a DLL; this
* DLL is only used IF this peer's 'pending_head' message
* is ready for transmission.
*/
struct PeerRecord *next;
/**
* Peer the record is about.
*/
struct GNUNET_PeerIdentity peer;
/**
* Corresponding core handle.
*/
struct GNUNET_CORE_Handle *ch;
/**
* Head of doubly-linked list of pending requests.
* Requests are sorted by deadline *except* for HEAD,
* which is only modified upon transmission to core.
*/
struct GNUNET_CORE_TransmitHandle *pending_head;
/**
* Tail of doubly-linked list of pending requests.
*/
struct GNUNET_CORE_TransmitHandle *pending_tail;
/**
* ID of timeout task for the 'pending_head' handle
* which is the one with the smallest timeout.
*/
GNUNET_SCHEDULER_TaskIdentifier timeout_task;
/**
* ID of task to run 'next_request_transmission'.
*/
GNUNET_SCHEDULER_TaskIdentifier ntr_task;
/**
* Current size of the queue of pending requests.
*/
unsigned int queue_size;
/**
* SendMessageRequest ID generator for this peer.
*/
uint16_t smr_id_gen;
};
/**
* Type of function called upon completion.
*
* @param cls closure
* @param success GNUNET_OK on success (which for request_connect
* ONLY means that we transmitted the connect request to CORE,
* it does not mean that we are actually now connected!);
* GNUNET_NO on timeout,
* GNUNET_SYSERR if core was shut down
*/
typedef void (*GNUNET_CORE_ControlContinuation) (void *cls,