diff options
author | tg(x) <*@tg-x.net> | 2017-03-22 10:08:01 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2017-03-22 10:08:01 +0100 |
commit | aa98f144e6db0da5a0a4cad83fe64a80bbab6692 (patch) | |
tree | 5a072b4e1b689bf4330b2a412bdadc705d33ff75 /src/multicast | |
parent | caeeec6cacaa5354883494cb64b0a38e5c75da5d (diff) | |
parent | b424335cc632a11bd76bad5791cef10e8c985720 (diff) | |
download | gnunet-aa98f144e6db0da5a0a4cad83fe64a80bbab6692.tar.gz gnunet-aa98f144e6db0da5a0a4cad83fe64a80bbab6692.zip |
Merge branch 'master' of gnunet.org:gnunet
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/.gitignore | 1 | ||||
-rw-r--r-- | src/multicast/Makefile.am | 17 | ||||
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 6 | ||||
-rw-r--r-- | src/multicast/test_multicast.conf | 10 | ||||
-rw-r--r-- | src/multicast/test_multicast_2peers.c | 511 | ||||
-rw-r--r-- | src/multicast/test_multicast_multipeer.c | 106 |
6 files changed, 612 insertions, 39 deletions
diff --git a/src/multicast/.gitignore b/src/multicast/.gitignore index d38ca9c02..43752ec4b 100644 --- a/src/multicast/.gitignore +++ b/src/multicast/.gitignore | |||
@@ -2,3 +2,4 @@ gnunet-service-multicast | |||
2 | gnunet-multicast | 2 | gnunet-multicast |
3 | test_multicast | 3 | test_multicast |
4 | test_multicast_multipeer | 4 | test_multicast_multipeer |
5 | test_multicast_2peers | ||
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am index 61821d973..1a61abb09 100644 --- a/src/multicast/Makefile.am +++ b/src/multicast/Makefile.am | |||
@@ -33,7 +33,8 @@ bin_PROGRAMS = \ | |||
33 | gnunet-multicast | 33 | gnunet-multicast |
34 | 34 | ||
35 | libexec_PROGRAMS = \ | 35 | libexec_PROGRAMS = \ |
36 | gnunet-service-multicast | 36 | gnunet-service-multicast \ |
37 | $(EXP_LIBEXEC) | ||
37 | 38 | ||
38 | gnunet_multicast_SOURCES = \ | 39 | gnunet_multicast_SOURCES = \ |
39 | gnunet-multicast.c | 40 | gnunet-multicast.c |
@@ -45,17 +46,17 @@ gnunet_service_multicast_SOURCES = \ | |||
45 | gnunet-service-multicast.c | 46 | gnunet-service-multicast.c |
46 | gnunet_service_multicast_LDADD = \ | 47 | gnunet_service_multicast_LDADD = \ |
47 | $(top_builddir)/src/util/libgnunetutil.la \ | 48 | $(top_builddir)/src/util/libgnunetutil.la \ |
48 | $(top_builddir)/src/cadet/libgnunetcadetnew.la \ | 49 | $(top_builddir)/src/cadet/libgnunetcadet.la \ |
49 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 50 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
50 | $(GN_LIBINTL) | 51 | $(GN_LIBINTL) |
51 | 52 | ||
52 | |||
53 | check_PROGRAMS = \ | 53 | check_PROGRAMS = \ |
54 | test_multicast \ | 54 | test_multicast \ |
55 | test_multicast_multipeer | 55 | test_multicast_2peers |
56 | # test_multicast_multipeer | ||
56 | 57 | ||
57 | if ENABLE_TEST_RUN | 58 | if ENABLE_TEST_RUN |
58 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@}; export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; unset XDG_DATA_HOME; unset XDG_CONFIG_HOME; export GNUNET_FORCE_LOG=';;;;INFO' | 59 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@}; export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; unset XDG_DATA_HOME; unset XDG_CONFIG_HOME; export GNUNET_FORCE_LOG=';;;;INFO'; |
59 | TESTS = $(check_PROGRAMS) | 60 | TESTS = $(check_PROGRAMS) |
60 | endif | 61 | endif |
61 | 62 | ||
@@ -66,9 +67,9 @@ test_multicast_LDADD = \ | |||
66 | $(top_builddir)/src/testing/libgnunettesting.la \ | 67 | $(top_builddir)/src/testing/libgnunettesting.la \ |
67 | $(top_builddir)/src/util/libgnunetutil.la | 68 | $(top_builddir)/src/util/libgnunetutil.la |
68 | 69 | ||
69 | test_multicast_multipeer_SOURCE = \ | 70 | test_multicast_2peers_SOURCE = \ |
70 | test_multicast_multipeer.c | 71 | test_multicast_2peers.c |
71 | test_multicast_multipeer_LDADD = \ | 72 | test_multicast_2peers_LDADD = \ |
72 | libgnunetmulticast.la \ | 73 | libgnunetmulticast.la \ |
73 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 74 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
74 | $(top_builddir)/src/util/libgnunetutil.la | 75 | $(top_builddir)/src/util/libgnunetutil.la |
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index 3f356af83..9683efcff 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c | |||
@@ -1302,7 +1302,7 @@ cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer) | |||
1302 | GNUNET_MQ_handler_end () | 1302 | GNUNET_MQ_handler_end () |
1303 | }; | 1303 | }; |
1304 | 1304 | ||
1305 | chn->channel = GNUNET_CADET_channel_creatE (cadet, chn, &chn->peer, | 1305 | chn->channel = GNUNET_CADET_channel_create (cadet, chn, &chn->peer, |
1306 | &grp->cadet_port_hash, | 1306 | &grp->cadet_port_hash, |
1307 | GNUNET_CADET_OPTION_RELIABLE, | 1307 | GNUNET_CADET_OPTION_RELIABLE, |
1308 | cadet_notify_window_change, | 1308 | cadet_notify_window_change, |
@@ -1392,7 +1392,7 @@ handle_client_origin_start (void *cls, | |||
1392 | }; | 1392 | }; |
1393 | 1393 | ||
1394 | 1394 | ||
1395 | orig->cadet_port = GNUNET_CADET_open_porT (cadet, | 1395 | orig->cadet_port = GNUNET_CADET_open_port (cadet, |
1396 | &grp->cadet_port_hash, | 1396 | &grp->cadet_port_hash, |
1397 | cadet_notify_connect, | 1397 | cadet_notify_connect, |
1398 | NULL, | 1398 | NULL, |
@@ -2085,7 +2085,7 @@ run (void *cls, | |||
2085 | replay_req_cadet = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2085 | replay_req_cadet = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
2086 | replay_req_client = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 2086 | replay_req_client = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
2087 | 2087 | ||
2088 | cadet = GNUNET_CADET_connecT (cfg); | 2088 | cadet = GNUNET_CADET_connect (cfg); |
2089 | 2089 | ||
2090 | GNUNET_assert (NULL != cadet); | 2090 | GNUNET_assert (NULL != cadet); |
2091 | 2091 | ||
diff --git a/src/multicast/test_multicast.conf b/src/multicast/test_multicast.conf index 675776bbc..3081aeecc 100644 --- a/src/multicast/test_multicast.conf +++ b/src/multicast/test_multicast.conf | |||
@@ -1,4 +1,12 @@ | |||
1 | [testbed] | ||
2 | HOSTNAME = localhost | ||
3 | |||
1 | [arm] | 4 | [arm] |
2 | GLOBAL_POSTFIX=-L ERROR | 5 | GLOBAL_POSTFIX=-L ERROR |
3 | 6 | ||
4 | #PREFIX = sakura -t test-multicast -e cgdb --args | 7 | [multicast] |
8 | #PREFIX = xterm -T peer -e gdb --args | ||
9 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-multicast.sock | ||
10 | |||
11 | [vpn] | ||
12 | AUTOSTART = NO | ||
diff --git a/src/multicast/test_multicast_2peers.c b/src/multicast/test_multicast_2peers.c new file mode 100644 index 000000000..058533e50 --- /dev/null +++ b/src/multicast/test_multicast_2peers.c | |||
@@ -0,0 +1,511 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet | ||
3 | * Copyright (C) 2013 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 multicast/test_multicast_2peers.c | ||
23 | * @brief Tests for the Multicast API with two peers doing the ping | ||
24 | * pong test. | ||
25 | * @author xrs | ||
26 | */ | ||
27 | |||
28 | #include <inttypes.h> | ||
29 | |||
30 | #include "platform.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | #include "gnunet_common.h" | ||
33 | #include "gnunet_util_lib.h" | ||
34 | #include "gnunet_testbed_service.h" | ||
35 | #include "gnunet_multicast_service.h" | ||
36 | |||
37 | #define NUM_PEERS 2 | ||
38 | |||
39 | static struct GNUNET_TESTBED_Operation *op0; | ||
40 | static struct GNUNET_TESTBED_Operation *op1; | ||
41 | static struct GNUNET_TESTBED_Operation *pi_op0; | ||
42 | static struct GNUNET_TESTBED_Operation *pi_op1; | ||
43 | |||
44 | static struct GNUNET_TESTBED_Peer **peers; | ||
45 | const struct GNUNET_PeerIdentity *peer_id[2]; | ||
46 | |||
47 | static struct GNUNET_SCHEDULER_Task *timeout_tid; | ||
48 | |||
49 | static struct GNUNET_MULTICAST_Origin *origin; | ||
50 | static struct GNUNET_MULTICAST_Member *member; | ||
51 | |||
52 | struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; | ||
53 | struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; | ||
54 | |||
55 | struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key; | ||
56 | struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key; | ||
57 | |||
58 | /** | ||
59 | * Global result for testcase. | ||
60 | */ | ||
61 | static int result; | ||
62 | |||
63 | |||
64 | /** | ||
65 | * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.). | ||
66 | * Cleans up. | ||
67 | */ | ||
68 | static void | ||
69 | shutdown_task (void *cls) | ||
70 | { | ||
71 | if (NULL != op0) | ||
72 | { | ||
73 | GNUNET_TESTBED_operation_done (op0); | ||
74 | op0 = NULL; | ||
75 | } | ||
76 | if (NULL != op1) | ||
77 | { | ||
78 | GNUNET_TESTBED_operation_done (op1); | ||
79 | op1 = NULL; | ||
80 | } | ||
81 | if (NULL != pi_op0) | ||
82 | { | ||
83 | GNUNET_TESTBED_operation_done (pi_op0); | ||
84 | pi_op0 = NULL; | ||
85 | } | ||
86 | if (NULL != pi_op1) | ||
87 | { | ||
88 | GNUNET_TESTBED_operation_done (pi_op1); | ||
89 | pi_op1 = NULL; | ||
90 | } | ||
91 | if (NULL != timeout_tid) | ||
92 | { | ||
93 | GNUNET_SCHEDULER_cancel (timeout_tid); | ||
94 | timeout_tid = NULL; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | timeout_task (void *cls) | ||
101 | { | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
103 | "Timeout!\n"); | ||
104 | result = GNUNET_SYSERR; | ||
105 | GNUNET_SCHEDULER_shutdown (); | ||
106 | } | ||
107 | |||
108 | |||
109 | static void | ||
110 | member_join_request (void *cls, | ||
111 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | ||
112 | const struct GNUNET_MessageHeader *join_msg, | ||
113 | struct GNUNET_MULTICAST_JoinHandle *jh) | ||
114 | { | ||
115 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
116 | "Member sent a join request.\n"); | ||
117 | |||
118 | } | ||
119 | |||
120 | |||
121 | static int | ||
122 | notify (void *cls, | ||
123 | size_t *data_size, | ||
124 | void *data) | ||
125 | { | ||
126 | |||
127 | char text[] = "ping"; | ||
128 | *data_size = strlen(text)+1; | ||
129 | GNUNET_memcpy(data, text, *data_size); | ||
130 | |||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
132 | "Member sents message to origin: %s\n", text); | ||
133 | |||
134 | return GNUNET_YES; | ||
135 | } | ||
136 | |||
137 | |||
138 | static void | ||
139 | member_join_decision (void *cls, | ||
140 | int is_admitted, | ||
141 | const struct GNUNET_PeerIdentity *peer, | ||
142 | uint16_t relay_count, | ||
143 | const struct GNUNET_PeerIdentity *relays, | ||
144 | const struct GNUNET_MessageHeader *join_msg) | ||
145 | { | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
147 | "Member received a decision from origin: %s\n", | ||
148 | (GNUNET_YES == is_admitted) | ||
149 | ? "accepted" | ||
150 | : "rejected"); | ||
151 | |||
152 | if (GNUNET_YES == is_admitted) | ||
153 | { | ||
154 | struct GNUNET_MULTICAST_MemberTransmitHandle *req; | ||
155 | |||
156 | // FIXME: move to MQ-style API! | ||
157 | req = GNUNET_MULTICAST_member_to_origin (member, | ||
158 | 0, | ||
159 | ¬ify, | ||
160 | NULL); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | |||
165 | static void | ||
166 | member_message (void *cls, | ||
167 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
168 | { | ||
169 | if (0 != strncmp ("pong", (char *)&msg[1], 4)) | ||
170 | { | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n"); | ||
172 | result = GNUNET_SYSERR; | ||
173 | GNUNET_SCHEDULER_shutdown (); | ||
174 | } | ||
175 | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
177 | "member receives: %s\n", (char *)&msg[1]); | ||
178 | |||
179 | // Testcase ends here. | ||
180 | result = GNUNET_YES; | ||
181 | GNUNET_SCHEDULER_shutdown (); | ||
182 | } | ||
183 | |||
184 | static void | ||
185 | origin_join_request (void *cls, | ||
186 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | ||
187 | const struct GNUNET_MessageHeader *join_msg, | ||
188 | struct GNUNET_MULTICAST_JoinHandle *jh) | ||
189 | { | ||
190 | struct GNUNET_MessageHeader *join_resp; | ||
191 | |||
192 | uint8_t data_size = ntohs (join_msg->size); | ||
193 | |||
194 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
195 | "origin got a join request...\n"); | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
197 | "origin receives: '%s'\n", (char *)&join_msg[1]); | ||
198 | |||
199 | const char data[] = "Come in!"; | ||
200 | data_size = strlen (data) + 1; | ||
201 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); | ||
202 | join_resp->size = htons (sizeof (join_resp) + data_size); | ||
203 | join_resp->type = htons (123); | ||
204 | GNUNET_memcpy (&join_resp[1], data, data_size); | ||
205 | |||
206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
207 | "origin sends: '%s'\n", data); | ||
208 | |||
209 | GNUNET_MULTICAST_join_decision (jh, | ||
210 | GNUNET_YES, | ||
211 | 0, | ||
212 | NULL, | ||
213 | join_resp); | ||
214 | GNUNET_free (join_resp); | ||
215 | result = GNUNET_OK; | ||
216 | } | ||
217 | |||
218 | int | ||
219 | origin_notify (void *cls, | ||
220 | size_t *data_size, | ||
221 | void *data) | ||
222 | { | ||
223 | char text[] = "pong"; | ||
224 | *data_size = strlen(text)+1; | ||
225 | memcpy(data, text, *data_size); | ||
226 | |||
227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); | ||
228 | |||
229 | return GNUNET_YES; | ||
230 | } | ||
231 | |||
232 | |||
233 | static void | ||
234 | origin_request (void *cls, | ||
235 | const struct GNUNET_MULTICAST_RequestHeader *req) | ||
236 | { | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); | ||
238 | |||
239 | if (0 != strncmp ("ping", (char *)&req[1], 4)) | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); | ||
241 | |||
242 | GNUNET_MULTICAST_origin_to_all (origin, | ||
243 | 0, | ||
244 | 0, | ||
245 | origin_notify, | ||
246 | NULL); | ||
247 | } | ||
248 | |||
249 | static void | ||
250 | origin_message (void *cls, | ||
251 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
252 | { | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); | ||
254 | } | ||
255 | |||
256 | |||
257 | static void | ||
258 | service_connect1 (void *cls, | ||
259 | struct GNUNET_TESTBED_Operation *op, | ||
260 | void *ca_result, | ||
261 | const char *emsg) | ||
262 | { | ||
263 | member = ca_result; | ||
264 | |||
265 | if (NULL != member) | ||
266 | { | ||
267 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); | ||
268 | } | ||
269 | else | ||
270 | { | ||
271 | result = GNUNET_SYSERR; | ||
272 | GNUNET_SCHEDULER_shutdown (); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | static void | ||
277 | multicast_da1 (void *cls, | ||
278 | void * op_result) | ||
279 | { | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
281 | "Member parting from multicast group\n"); | ||
282 | |||
283 | GNUNET_MULTICAST_member_part (member, NULL, NULL); | ||
284 | } | ||
285 | |||
286 | |||
287 | static void * | ||
288 | multicast_ca1 (void *cls, | ||
289 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
290 | { | ||
291 | struct GNUNET_MessageHeader *join_msg; | ||
292 | void *ret; | ||
293 | |||
294 | // Get members keys | ||
295 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | ||
296 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | ||
297 | |||
298 | char data[] = "Hi, can I enter?"; | ||
299 | uint8_t data_size = strlen (data) + 1; | ||
300 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | ||
301 | join_msg->size = htons (sizeof (join_msg) + data_size); | ||
302 | join_msg->type = htons (123); | ||
303 | GNUNET_memcpy (&join_msg[1], data, data_size); | ||
304 | |||
305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
306 | "Members tries to join multicast group\n"); | ||
307 | |||
308 | ret = GNUNET_MULTICAST_member_join (cfg, | ||
309 | &group_pub_key, | ||
310 | member_key, | ||
311 | peer_id[0], | ||
312 | 0, | ||
313 | NULL, | ||
314 | join_msg, /* join message */ | ||
315 | member_join_request, | ||
316 | member_join_decision, | ||
317 | NULL, /* no test for member_replay_frag */ | ||
318 | NULL, /* no test for member_replay_msg */ | ||
319 | member_message, | ||
320 | NULL); | ||
321 | GNUNET_free (join_msg); | ||
322 | return ret; | ||
323 | } | ||
324 | |||
325 | |||
326 | static void | ||
327 | peer_information_cb (void *cls, | ||
328 | struct GNUNET_TESTBED_Operation *op, | ||
329 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
330 | const char *emsg) | ||
331 | { | ||
332 | int i = (int) (long) cls; | ||
333 | |||
334 | if (NULL == pinfo) | ||
335 | { | ||
336 | result = GNUNET_SYSERR; | ||
337 | GNUNET_SCHEDULER_shutdown (); | ||
338 | } | ||
339 | |||
340 | peer_id[i] = pinfo->result.id; | ||
341 | |||
342 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
343 | "Got peer information of %s (%s)\n", (0==i)?"origin":"member" ,GNUNET_i2s(pinfo->result.id)); | ||
344 | |||
345 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
346 | "Create member peer\n"); | ||
347 | |||
348 | if (0 == i) | ||
349 | { | ||
350 | /* connect to multicast service of member */ | ||
351 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ | ||
352 | peers[1], /* The peer whose service to connect to */ | ||
353 | "multicast", /* The name of the service */ | ||
354 | service_connect1, /* callback to call after a handle to service | ||
355 | is opened */ | ||
356 | NULL, /* closure for the above callback */ | ||
357 | multicast_ca1, /* callback to call with peer's configuration; | ||
358 | this should open the needed service connection */ | ||
359 | multicast_da1, /* callback to be called when closing the | ||
360 | opened service connection */ | ||
361 | NULL); /* closure for the above two callbacks */ | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * Test logic of peer "0" being origin starts here. | ||
367 | * | ||
368 | * @param cls closure, for the example: NULL | ||
369 | * @param op should be equal to "dht_op" | ||
370 | * @param ca_result result of the connect operation, the | ||
371 | * connection to the DHT service | ||
372 | * @param emsg error message, if testbed somehow failed to | ||
373 | * connect to the DHT. | ||
374 | */ | ||
375 | static void | ||
376 | service_connect0 (void *cls, | ||
377 | struct GNUNET_TESTBED_Operation *op, | ||
378 | void *ca_result, | ||
379 | const char *emsg) | ||
380 | { | ||
381 | origin = ca_result; | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
384 | "Connected to multicast service of origin\n"); | ||
385 | |||
386 | // Get GNUnet identity of origin | ||
387 | pi_op0 = GNUNET_TESTBED_peer_get_information (peers[0], | ||
388 | GNUNET_TESTBED_PIT_IDENTITY, | ||
389 | peer_information_cb, | ||
390 | (void *) 0); | ||
391 | // Get GNUnet identity of member | ||
392 | pi_op1 = GNUNET_TESTBED_peer_get_information (peers[1], | ||
393 | GNUNET_TESTBED_PIT_IDENTITY, | ||
394 | peer_information_cb, | ||
395 | (void *) 1); | ||
396 | |||
397 | /* Connection to service successful. Here we'd usually do something with | ||
398 | * the service. */ | ||
399 | result = GNUNET_OK; | ||
400 | //GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */ | ||
401 | } | ||
402 | |||
403 | |||
404 | |||
405 | /** | ||
406 | * Function run when service multicast has started and is providing us | ||
407 | * with a configuration file. | ||
408 | */ | ||
409 | static void * | ||
410 | multicast_ca0 (void *cls, | ||
411 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
412 | { | ||
413 | group_key = GNUNET_CRYPTO_eddsa_key_create (); | ||
414 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); | ||
415 | |||
416 | return GNUNET_MULTICAST_origin_start (cfg, | ||
417 | group_key, | ||
418 | 0, | ||
419 | origin_join_request, | ||
420 | NULL, /* no test for origin_replay_frag */ | ||
421 | NULL, /* no test for origin_replay_msg */ | ||
422 | origin_request, | ||
423 | origin_message, | ||
424 | NULL); | ||
425 | } | ||
426 | |||
427 | static void | ||
428 | multicast_da0 (void *cls, | ||
429 | void *op_result) | ||
430 | { | ||
431 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
432 | "Origin closes multicast group\n"); | ||
433 | |||
434 | GNUNET_MULTICAST_origin_stop (origin, NULL, NULL); | ||
435 | } | ||
436 | |||
437 | |||
438 | /** | ||
439 | * Main function inovked from TESTBED once all of the | ||
440 | * peers are up and running. This one then connects | ||
441 | * just to the multicast service of peer 0 and 1. | ||
442 | * Peer 0 is going to be origin. | ||
443 | * Peer 1 is going to be one member. | ||
444 | * Origin will start a multicast group and the member will try to join it. | ||
445 | * After that we execute some multicast test. | ||
446 | * | ||
447 | * @param cls closure | ||
448 | * @param h the run handle | ||
449 | * @param peers started peers for the test | ||
450 | * @param num_peers size of the 'peers' array | ||
451 | * @param links_succeeded number of links between peers that were created | ||
452 | * @param links_failed number of links testbed was unable to establish | ||
453 | */ | ||
454 | static void | ||
455 | testbed_master (void *cls, | ||
456 | struct GNUNET_TESTBED_RunHandle *h, | ||
457 | unsigned int num_peers, | ||
458 | struct GNUNET_TESTBED_Peer **p, | ||
459 | unsigned int links_succeeded, | ||
460 | unsigned int links_failed) | ||
461 | { | ||
462 | /* Testbed is ready with peers running and connected in a pre-defined overlay | ||
463 | topology (FIXME) */ | ||
464 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
465 | "Connected to testbed_master()\n"); | ||
466 | |||
467 | peers = p; | ||
468 | |||
469 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
470 | "Create origin peer\n"); | ||
471 | op0 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ | ||
472 | peers[0], /* The peer whose service to connect to */ | ||
473 | "multicast", /* The name of the service */ | ||
474 | service_connect0, /* callback to call after a handle to service | ||
475 | is opened */ | ||
476 | NULL, /* closure for the above callback */ | ||
477 | multicast_ca0, /* callback to call with peer's configuration; | ||
478 | this should open the needed service connection */ | ||
479 | multicast_da0, /* callback to be called when closing the | ||
480 | opened service connection */ | ||
481 | NULL); /* closure for the above two callbacks */ | ||
482 | |||
483 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ | ||
484 | |||
485 | /* Schedule the shutdown task with a delay of a few Seconds */ | ||
486 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 50), | ||
487 | &timeout_task, NULL); | ||
488 | } | ||
489 | |||
490 | |||
491 | int | ||
492 | main (int argc, char *argv[]) | ||
493 | { | ||
494 | int ret; | ||
495 | |||
496 | result = GNUNET_SYSERR; | ||
497 | ret = GNUNET_TESTBED_test_run | ||
498 | ("test-multicast-multipeer", /* test case name */ | ||
499 | "test_multicast.conf", /* template configuration */ | ||
500 | NUM_PEERS, /* number of peers to start */ | ||
501 | 0LL, /* Event mask - set to 0 for no event notifications */ | ||
502 | NULL, /* Controller event callback */ | ||
503 | NULL, /* Closure for controller event callback */ | ||
504 | testbed_master, /* continuation callback to be called when testbed setup is complete */ | ||
505 | NULL); /* Closure for the test_master callback */ | ||
506 | if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) | ||
507 | return 1; | ||
508 | return 0; | ||
509 | } | ||
510 | |||
511 | /* end of test_multicast_multipeer.c */ | ||
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c index 1b76737f4..58e43d4ba 100644 --- a/src/multicast/test_multicast_multipeer.c +++ b/src/multicast/test_multicast_multipeer.c | |||
@@ -107,7 +107,6 @@ shutdown_task (void *cls) | |||
107 | static void | 107 | static void |
108 | timeout_task (void *cls) | 108 | timeout_task (void *cls) |
109 | { | 109 | { |
110 | timeout_tid = NULL; | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
112 | "Timeout!\n"); | 111 | "Timeout!\n"); |
113 | result = GNUNET_SYSERR; | 112 | result = GNUNET_SYSERR; |
@@ -126,6 +125,21 @@ member_join_request (void *cls, | |||
126 | 125 | ||
127 | } | 126 | } |
128 | 127 | ||
128 | int notify (void *cls, | ||
129 | size_t *data_size, | ||
130 | void *data) | ||
131 | { | ||
132 | |||
133 | char text[] = "ping"; | ||
134 | *data_size = strlen(text)+1; | ||
135 | GNUNET_memcpy(data, text, *data_size); | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
138 | "Member sents message to origin: %s\n", text); | ||
139 | |||
140 | return GNUNET_YES; | ||
141 | } | ||
142 | |||
129 | 143 | ||
130 | static void | 144 | static void |
131 | member_join_decision (void *cls, | 145 | member_join_decision (void *cls, |
@@ -135,11 +149,19 @@ member_join_decision (void *cls, | |||
135 | const struct GNUNET_PeerIdentity *relays, | 149 | const struct GNUNET_PeerIdentity *relays, |
136 | const struct GNUNET_MessageHeader *join_msg) | 150 | const struct GNUNET_MessageHeader *join_msg) |
137 | { | 151 | { |
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 152 | struct GNUNET_MULTICAST_MemberTransmitHandle *req; |
153 | |||
154 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
139 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); | 155 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); |
140 | 156 | ||
141 | result = GNUNET_OK; | 157 | if (GNUNET_YES == is_admitted) |
142 | GNUNET_SCHEDULER_shutdown (); | 158 | { |
159 | req = GNUNET_MULTICAST_member_to_origin (member, | ||
160 | 0, | ||
161 | notify, | ||
162 | NULL); | ||
163 | |||
164 | } | ||
143 | } | 165 | } |
144 | 166 | ||
145 | static void | 167 | static void |
@@ -161,6 +183,10 @@ member_message () | |||
161 | { | 183 | { |
162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
163 | "member message...\n"); | 185 | "member message...\n"); |
186 | |||
187 | // FIXME: not finished here | ||
188 | result = GNUNET_YES; | ||
189 | GNUNET_SCHEDULER_shutdown (); | ||
164 | } | 190 | } |
165 | 191 | ||
166 | static void | 192 | static void |
@@ -173,20 +199,21 @@ origin_join_request (void *cls, | |||
173 | 199 | ||
174 | uint8_t data_size = ntohs (join_msg->size); | 200 | uint8_t data_size = ntohs (join_msg->size); |
175 | 201 | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
177 | "Dizzy: Mh, got a join request...\n"); | 203 | "origin got a join request...\n"); |
178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
179 | "'%s'\n", (char *)&join_msg[1]); | 205 | "origin receives: '%s'\n", (char *)&join_msg[1]); |
180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
181 | "Dizzy: Oh, it's Bird! Let's get him in.\n"); | ||
182 | 206 | ||
183 | char data[] = "Hi, Bird. Come in!"; | 207 | char data[] = "Come in!"; |
184 | data_size = strlen (data) + 1; | 208 | data_size = strlen (data) + 1; |
185 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); | 209 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); |
186 | join_resp->size = htons (sizeof (join_resp) + data_size); | 210 | join_resp->size = htons (sizeof (join_resp) + data_size); |
187 | join_resp->type = htons (123); | 211 | join_resp->type = htons (123); |
188 | GNUNET_memcpy (&join_resp[1], data, data_size); | 212 | GNUNET_memcpy (&join_resp[1], data, data_size); |
189 | 213 | ||
214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
215 | "origin sends: '%s'\n", data); | ||
216 | |||
190 | GNUNET_MULTICAST_join_decision (jh, | 217 | GNUNET_MULTICAST_join_decision (jh, |
191 | GNUNET_YES, | 218 | GNUNET_YES, |
192 | 0, | 219 | 0, |
@@ -198,37 +225,62 @@ origin_join_request (void *cls, | |||
198 | 225 | ||
199 | static void | 226 | static void |
200 | origin_replay_frag (void *cls, | 227 | origin_replay_frag (void *cls, |
201 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 228 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
202 | uint64_t fragment_id, | 229 | uint64_t fragment_id, |
203 | uint64_t flags, | 230 | uint64_t flags, |
204 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 231 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
205 | { | 232 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); | 233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); |
207 | } | 234 | } |
208 | 235 | ||
209 | static void | 236 | static void |
210 | origin_replay_msg (void *cls, | 237 | origin_replay_msg (void *cls, |
211 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, | 238 | const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key, |
212 | uint64_t message_id, | 239 | uint64_t message_id, |
213 | uint64_t fragment_offset, | 240 | uint64_t fragment_offset, |
214 | uint64_t flags, | 241 | uint64_t flags, |
215 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 242 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
216 | { | 243 | { |
217 | 244 | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); | 245 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); |
219 | } | 246 | } |
220 | 247 | ||
248 | |||
249 | int | ||
250 | origin_notify (void *cls, | ||
251 | size_t *data_size, | ||
252 | void *data) | ||
253 | { | ||
254 | char text[] = "pong"; | ||
255 | *data_size = strlen(text)+1; | ||
256 | memcpy(data, text, *data_size); | ||
257 | |||
258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); | ||
259 | |||
260 | return GNUNET_YES; | ||
261 | } | ||
262 | |||
263 | |||
221 | static void | 264 | static void |
222 | origin_request (void *cls, | 265 | origin_request (void *cls, |
223 | const struct GNUNET_MULTICAST_RequestHeader *req) | 266 | const struct GNUNET_MULTICAST_RequestHeader *req) |
224 | { | 267 | { |
225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin request msg\n"); | 268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); |
269 | |||
270 | if (0 != strncmp ("ping", (char *)&req[1], 4)) { | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); | ||
272 | } | ||
226 | 273 | ||
274 | GNUNET_MULTICAST_origin_to_all (origin, | ||
275 | 0, | ||
276 | 0, | ||
277 | origin_notify, | ||
278 | NULL); | ||
227 | } | 279 | } |
228 | 280 | ||
229 | static void | 281 | static void |
230 | origin_message (void *cls, | 282 | origin_message (void *cls, |
231 | const struct GNUNET_MULTICAST_MessageHeader *msg) | 283 | const struct GNUNET_MULTICAST_MessageHeader *msg) |
232 | { | 284 | { |
233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); | 285 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); |
234 | } | 286 | } |
@@ -268,8 +320,8 @@ multicast_ca1 (void *cls, | |||
268 | // Get members keys | 320 | // Get members keys |
269 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | 321 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); |
270 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | 322 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); |
271 | 323 | ||
272 | char data[] = "Whut's up, Dizzy!"; | 324 | char data[] = "Hi, can I enter?"; |
273 | uint8_t data_size = strlen (data) + 1; | 325 | uint8_t data_size = strlen (data) + 1; |
274 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | 326 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); |
275 | join_msg->size = htons (sizeof (join_msg) + data_size); | 327 | join_msg->size = htons (sizeof (join_msg) + data_size); |
@@ -453,7 +505,7 @@ testbed_master (void *cls, | |||
453 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ | 505 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ |
454 | 506 | ||
455 | /* Schedule the shutdown task with a delay of a few Seconds */ | 507 | /* Schedule the shutdown task with a delay of a few Seconds */ |
456 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40), | 508 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 48), |
457 | &timeout_task, NULL); | 509 | &timeout_task, NULL); |
458 | } | 510 | } |
459 | 511 | ||