/*
This file is part of GNUnet.
Copyright (C) 2012, 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 of the License,
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
Affero General Public License for more details.
*/
/**
* @file multicast/multicast_api.c
* @brief Multicast service; implements multicast groups using CADET connections.
* @author Christian Grothoff
* @author Gabor X Toth
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_multicast_service.h"
#include "multicast.h"
#define LOG(kind,...) GNUNET_log_from (kind, "multicast-api",__VA_ARGS__)
/**
* Handle for a request to send a message to all multicast group members
* (from the origin).
*/
struct GNUNET_MULTICAST_OriginTransmitHandle
{
GNUNET_MULTICAST_OriginTransmitNotify notify;
void *notify_cls;
struct GNUNET_MULTICAST_Origin *origin;
uint64_t message_id;
uint64_t group_generation;
uint64_t fragment_offset;
};
/**
* Handle for a message to be delivered from a member to the origin.
*/
struct GNUNET_MULTICAST_MemberTransmitHandle
{
GNUNET_MULTICAST_MemberTransmitNotify notify;
void *notify_cls;
struct GNUNET_MULTICAST_Member *member;
uint64_t request_id;
uint64_t fragment_offset;
};
struct GNUNET_MULTICAST_Group
{
/**
* Configuration to use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Client connection to the service.
*/
struct GNUNET_MQ_Handle *mq;
/**
* Message to send on connect.
*/
struct GNUNET_MQ_Envelope *connect_env;
/**
* Time to wait until we try to reconnect on failure.
*/
struct GNUNET_TIME_Relative reconnect_delay;
/**
* Task for reconnecting when the listener fails.
*/
struct GNUNET_SCHEDULER_Task *reconnect_task;
GNUNET_MULTICAST_JoinRequestCallback join_req_cb;
GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb;
GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb;
GNUNET_MULTICAST_MessageCallback message_cb;
void *cb_cls;
/**
* Function called after disconnected from the service.
*/
GNUNET_ContinuationCallback disconnect_cb;
/**
* Closure for @a disconnect_cb.
*/
void *disconnect_cls;
/**
* Are we currently transmitting a message?
*/
uint8_t in_transmit;
/**
* Number of MULTICAST_FRAGMENT_ACK messages we are still waiting for.
*/
uint8_t acks_pending;
/**
* Is this the origin or a member?
*/
uint8_t