/*
This file is part of GNUnet.
Copyright (C) 2009-2014 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, 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_util_lib.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 @e get_message.
*/
void *get_message_cls;
/**
* Deadline for the transmission (the request does not get cancelled
* at this time, this is merely how soon the application wants this out).
*/
struct GNUNET_TIME_Absolute deadline;
/**
* When did this request get queued?
*/
struct GNUNET_TIME_Absolute request_time;
/**
* How important is this message?
*/
enum GNUNET_CORE_Priority priority;
/**
* Is corking allowed?
*/
int cork;
/**
* Size of this request.
*/
uint16_t msize;
/**
* Send message request ID for this request.
*/
uint16_t smr_id;
};
/**
* 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;
/**
* 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;
/**
* Peer the record is about.
*/
struct GNUNET_PeerIdentity peer;
/**
* ID of task to run #run_request_next_transmission().
*/
struct GNUNET_SCHEDULER_Task *ntr_task;
/**
* SendMessageRequest ID generator for this peer.
*/
uint16_t