/*
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__)
/**
* Handle for a transmission request.
*/
struct GNUNET_CORE_TransmitHandle
{
/**
* Corresponding peer record.
*/
struct PeerRecord *peer;
/**
* Corresponding SEND_REQUEST message. Only non-NULL
* while SEND_REQUEST message is pending.
*/
struct ControlMessage *cm;
/**
* Function that will be called to get the actual request
* (once we are ready to transmit this request to the core).
* The function will be called with a NULL buffer to signal
* timeout.
*/
GNUNET_CONNECTION_TransmitReadyNotify get_message;
/**
* Closure for get_message.
*/
void *get_message_cls;
/**
* Timeout for this handle.
*/
struct GNUNET_TIME_Absolute timeout;
/**
* How important is this message?
*/
uint32_t priority;
/**
* Size of this request.
*/
uint16_t msize;
/**
* Send message request ID for this request.
*/
uint16_t smr_id;
/**
* Is corking allowed?
*/
int cork;
};
/**
* 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;
/**
* Pending request, if any. 'th->peer' is set to NULL if the
* request is not active.
*/
struct GNUNET_CORE_TransmitHandle th;
/**
* 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;
/**
* 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,
*