/*
This file is part of GNUnet.
(C) 2009, 2010, 2012 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 gns/gns_api.c
* @brief library to access the GNS service
* @author Martin Schanzenbach
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_dht_service.h"
#include "gns.h"
#include "gnunet_gns_service.h"
/**
* Handle to a lookup request
*/
struct GNUNET_GNS_LookupRequest
{
/**
* DLL
*/
struct GNUNET_GNS_LookupRequest *next;
/**
* DLL
*/
struct GNUNET_GNS_LookupRequest *prev;
/**
* handle to gns
*/
struct GNUNET_GNS_Handle *gns_handle;
/**
* processor to call on lookup result
*/
GNUNET_GNS_LookupResultProcessor lookup_proc;
/**
* processor closure
*/
void *proc_cls;
/**
* request id
*/
uint32_t r_id;
};
/**
* Handle to a shorten request
*/
struct GNUNET_GNS_ShortenRequest
{
/**
* DLL
*/
struct GNUNET_GNS_ShortenRequest *next;
/**
* DLL
*/
struct GNUNET_GNS_ShortenRequest *prev;
/**
* handle to gns
*/
struct GNUNET_GNS_Handle *gns_handle;
/**
* processor to call on shorten result
*/
GNUNET_GNS_ShortenResultProcessor shorten_proc;
/**
* processor closure
*/
void *proc_cls;
/**
* request id
*/
uint32_t r_id;
};
/**
* Handle to GetAuthorityRequest
*/
struct GNUNET_GNS_GetAuthRequest
{
/**
* DLL
*/
struct GNUNET_GNS_GetAuthRequest *next;
/**
* DLL
*/
struct GNUNET_GNS_GetAuthRequest *prev;
/**
* handle to gns
*/
struct GNUNET_GNS_Handle *gns_handle;
/**
* processor to call on authority lookup result
*/
GNUNET_GNS_GetAuthResultProcessor auth_proc;
/**
* processor closure
*/
void *proc_cls;
/**
* request id
*/
uint32_t r_id;
};
/**
* Entry in our list of messages to be (re-)transmitted.
*/
struct PendingMessage
{
/**
* This is a doubly-linked list.
*/
struct PendingMessage *prev;
/**
* This is a doubly-linked list.
*/
struct PendingMessage *next;
/**
* Size of the message.
*/
size_t size;
/**
* request id
*/
uint32_t r_id;
/**
* This message has been transmitted. GNUNET_NO if the message is
* in the "pending" DLL, GNUNET_YES if it has been transmitted to
* the service via the current client connection.
*/
int transmitted;
};
/**
* Connection to the GNS service.
*/
struct GNUNET_GNS_Handle
{
/**
* Configuration to use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Socket (if available).
*/
struct GNUNET_CLIENT_Connection *client;
/**
* Currently pending transmission request (or NULL).
*/
struct GNUNET_CLIENT_TransmitHandle *th;
/**
* Head of linked list of shorten messages we would like to transmit.
*/
struct PendingMessage *pending_head;
/**
* Tail of linked list of shorten messages we would like to transmit.
*/
struct PendingMessage *pending_tail;
/**
* Head of linked list of shorten messages we would like to transmit.
*/
struct GNUNET_GNS_ShortenRequest *shorten_head;
/**
* Tail of linked list of shorten messages we would like to transmit.
*/
struct GNUNET_GNS_ShortenRequest *shorten_tail;
/**
* Head of linked list of lookup messages we would like to transmit.
*/
struct GNUNET_GNS_LookupRequest *lookup_head;
/**
* Tail of linked list of lookup messages we would like to transmit.
*/
struct GNUNET_GNS_LookupRequest *lookup_tail;
/**
* Head of linked list of authority lookup messages we would like to transmit.
*/
struct GNUNET_GNS_GetAuthRequest *get_auth_head;
/**
* Tail of linked list of authority lookup messages we would like to transmit.
*/
struct GNUNET_GNS_GetAuthRequest *get_auth_tail;
/**
* Reconnect task
*/
GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
/**
* How long do we wait until we try to reconnect?
*/
struct GNUNET_TIME_Relative reconnect_backoff;
/**
* Request Id generator. Incremented by one for each request.
*/
uint32_t r_id_gen;
/**
* Did we start our receive loop yet?
*/
int in_receive;
};
/**
* Try to send messages from list of messages to send
* @param handle GNS_Handle
*/
static void
process_pending_messages (struct GNUNET_GNS_Handle *handle);
/**
* Reconnect to GNS service.
*
* @param handle the handle to the GNS service
*/
static void
reconnect (struct GNUNET_GNS_Handle *handle)
{
GNUNET_assert (NULL == handle->client);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Trying to connect to GNS\n");
handle->client = GNUNET_CLIENT_connect