/*
* This file is part of GNUnet
* Copyright (C) 2013 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 psycutil/psyc_message.c
* @brief PSYC utilities; receiving/transmitting/logging PSYC messages.
* @author Gabor X Toth
*/
#include <inttypes.h>
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_psyc_util_lib.h"
#include "gnunet_psyc_service.h"
#define LOG(kind,...) GNUNET_log_from (kind, "psyc-util",__VA_ARGS__)
struct GNUNET_PSYC_TransmitHandle
{
/**
* Client connection to service.
*/
struct GNUNET_MQ_Handle *mq;
/**
* Message currently being received from the client.
*/
struct GNUNET_MessageHeader *msg;
/**
* Envelope for @a msg
*/
struct GNUNET_MQ_Envelope *env;
/**
* Callback to request next modifier from client.
*/
GNUNET_PSYC_TransmitNotifyModifier notify_mod;
/**
* Closure for the notify callbacks.
*/
void *notify_mod_cls;
/**
* Callback to request next data fragment from client.
*/
GNUNET_PSYC_TransmitNotifyData notify_data;
/**
* Closure for the notify callbacks.
*/
void *notify_data_cls;
/**
* Modifier of the environment that is currently being transmitted.
*/
struct GNUNET_PSYC_Modifier *mod;
/**
*
*/
const char *mod_value;
/**
* Number of bytes remaining to be transmitted from the current modifier value.
*/
uint32_t mod_value_remaining;
/**
* State of the current message being received from client.
*/
enum GNUNET_PSYC_MessageState state;
/**
* Number of PSYC_TRANSMIT_ACK messages we are still waiting for.
*/
uint8_t acks_pending;
/**
* Is transmission paused?
*/
uint8_t paused;
/**
* Are we currently transmitting a message?
*/
uint8_t in_transmit;
/**
* Notify callback is currently being called.
*/
uint8_t in_notify;
};
struct GNUNET_PSYC_ReceiveHandle
{
/**
* Message callback.
*/
GNUNET_PSYC_MessageCallback message_cb;
/**
* Message part callback.
*/
GNUNET_PSYC_MessagePartCallback message_part_cb;
/**
* Closure for the callbacks.
*/
void *cb_cls;
/**
* ID of the message being received from the PSYC service.
*/
uint64_t message_id;
/**
* Public key of the slave from which a message is being received.
*/
struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
/**
* State of the currently being received message from the PSYC service.
*/
enum GNUNET_PSYC_MessageState state;
/**
* Flags for the currently being received message from the PSYC service.
*/
enum GNUNET_PSYC_MessageFlags flags;
/**
* Expected value size for the modifier being received from the PSYC service.
*/
uint32_t mod_va