#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_block_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
#include "gnunet_set_service.h"
#include "consensus_protocol.h"
#include "consensus.h"
-#define ELEMENT_TYPE_CONTESTED_MARKER (GNUNET_CONSENSUS_ELEMENT_TYPE_USER_MAX + 1)
-
enum ReferendumVote
{
GNUNET_NETWORK_STRUCT_BEGIN
-
-struct ContestedPayload
-{
-};
-
/**
* Tuple of integers that together
* identify a task uniquely.
if (NULL != element)
{
struct GNUNET_CONSENSUS_ElementMessage *m;
+ const struct ConsensusElement *ce;
+
+ GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type);
+ ce = element->data;
+
+ GNUNET_assert (GNUNET_NO == ce->is_contested_marker);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"P%d: sending element %s to client\n",
session->local_peer_idx,
debug_str_element (element));
- ev = GNUNET_MQ_msg_extra (m, element->size,
+ ev = GNUNET_MQ_msg_extra (m, element->size - sizeof (struct ConsensusElement),
GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
- m->element_type = htons (element->element_type);
- GNUNET_memcpy (&m[1], element->data, element->size);
+ m->element_type = ce->payload_type;
+ GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof (struct ConsensusElement));
GNUNET_MQ_send (session->client_mq, ev);
}
else
struct ReferendumEntry *output_rfn = NULL;
unsigned int other_idx;
struct SetOpCls *setop;
+ const struct ConsensusElement *consensus_element = NULL;
+
+ if (NULL != element)
+ {
+ GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type);
+ consensus_element = element->data;
+ }
setop = &task->cls.setop;
if ( (GNUNET_SET_STATUS_ADD_LOCAL == status) || (GNUNET_SET_STATUS_ADD_REMOTE == status) )
{
- if ( (GNUNET_YES == setop->transceive_contested) && (ELEMENT_TYPE_CONTESTED_MARKER == element->element_type) )
+ if ( (GNUNET_YES == setop->transceive_contested) &&
+ (GNUNET_YES == consensus_element->is_contested_marker) )
{
GNUNET_assert (NULL != output_rfn);
rfn_contest (output_rfn, task_other_peer (task));
switch (status)
{
case GNUNET_SET_STATUS_ADD_LOCAL:
+ GNUNET_assert (NULL != consensus_element);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding element in Task {%s}\n",
debug_str_task_key (&task->key));
// XXX: add result to structures in task
break;
case GNUNET_SET_STATUS_ADD_REMOTE:
+ GNUNET_assert (NULL != consensus_element);
if (GNUNET_YES == setop->do_not_remove)
break;
- if (ELEMENT_TYPE_CONTESTED_MARKER == element->element_type)
+ if (GNUNET_YES == consensus_element->is_contested_marker)
break;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Removing element in Task {%s}\n",
if ( (GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested) )
{
struct GNUNET_SET_Element element;
- struct ContestedPayload payload;
- element.data = &payload;
- element.size = sizeof (struct ContestedPayload);
- element.element_type = ELEMENT_TYPE_CONTESTED_MARKER;
+ struct ConsensusElement ce = { 0 };
+ ce.is_contested_marker = GNUNET_YES;
+ element.data = &ce;
+ element.size = sizeof (struct ConsensusElement);
+ element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
GNUNET_SET_add_element (set->h, &element, NULL, NULL);
}
if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)])
const struct GNUNET_CONSENSUS_ElementMessage *msg)
{
struct ConsensusSession *session = cls;
- struct GNUNET_SET_Element *element;
ssize_t element_size;
struct GNUNET_SET_Handle *initial_set;
+ struct ConsensusElement *ce;
if (GNUNET_YES == session->conclude_started)
{
GNUNET_SERVICE_client_drop (session->client);
return;
}
+
element_size = ntohs (msg->header.size) - sizeof (struct GNUNET_CONSENSUS_ElementMessage);
- element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size);
- element->element_type = msg->element_type;
- element->size = element_size;
- GNUNET_memcpy (&element[1], &msg[1], element_size);
- element->data = &element[1];
+ ce = GNUNET_malloc (sizeof (struct ConsensusElement) + element_size);
+ GNUNET_memcpy (&ce[1], &msg[1], element_size);
+ ce->payload_type = msg->element_type;
+
+ struct GNUNET_SET_Element element = {
+ .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
+ .size = sizeof (struct ConsensusElement) + element_size,
+ .data = ce,
+ };
+
{
struct SetKey key = { SET_KIND_CURRENT, 0, 0 };
struct SetEntry *entry;
GNUNET_assert (NULL != entry);
initial_set = entry->h;
}
+
session->num_client_insert_pending++;
GNUNET_SET_add_element (initial_set,
- element,
+ &element,
&client_insert_done,
session);
#ifdef GNUNET_EXTRA_LOGGING
{
- struct GNUNET_HashCode hash;
-
- GNUNET_SET_element_hash (element,
- &hash);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"P%u: element %s added\n",
session->local_peer_idx,
- GNUNET_h2s (&hash));
+ debug_str_element (&element));
}
#endif
- GNUNET_free (element);
+ GNUNET_free (ce);
GNUNET_SERVICE_client_continue (session->client);
}
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2017 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 consensus/plugin_block_consensus.c
+ * @brief consensus block, either nested block or marker
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_block_plugin.h"
+#include "gnunet_block_group_lib.h"
+
+
+/**
+ * Function called to validate a reply or a request. For
+ * request evaluation, simply pass "NULL" for the reply_block.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param group block group to use
+ * @param eo control flags
+ * @param query original query (hash)
+ * @param xquery extrended query data (can be NULL, depending on type)
+ * @param xquery_size number of bytes in xquery
+ * @param reply_block response to validate
+ * @param reply_block_size number of bytes in reply block
+ * @return characterization of result
+ */
+static enum GNUNET_BLOCK_EvaluationResult
+block_plugin_consensus_evaluate (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ struct GNUNET_BLOCK_Group *group,
+ enum GNUNET_BLOCK_EvaluationOptions eo,
+ const struct GNUNET_HashCode *query,
+ const void *xquery,
+ size_t xquery_size,
+ const void *reply_block,
+ size_t reply_block_size)
+{
+ return GNUNET_BLOCK_EVALUATION_OK_MORE;
+}
+
+
+/**
+ * Function called to obtain the key for a block.
+ *
+ * @param cls closure
+ * @param type block type
+ * @param block block to get the key for
+ * @param block_size number of bytes in block
+ * @param key set to the key (query) for the given block
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
+ * (or if extracting a key from a block of this type does not work)
+ */
+static int
+block_plugin_consensus_get_key (void *cls,
+ enum GNUNET_BLOCK_Type type,
+ const void *block,
+ size_t block_size,
+ struct GNUNET_HashCode *key)
+{
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Entry point for the plugin.
+ */
+void *
+libgnunet_plugin_block_consensus_init (void *cls)
+{
+ static enum GNUNET_BLOCK_Type types[] =
+ {
+ GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
+ GNUNET_BLOCK_TYPE_ANY /* end of list */
+ };
+ struct GNUNET_BLOCK_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
+ api->evaluate = &block_plugin_consensus_evaluate;
+ api->get_key = &block_plugin_consensus_get_key;
+ api->types = types;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ */
+void *
+libgnunet_plugin_block_consensus_done (void *cls)
+{
+ struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ return NULL;
+}
+
+/* end of plugin_block_consensus.c */