GNUnet 0.22.2
consensus_api.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.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 33 of file consensus_api.c.

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 106 of file consensus_api.c.

108{
109 /* any size is fine, elements are variable-size */
110 return GNUNET_OK;
111}
@ GNUNET_OK

References GNUNET_OK.

◆ 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 121 of file consensus_api.c.

123{
124 struct GNUNET_CONSENSUS_Handle *consensus = cls;
125 struct GNUNET_SET_Element element;
126
128 "received new element\n");
129 element.element_type = msg->element_type;
130 element.size = ntohs (msg->header.size) - sizeof(struct
132 element.data = &msg[1];
133 consensus->new_element_cb (consensus->new_element_cls,
134 &element);
135}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define LOG(kind,...)
Definition: consensus_api.c:33
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_ERROR_TYPE_DEBUG
Message with an element.
Definition: consensus.h:73
Handle for the service.
Definition: consensus_api.c:40
void * new_element_cls
Closure for new_element_cb.
Definition: consensus_api.c:54
GNUNET_CONSENSUS_ElementCallback new_element_cb
Callback for new elements.
Definition: consensus_api.c:49
Element stored in a set.

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

◆ 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 146 of file consensus_api.c.

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

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

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 170 of file consensus_api.c.

172{
174 "consensus service disconnected us\n");
175}
@ GNUNET_ERROR_TYPE_WARNING

References GNUNET_ERROR_TYPE_WARNING, and LOG.

Referenced by GNUNET_CONSENSUS_create().

Here is the caller graph for this function:

◆ idc_adapter()

static void idc_adapter ( void *  cls)
static

Definition at line 253 of file consensus_api.c.

254{
255 struct InsertDoneInfo *i = cls;
256
257 i->idc (i->cls, GNUNET_OK);
258 GNUNET_free (i);
259}
#define GNUNET_free(ptr)
Wrapper around free.
FIXME: this should not bee necessary when the API issue has been fixed.
Definition: consensus_api.c:93
GNUNET_CONSENSUS_InsertDoneCallback idc
Definition: consensus_api.c:94

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

Referenced by GNUNET_CONSENSUS_insert().

Here is the caller graph for this function: