diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-09-06 11:37:39 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-09-06 11:37:39 +0000 |
commit | e81bbc8f2131c4ad7f7d27b4060694efefbdd13d (patch) | |
tree | 30459e4c0748662b45aeeb3a47974196b858a556 | |
parent | 831dc785eccaa364ff00ff8e2f46372578b4f74b (diff) | |
download | gnunet-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
-rw-r--r-- | src/consensus/consensus_api.c | 26 | ||||
-rw-r--r-- | src/consensus/gnunet-service-consensus.c | 4 | ||||
-rw-r--r-- | src/consensus/test_consensus_api.c | 31 | ||||
-rw-r--r-- | src/include/gnunet_consensus_service.h | 2 | ||||
-rw-r--r-- | src/set/test_set_api.c | 5 |
5 files changed, 24 insertions, 44 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 | ||
33 | static struct GNUNET_HashCode session_id; | 33 | static struct GNUNET_HashCode session_id; |
34 | 34 | ||
35 | static unsigned int elements_received; | ||
35 | 36 | ||
36 | static int | 37 | |
37 | conclude_done (void *cls, const struct GNUNET_CONSENSUS_Group *group) | 38 | static void |
39 | conclude_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 | ||
49 | static int | 47 | static void |
50 | on_new_element (void *cls, | 48 | on_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 | ||
57 | static void | 54 | static 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", |
diff --git a/src/include/gnunet_consensus_service.h b/src/include/gnunet_consensus_service.h index db7509976..fc1255506 100644 --- a/src/include/gnunet_consensus_service.h +++ b/src/include/gnunet_consensus_service.h | |||
@@ -52,7 +52,7 @@ extern "C" | |||
52 | * @param element new element, NULL on error | 52 | * @param element new element, NULL on error |
53 | */ | 53 | */ |
54 | typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls, | 54 | typedef void (*GNUNET_CONSENSUS_ElementCallback) (void *cls, |
55 | const struct GNUNET_SET_Element *element); | 55 | const struct GNUNET_SET_Element *element); |
56 | 56 | ||
57 | 57 | ||
58 | 58 | ||
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index 3dd49f036..b7e1961f2 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c | |||
@@ -136,9 +136,10 @@ init_set2 (void *cls) | |||
136 | { | 136 | { |
137 | struct GNUNET_SET_Element element; | 137 | struct GNUNET_SET_Element element; |
138 | 138 | ||
139 | |||
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); | 139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); |
141 | 140 | ||
141 | element.type = 0; | ||
142 | |||
142 | element.data = "hello"; | 143 | element.data = "hello"; |
143 | element.size = strlen(element.data); | 144 | element.size = strlen(element.data); |
144 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | 145 | GNUNET_SET_add_element (set2, &element, NULL, NULL); |
@@ -159,6 +160,8 @@ init_set1 (void) | |||
159 | { | 160 | { |
160 | struct GNUNET_SET_Element element; | 161 | struct GNUNET_SET_Element element; |
161 | 162 | ||
163 | element.type = 0; | ||
164 | |||
162 | element.data = "hello"; | 165 | element.data = "hello"; |
163 | element.size = strlen(element.data); | 166 | element.size = strlen(element.data); |
164 | GNUNET_SET_add_element (set1, &element, NULL, NULL); | 167 | GNUNET_SET_add_element (set1, &element, NULL, NULL); |