aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-02-26 23:05:29 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-02-26 23:06:05 +0100
commite2b2ab728217a64027232c7b8fbbb68ba13edd4a (patch)
tree69caa7c21703f2eabe9a1ec12ef7d07ac58b0728 /src/consensus
parent8d7c29c4684f807d5e9a3004bbbab132b158c5aa (diff)
downloadgnunet-e2b2ab728217a64027232c7b8fbbb68ba13edd4a.tar.gz
gnunet-e2b2ab728217a64027232c7b8fbbb68ba13edd4a.zip
wrap consensus elements in block type
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/Makefile.am18
-rw-r--r--src/consensus/consensus_protocol.h21
-rw-r--r--src/consensus/gnunet-service-consensus.c73
-rw-r--r--src/consensus/plugin_block_consensus.c117
-rw-r--r--src/consensus/test_consensus.conf6
5 files changed, 203 insertions, 32 deletions
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am
index b6385ac71..2b1987fbc 100644
--- a/src/consensus/Makefile.am
+++ b/src/consensus/Makefile.am
@@ -5,6 +5,8 @@ pkgcfgdir= $(pkgdatadir)/config.d/
5 5
6libexecdir= $(pkglibdir)/libexec/ 6libexecdir= $(pkglibdir)/libexec/
7 7
8plugindir = $(libdir)/gnunet
9
8pkgcfg_DATA = \ 10pkgcfg_DATA = \
9 consensus.conf 11 consensus.conf
10 12
@@ -67,6 +69,22 @@ libgnunetconsensus_la_LIBADD = \
67libgnunetconsensus_la_LDFLAGS = \ 69libgnunetconsensus_la_LDFLAGS = \
68 $(GN_LIB_LDFLAGS) 70 $(GN_LIB_LDFLAGS)
69 71
72
73plugin_LTLIBRARIES = \
74 libgnunet_plugin_block_consensus.la
75
76libgnunet_plugin_block_consensus_la_SOURCES = \
77 plugin_block_consensus.c
78libgnunet_plugin_block_consensus_la_LIBADD = \
79 $(top_builddir)/src/block/libgnunetblock.la \
80 $(top_builddir)/src/block/libgnunetblockgroup.la \
81 $(top_builddir)/src/util/libgnunetutil.la \
82 $(LTLIBINTL)
83libgnunet_plugin_block_consensus_la_LDFLAGS = \
84 $(GN_PLUGIN_LDFLAGS)
85
86
87
70if HAVE_TESTING 88if HAVE_TESTING
71check_PROGRAMS = \ 89check_PROGRAMS = \
72 test_consensus_api 90 test_consensus_api
diff --git a/src/consensus/consensus_protocol.h b/src/consensus/consensus_protocol.h
index fb3bde628..101b8aee7 100644
--- a/src/consensus/consensus_protocol.h
+++ b/src/consensus/consensus_protocol.h
@@ -87,6 +87,27 @@ struct GNUNET_CONSENSUS_RoundContextMessage
87 uint16_t is_contested; 87 uint16_t is_contested;
88}; 88};
89 89
90
91/**
92 * Consensus element, either marker or payload.
93 */
94struct ConsensusElement
95{
96 /**
97 * Payload element_type, only valid
98 * if this is not a marker element.
99 */
100 uint16_t payload_type;
101
102 /**
103 * Is this a marker element?
104 */
105 uint8_t is_contested_marker;
106
107 /* rest: element data */
108};
109
110
90GNUNET_NETWORK_STRUCT_END 111GNUNET_NETWORK_STRUCT_END
91 112
92#endif 113#endif
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 4036d2b11..9d5d35c94 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -26,6 +26,7 @@
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_block_lib.h"
29#include "gnunet_protocols.h" 30#include "gnunet_protocols.h"
30#include "gnunet_applications.h" 31#include "gnunet_applications.h"
31#include "gnunet_set_service.h" 32#include "gnunet_set_service.h"
@@ -34,8 +35,6 @@
34#include "consensus_protocol.h" 35#include "consensus_protocol.h"
35#include "consensus.h" 36#include "consensus.h"
36 37
37#define ELEMENT_TYPE_CONTESTED_MARKER (GNUNET_CONSENSUS_ELEMENT_TYPE_USER_MAX + 1)
38
39 38
40enum ReferendumVote 39enum ReferendumVote
41{ 40{
@@ -65,11 +64,6 @@ enum EarlyStoppingPhase
65 64
66GNUNET_NETWORK_STRUCT_BEGIN 65GNUNET_NETWORK_STRUCT_BEGIN
67 66
68
69struct ContestedPayload
70{
71};
72
73/** 67/**
74 * Tuple of integers that together 68 * Tuple of integers that together
75 * identify a task uniquely. 69 * identify a task uniquely.
@@ -669,16 +663,22 @@ send_to_client_iter (void *cls,
669 if (NULL != element) 663 if (NULL != element)
670 { 664 {
671 struct GNUNET_CONSENSUS_ElementMessage *m; 665 struct GNUNET_CONSENSUS_ElementMessage *m;
666 const struct ConsensusElement *ce;
667
668 GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type);
669 ce = element->data;
670
671 GNUNET_assert (GNUNET_NO == ce->is_contested_marker);
672 672
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
674 "P%d: sending element %s to client\n", 674 "P%d: sending element %s to client\n",
675 session->local_peer_idx, 675 session->local_peer_idx,
676 debug_str_element (element)); 676 debug_str_element (element));
677 677
678 ev = GNUNET_MQ_msg_extra (m, element->size, 678 ev = GNUNET_MQ_msg_extra (m, element->size - sizeof (struct ConsensusElement),
679 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT); 679 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT);
680 m->element_type = htons (element->element_type); 680 m->element_type = ce->payload_type;
681 GNUNET_memcpy (&m[1], element->data, element->size); 681 GNUNET_memcpy (&m[1], &ce[1], element->size - sizeof (struct ConsensusElement));
682 GNUNET_MQ_send (session->client_mq, ev); 682 GNUNET_MQ_send (session->client_mq, ev);
683 } 683 }
684 else 684 else
@@ -878,6 +878,13 @@ set_result_cb (void *cls,
878 struct ReferendumEntry *output_rfn = NULL; 878 struct ReferendumEntry *output_rfn = NULL;
879 unsigned int other_idx; 879 unsigned int other_idx;
880 struct SetOpCls *setop; 880 struct SetOpCls *setop;
881 const struct ConsensusElement *consensus_element = NULL;
882
883 if (NULL != element)
884 {
885 GNUNET_assert (GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT == element->element_type);
886 consensus_element = element->data;
887 }
881 888
882 setop = &task->cls.setop; 889 setop = &task->cls.setop;
883 890
@@ -932,7 +939,8 @@ set_result_cb (void *cls,
932 939
933 if ( (GNUNET_SET_STATUS_ADD_LOCAL == status) || (GNUNET_SET_STATUS_ADD_REMOTE == status) ) 940 if ( (GNUNET_SET_STATUS_ADD_LOCAL == status) || (GNUNET_SET_STATUS_ADD_REMOTE == status) )
934 { 941 {
935 if ( (GNUNET_YES == setop->transceive_contested) && (ELEMENT_TYPE_CONTESTED_MARKER == element->element_type) ) 942 if ( (GNUNET_YES == setop->transceive_contested) &&
943 (GNUNET_YES == consensus_element->is_contested_marker) )
936 { 944 {
937 GNUNET_assert (NULL != output_rfn); 945 GNUNET_assert (NULL != output_rfn);
938 rfn_contest (output_rfn, task_other_peer (task)); 946 rfn_contest (output_rfn, task_other_peer (task));
@@ -943,6 +951,7 @@ set_result_cb (void *cls,
943 switch (status) 951 switch (status)
944 { 952 {
945 case GNUNET_SET_STATUS_ADD_LOCAL: 953 case GNUNET_SET_STATUS_ADD_LOCAL:
954 GNUNET_assert (NULL != consensus_element);
946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
947 "Adding element in Task {%s}\n", 956 "Adding element in Task {%s}\n",
948 debug_str_task_key (&task->key)); 957 debug_str_task_key (&task->key));
@@ -989,9 +998,10 @@ set_result_cb (void *cls,
989 // XXX: add result to structures in task 998 // XXX: add result to structures in task
990 break; 999 break;
991 case GNUNET_SET_STATUS_ADD_REMOTE: 1000 case GNUNET_SET_STATUS_ADD_REMOTE:
1001 GNUNET_assert (NULL != consensus_element);
992 if (GNUNET_YES == setop->do_not_remove) 1002 if (GNUNET_YES == setop->do_not_remove)
993 break; 1003 break;
994 if (ELEMENT_TYPE_CONTESTED_MARKER == element->element_type) 1004 if (GNUNET_YES == consensus_element->is_contested_marker)
995 break; 1005 break;
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
997 "Removing element in Task {%s}\n", 1007 "Removing element in Task {%s}\n",
@@ -1318,10 +1328,11 @@ commit_set (struct ConsensusSession *session,
1318 if ( (GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested) ) 1328 if ( (GNUNET_YES == setop->transceive_contested) && (GNUNET_YES == set->is_contested) )
1319 { 1329 {
1320 struct GNUNET_SET_Element element; 1330 struct GNUNET_SET_Element element;
1321 struct ContestedPayload payload; 1331 struct ConsensusElement ce = { 0 };
1322 element.data = &payload; 1332 ce.is_contested_marker = GNUNET_YES;
1323 element.size = sizeof (struct ContestedPayload); 1333 element.data = &ce;
1324 element.element_type = ELEMENT_TYPE_CONTESTED_MARKER; 1334 element.size = sizeof (struct ConsensusElement);
1335 element.element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT;
1325 GNUNET_SET_add_element (set->h, &element, NULL, NULL); 1336 GNUNET_SET_add_element (set->h, &element, NULL, NULL);
1326 } 1337 }
1327 if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)]) 1338 if (GNUNET_NO == session->peers_blacklisted[task_other_peer (task)])
@@ -3041,9 +3052,9 @@ handle_client_insert (void *cls,
3041 const struct GNUNET_CONSENSUS_ElementMessage *msg) 3052 const struct GNUNET_CONSENSUS_ElementMessage *msg)
3042{ 3053{
3043 struct ConsensusSession *session = cls; 3054 struct ConsensusSession *session = cls;
3044 struct GNUNET_SET_Element *element;
3045 ssize_t element_size; 3055 ssize_t element_size;
3046 struct GNUNET_SET_Handle *initial_set; 3056 struct GNUNET_SET_Handle *initial_set;
3057 struct ConsensusElement *ce;
3047 3058
3048 if (GNUNET_YES == session->conclude_started) 3059 if (GNUNET_YES == session->conclude_started)
3049 { 3060 {
@@ -3051,12 +3062,18 @@ handle_client_insert (void *cls,
3051 GNUNET_SERVICE_client_drop (session->client); 3062 GNUNET_SERVICE_client_drop (session->client);
3052 return; 3063 return;
3053 } 3064 }
3065
3054 element_size = ntohs (msg->header.size) - sizeof (struct GNUNET_CONSENSUS_ElementMessage); 3066 element_size = ntohs (msg->header.size) - sizeof (struct GNUNET_CONSENSUS_ElementMessage);
3055 element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size); 3067 ce = GNUNET_malloc (sizeof (struct ConsensusElement) + element_size);
3056 element->element_type = msg->element_type; 3068 GNUNET_memcpy (&ce[1], &msg[1], element_size);
3057 element->size = element_size; 3069 ce->payload_type = msg->element_type;
3058 GNUNET_memcpy (&element[1], &msg[1], element_size); 3070
3059 element->data = &element[1]; 3071 struct GNUNET_SET_Element element = {
3072 .element_type = GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
3073 .size = sizeof (struct ConsensusElement) + element_size,
3074 .data = ce,
3075 };
3076
3060 { 3077 {
3061 struct SetKey key = { SET_KIND_CURRENT, 0, 0 }; 3078 struct SetKey key = { SET_KIND_CURRENT, 0, 0 };
3062 struct SetEntry *entry; 3079 struct SetEntry *entry;
@@ -3066,26 +3083,22 @@ handle_client_insert (void *cls,
3066 GNUNET_assert (NULL != entry); 3083 GNUNET_assert (NULL != entry);
3067 initial_set = entry->h; 3084 initial_set = entry->h;
3068 } 3085 }
3086
3069 session->num_client_insert_pending++; 3087 session->num_client_insert_pending++;
3070 GNUNET_SET_add_element (initial_set, 3088 GNUNET_SET_add_element (initial_set,
3071 element, 3089 &element,
3072 &client_insert_done, 3090 &client_insert_done,
3073 session); 3091 session);
3074 3092
3075#ifdef GNUNET_EXTRA_LOGGING 3093#ifdef GNUNET_EXTRA_LOGGING
3076 { 3094 {
3077 struct GNUNET_HashCode hash;
3078
3079 GNUNET_SET_element_hash (element,
3080 &hash);
3081
3082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3083 "P%u: element %s added\n", 3096 "P%u: element %s added\n",
3084 session->local_peer_idx, 3097 session->local_peer_idx,
3085 GNUNET_h2s (&hash)); 3098 debug_str_element (&element));
3086 } 3099 }
3087#endif 3100#endif
3088 GNUNET_free (element); 3101 GNUNET_free (ce);
3089 GNUNET_SERVICE_client_continue (session->client); 3102 GNUNET_SERVICE_client_continue (session->client);
3090} 3103}
3091 3104
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c
new file mode 100644
index 000000000..399e85feb
--- /dev/null
+++ b/src/consensus/plugin_block_consensus.c
@@ -0,0 +1,117 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @file consensus/plugin_block_consensus.c
23 * @brief consensus block, either nested block or marker
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_block_plugin.h"
29#include "gnunet_block_group_lib.h"
30
31
32/**
33 * Function called to validate a reply or a request. For
34 * request evaluation, simply pass "NULL" for the reply_block.
35 *
36 * @param cls closure
37 * @param type block type
38 * @param group block group to use
39 * @param eo control flags
40 * @param query original query (hash)
41 * @param xquery extrended query data (can be NULL, depending on type)
42 * @param xquery_size number of bytes in xquery
43 * @param reply_block response to validate
44 * @param reply_block_size number of bytes in reply block
45 * @return characterization of result
46 */
47static enum GNUNET_BLOCK_EvaluationResult
48block_plugin_consensus_evaluate (void *cls,
49 enum GNUNET_BLOCK_Type type,
50 struct GNUNET_BLOCK_Group *group,
51 enum GNUNET_BLOCK_EvaluationOptions eo,
52 const struct GNUNET_HashCode *query,
53 const void *xquery,
54 size_t xquery_size,
55 const void *reply_block,
56 size_t reply_block_size)
57{
58 return GNUNET_BLOCK_EVALUATION_OK_MORE;
59}
60
61
62/**
63 * Function called to obtain the key for a block.
64 *
65 * @param cls closure
66 * @param type block type
67 * @param block block to get the key for
68 * @param block_size number of bytes in block
69 * @param key set to the key (query) for the given block
70 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
71 * (or if extracting a key from a block of this type does not work)
72 */
73static int
74block_plugin_consensus_get_key (void *cls,
75 enum GNUNET_BLOCK_Type type,
76 const void *block,
77 size_t block_size,
78 struct GNUNET_HashCode *key)
79{
80 return GNUNET_SYSERR;
81}
82
83
84/**
85 * Entry point for the plugin.
86 */
87void *
88libgnunet_plugin_block_consensus_init (void *cls)
89{
90 static enum GNUNET_BLOCK_Type types[] =
91 {
92 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
93 GNUNET_BLOCK_TYPE_ANY /* end of list */
94 };
95 struct GNUNET_BLOCK_PluginFunctions *api;
96
97 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
98 api->evaluate = &block_plugin_consensus_evaluate;
99 api->get_key = &block_plugin_consensus_get_key;
100 api->types = types;
101 return api;
102}
103
104
105/**
106 * Exit point from the plugin.
107 */
108void *
109libgnunet_plugin_block_consensus_done (void *cls)
110{
111 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
112
113 GNUNET_free (api);
114 return NULL;
115}
116
117/* end of plugin_block_consensus.c */
diff --git a/src/consensus/test_consensus.conf b/src/consensus/test_consensus.conf
index 8f144fa5e..c3077b65d 100644
--- a/src/consensus/test_consensus.conf
+++ b/src/consensus/test_consensus.conf
@@ -2,9 +2,11 @@
2GNUNET_TEST_HOME = /tmp/test-consensus/ 2GNUNET_TEST_HOME = /tmp/test-consensus/
3 3
4[consensus] 4[consensus]
5OPTIONS = -L INFO 5#OPTIONS = -L INFO
6BINARY = gnunet-service-evil-consensus 6BINARY = gnunet-service-evil-consensus
7 7
8PREFIX = valgrind
9
8#EVIL_SPEC = 0;cram-all;noreplace;5 10#EVIL_SPEC = 0;cram-all;noreplace;5
9#EVIL_SPEC = 0;cram;5/1;cram;5 11#EVIL_SPEC = 0;cram;5/1;cram;5
10#EVIL_SPEC = 0;cram;5/1;cram;5/2;cram;5 12#EVIL_SPEC = 0;cram;5/1;cram;5/2;cram;5
@@ -37,7 +39,7 @@ PLUGINS = unix
37OPTIONS = -LERROR 39OPTIONS = -LERROR
38 40
39[set] 41[set]
40OPTIONS = -L INFO 42#OPTIONS = -L INFO
41#PREFIX = valgrind --leak-check=full 43#PREFIX = valgrind --leak-check=full
42#PREFIX = valgrind 44#PREFIX = valgrind
43 45