aboutsummaryrefslogtreecommitdiff
path: root/src/consensus
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2013-09-06 11:37:39 +0000
committerFlorian Dold <florian.dold@gmail.com>2013-09-06 11:37:39 +0000
commite81bbc8f2131c4ad7f7d27b4060694efefbdd13d (patch)
tree30459e4c0748662b45aeeb3a47974196b858a556 /src/consensus
parent831dc785eccaa364ff00ff8e2f46372578b4f74b (diff)
downloadgnunet-e81bbc8f2131c4ad7f7d27b4060694efefbdd13d.tar.gz
gnunet-e81bbc8f2131c4ad7f7d27b4060694efefbdd13d.zip
- initialize set type in test case
- handle 1-peer consensus correcly - don't store peers in consensus api - updated consensus test case
Diffstat (limited to 'src/consensus')
-rw-r--r--src/consensus/consensus_api.c26
-rw-r--r--src/consensus/gnunet-service-consensus.c4
-rw-r--r--src/consensus/test_consensus_api.c31
3 files changed, 19 insertions, 42 deletions
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c
index 873e72ca1..b2b3694d6 100644
--- a/src/consensus/consensus_api.c
+++ b/src/consensus/consensus_api.c
@@ -65,16 +65,6 @@ struct GNUNET_CONSENSUS_Handle
65 struct GNUNET_HashCode session_id; 65 struct GNUNET_HashCode session_id;
66 66
67 /** 67 /**
68 * Number of peers in the consensus. Optionally includes the local peer.
69 */
70 int num_peers;
71
72 /**
73 * Peer identities of peers participating in the consensus, includes the local peer.
74 */
75 struct GNUNET_PeerIdentity **peers;
76
77 /**
78 * GNUNES_YES iff the join message has been sent to the service. 68 * GNUNES_YES iff the join message has been sent to the service.
79 */ 69 */
80 int joined; 70 int joined;
@@ -194,15 +184,7 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
194 consensus->cfg = cfg; 184 consensus->cfg = cfg;
195 consensus->new_element_cb = new_element_cb; 185 consensus->new_element_cb = new_element_cb;
196 consensus->new_element_cls = new_element_cls; 186 consensus->new_element_cls = new_element_cls;
197 consensus->num_peers = num_peers;
198 consensus->session_id = *session_id; 187 consensus->session_id = *session_id;
199
200 if (0 == num_peers)
201 consensus->peers = NULL;
202 else if (num_peers > 0)
203 consensus->peers =
204 GNUNET_memdup (peers, num_peers * sizeof (struct GNUNET_PeerIdentity));
205
206 consensus->client = GNUNET_CLIENT_connect ("consensus", cfg); 188 consensus->client = GNUNET_CLIENT_connect ("consensus", cfg);
207 consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client, 189 consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client,
208 mq_handlers, NULL, consensus); 190 mq_handlers, NULL, consensus);
@@ -214,10 +196,10 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
214 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN); 196 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
215 197
216 join_msg->session_id = consensus->session_id; 198 join_msg->session_id = consensus->session_id;
217 join_msg->num_peers = htonl (consensus->num_peers); 199 join_msg->num_peers = htonl (num_peers);
218 memcpy(&join_msg[1], 200 memcpy(&join_msg[1],
219 consensus->peers, 201 peers,
220 consensus->num_peers * sizeof (struct GNUNET_PeerIdentity)); 202 num_peers * sizeof (struct GNUNET_PeerIdentity));
221 203
222 GNUNET_MQ_send (consensus->mq, ev); 204 GNUNET_MQ_send (consensus->mq, ev);
223 return consensus; 205 return consensus;
@@ -318,8 +300,6 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
318 GNUNET_CLIENT_disconnect (consensus->client); 300 GNUNET_CLIENT_disconnect (consensus->client);
319 consensus->client = NULL; 301 consensus->client = NULL;
320 } 302 }
321 if (NULL != consensus->peers)
322 GNUNET_free (consensus->peers);
323 GNUNET_free (consensus); 303 GNUNET_free (consensus);
324} 304}
325 305
diff --git a/src/consensus/gnunet-service-consensus.c b/src/consensus/gnunet-service-consensus.c
index 9e72a7f74..a490ad7f4 100644
--- a/src/consensus/gnunet-service-consensus.c
+++ b/src/consensus/gnunet-service-consensus.c
@@ -1187,8 +1187,8 @@ client_conclude (void *cls,
1187 } 1187 }
1188 if (session->num_peers <= 1) 1188 if (session->num_peers <= 1)
1189 { 1189 {
1190 /* FIXME: what to do here? */ 1190 session->current_round = CONSENSUS_ROUND_FINISH;
1191 //send_client_conclude_done (session); 1191 GNUNET_SET_iterate (session->element_set, send_to_client_iter, session);
1192 } 1192 }
1193 else 1193 else
1194 { 1194 {
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
index c79a6221c..37a5eb692 100644
--- a/src/consensus/test_consensus_api.c
+++ b/src/consensus/test_consensus_api.c
@@ -32,26 +32,23 @@ static struct GNUNET_CONSENSUS_Handle *consensus;
32 32
33static struct GNUNET_HashCode session_id; 33static struct GNUNET_HashCode session_id;
34 34
35static unsigned int elements_received;
35 36
36static int 37
37conclude_done (void *cls, const struct GNUNET_CONSENSUS_Group *group) 38static void
39conclude_done (void *cls)
38{ 40{
39 if (NULL == group) 41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
40 { 42 if (2 != elements_received)
41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n"); 43 GNUNET_abort ();
42 GNUNET_SCHEDULER_shutdown (); 44 GNUNET_SCHEDULER_shutdown ();
43 return GNUNET_NO;
44 }
45 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "concluded\n");
46 return GNUNET_YES;
47} 45}
48 46
49static int 47static void
50on_new_element (void *cls, 48on_new_element (void *cls,
51 struct GNUNET_CONSENSUS_Element *element) 49 const struct GNUNET_SET_Element *element)
52{ 50{
53 GNUNET_assert (0); 51 elements_received++;
54 return GNUNET_YES;
55} 52}
56 53
57static void 54static void
@@ -62,7 +59,7 @@ insert_done (void *cls, int success)
62 GNUNET_assert (GNUNET_NO == called); 59 GNUNET_assert (GNUNET_NO == called);
63 called = GNUNET_YES; 60 called = GNUNET_YES;
64 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n"); 61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
65 GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_SECONDS, 0, &conclude_done, NULL); 62 GNUNET_CONSENSUS_conclude (consensus, GNUNET_TIME_UNIT_SECONDS, &conclude_done, NULL);
66} 63}
67 64
68 65
@@ -91,8 +88,8 @@ run (void *cls,
91{ 88{
92 char *str = "foo"; 89 char *str = "foo";
93 90
94 struct GNUNET_CONSENSUS_Element el1 = {"foo", 4, 0}; 91 struct GNUNET_SET_Element el1 = {4, 0, "foo"};
95 struct GNUNET_CONSENSUS_Element el2 = {"bar", 4, 0}; 92 struct GNUNET_SET_Element el2 = {5, 0, "quux"};
96 93
97 GNUNET_log_setup ("test_consensus_api", 94 GNUNET_log_setup ("test_consensus_api",
98 "INFO", 95 "INFO",