/*
* This file is part of GNUnet
* Copyright (C) 2013 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* @file psyc/psyc_api.c
* @brief PSYC service; high-level access to the PSYC protocol
* note that clients of this API are NOT expected to
* understand the PSYC message format, only the semantics!
* Parsing (and serializing) the PSYC stream format is done
* within the implementation of the libgnunetpsyc library,
* and this API deliberately exposes as little as possible
* of the actual data stream format to the application!
* @author Gabor X Toth
*/
#include <inttypes.h>
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_env_lib.h"
#include "gnunet_multicast_service.h"
#include "gnunet_psyc_service.h"
#include "gnunet_psyc_util_lib.h"
#include "psyc.h"
#define LOG(kind,...) GNUNET_log_from (kind, "psyc-api",__VA_ARGS__)
/**
* Handle to access PSYC channel operations for both the master and slaves.
*/
struct GNUNET_PSYC_Channel
{
/**
* Configuration to use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Client connection to the service.
*/
struct GNUNET_CLIENT_MANAGER_Connection *client;
/**
* Transmission handle;
*/
struct GNUNET_PSYC_TransmitHandle *tmit;
/**
* Receipt handle;
*/
struct GNUNET_PSYC_ReceiveHandle *recv;
/**
* Message to send on reconnect.
*/
struct GNUNET_MessageHeader *connect_msg;
/**
* Function called after disconnected from the service.
*/
GNUNET_ContinuationCallback disconnect_cb;
/**
* Closure for @a disconnect_cb.
*/
void *disconnect_cls;
/**
* Are we polling for incoming messages right now?
*/
uint8_t in_receive;
/**
* Is this a master or slave channel?
*/
uint8_t is_master;
/**
* Is this channel in the process of disconnecting from the service?
* #GNUNET_YES or #GNUNET_NO
*/
uint8_t is_disconnecting;
};
/**
* Handle for the master of a PSYC channel.
*/
struct GNUNET_PSYC_Master
{
struct GNUNET_PSYC_Channel chn;
GNUNET_PSYC_MasterStartCallback start_cb;
/**
* Join request callback.
*/
GNUNET_PSYC_JoinRequestCallback join_req_cb;
/**
* Closure for the callbacks.
*/
void *cb_cls;
};
/**
* Handle for a PSYC channel slave.
*/
struct GNUNET_PSYC_Slave
{
struct GNUNET_PSYC_Channel chn;
GNUNET_PSYC_SlaveConnectCallback connect_cb