GNUnet  0.10.x
Data Structures | Macros | Functions
consensus_api.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_client_lib.h"
#include "gnunet_consensus_service.h"
#include "consensus.h"
Include dependency graph for consensus_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CONSENSUS_Handle
 Handle for the service. More...
 
struct  InsertDoneInfo
 FIXME: this should not bee necessary when the API issue has been fixed. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "consensus-api", __VA_ARGS__)
 

Functions

static int check_new_element (void *cls, const struct GNUNET_CONSENSUS_ElementMessage *msg)
 Called when the server has sent is a new element. More...
 
static void handle_new_element (void *cls, const struct GNUNET_CONSENSUS_ElementMessage *msg)
 Called when the server has sent is a new element. More...
 
static void handle_conclude_done (void *cls, const struct GNUNET_MessageHeader *msg)
 Called when the server has announced that the conclusion is over. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
struct GNUNET_CONSENSUS_HandleGNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, const struct GNUNET_PeerIdentity *peers, const struct GNUNET_HashCode *session_id, struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute deadline, GNUNET_CONSENSUS_ElementCallback new_element_cb, void *new_element_cls)
 Create a consensus session. More...
 
static void idc_adapter (void *cls)
 
void GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus, const struct GNUNET_SET_Element *element, GNUNET_CONSENSUS_InsertDoneCallback idc, void *idc_cls)
 Insert an element in the set being reconsiled. More...
 
void GNUNET_CONSENSUS_conclude (struct GNUNET_CONSENSUS_Handle *consensus, GNUNET_CONSENSUS_ConcludeCallback conclude, void *conclude_cls)
 We are done with inserting new elements into the consensus; try to conclude the consensus within a given time window. More...
 
void GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
 Destroy a consensus handle (free all state associated with it, no longer call any of the callbacks). More...
 

Detailed Description

Author
Florian Dold

Definition in file consensus_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "consensus-api", __VA_ARGS__)

Definition at line 34 of file consensus_api.c.

Referenced by GNUNET_CONSENSUS_insert(), handle_new_element(), and mq_error_handler().

Function Documentation

◆ check_new_element()

static int check_new_element ( void *  cls,
const struct GNUNET_CONSENSUS_ElementMessage msg 
)
static

Called when the server has sent is a new element.

Parameters
clsconsensus handle
msgelement message

Definition at line 105 of file consensus_api.c.

References GNUNET_OK.

107 {
108  /* any size is fine, elements are variable-size */
109  return GNUNET_OK;
110 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_new_element()

static void handle_new_element ( void *  cls,
const struct GNUNET_CONSENSUS_ElementMessage msg 
)
static

Called when the server has sent is a new element.

Parameters
clsconsensus handle
msgelement message

Definition at line 120 of file consensus_api.c.

References GNUNET_SET_Element::data, GNUNET_CONSENSUS_ElementMessage::element_type, GNUNET_SET_Element::element_type, GNUNET_ERROR_TYPE_DEBUG, GNUNET_CONSENSUS_ElementMessage::header, LOG, GNUNET_CONSENSUS_Handle::new_element_cb, GNUNET_CONSENSUS_Handle::new_element_cls, GNUNET_SET_Element::size, and GNUNET_MessageHeader::size.

122 {
123  struct GNUNET_CONSENSUS_Handle *consensus = cls;
124  struct GNUNET_SET_Element element;
125 
127  "received new element\n");
128  element.element_type = msg->element_type;
129  element.size = ntohs(msg->header.size) - sizeof(struct GNUNET_CONSENSUS_ElementMessage);
130  element.data = &msg[1];
131  consensus->new_element_cb(consensus->new_element_cls,
132  &element);
133 }
void * new_element_cls
Closure for new_element_cb.
Definition: consensus_api.c:54
Element stored in a set.
#define LOG(kind,...)
Definition: consensus_api.c:34
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
GNUNET_CONSENSUS_ElementCallback new_element_cb
Callback for new elements.
Definition: consensus_api.c:49
Message with an element.
Definition: consensus.h:71
struct GNUNET_MessageHeader header
Type: Either GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT or GNUNET_MESSAGE_TYPE_CONSENSUS_C...
Definition: consensus.h:77
uint16_t element_type
Type: GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_NEW_ELEMENT.
Definition: consensus.h:82
Handle for the service.
Definition: consensus_api.c:40

◆ handle_conclude_done()

static void handle_conclude_done ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Called when the server has announced that the conclusion is over.

Parameters
clsconsensus handle
msgconclude done message

Definition at line 144 of file consensus_api.c.

References GNUNET_CONSENSUS_Handle::conclude_cb, GNUNET_CONSENSUS_Handle::conclude_cls, GNUNET_assert, GNUNET_MQ_destroy(), and GNUNET_CONSENSUS_Handle::mq.

146 {
147  struct GNUNET_CONSENSUS_Handle *consensus = cls;
149 
150  GNUNET_MQ_destroy(consensus->mq);
151  consensus->mq = NULL;
152  GNUNET_assert(NULL != (cc = consensus->conclude_cb));
153  consensus->conclude_cb = NULL;
154  cc(consensus->conclude_cls);
155 }
GNUNET_CONSENSUS_ConcludeCallback conclude_cb
Called when the conclude operation finishes or fails.
Definition: consensus_api.c:69
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void(* GNUNET_CONSENSUS_ConcludeCallback)(void *cls)
Called when a conclusion was successful.
Handle for the service.
Definition: consensus_api.c:40
void * conclude_cls
Closure for the conclude_cb callback.
Definition: consensus_api.c:74
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: consensus_api.c:84
Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure, same closure as for the message handlers
errorerror code

Definition at line 168 of file consensus_api.c.

References GNUNET_ERROR_TYPE_WARNING, and LOG.

Referenced by GNUNET_CONSENSUS_create().

170 {
172  "consensus service disconnected us\n");
173 }
#define LOG(kind,...)
Definition: consensus_api.c:34
Here is the caller graph for this function:

◆ idc_adapter()

static void idc_adapter ( void *  cls)
static

Definition at line 251 of file consensus_api.c.

References InsertDoneInfo::cls, GNUNET_free, GNUNET_OK, and InsertDoneInfo::idc.

Referenced by GNUNET_CONSENSUS_insert().

252 {
253  struct InsertDoneInfo *i = cls;
254 
255  i->idc(i->cls, GNUNET_OK);
256  GNUNET_free(i);
257 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
FIXME: this should not bee necessary when the API issue has been fixed.
Definition: consensus_api.c:92
GNUNET_CONSENSUS_InsertDoneCallback idc
Definition: consensus_api.c:93
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: