aboutsummaryrefslogtreecommitdiff
path: root/src/multicast/test_multicast_multipeer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/multicast/test_multicast_multipeer.c')
-rw-r--r--src/multicast/test_multicast_multipeer.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index d1ed1cb39..7766ff875 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -2,20 +2,18 @@
2 * This file is part of GNUnet 2 * This file is part of GNUnet
3 * Copyright (C) 2013 GNUnet e.V. 3 * Copyright (C) 2013 GNUnet e.V.
4 * 4 *
5 * GNUnet is free software; you can redistribute it and/or modify 5 * GNUnet is free software: you can redistribute it and/or modify it
6 * it under the terms of the GNU General Public License as published 6 * under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your 7 * by the Free Software Foundation, either version 3 of the License,
8 * option) any later version. 8 * or (at your option) any later version.
9 * 9 *
10 * GNUnet is distributed in the hope that it will be useful, but 10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details. 13 * Affero General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU Affero General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */ 17 */
20 18
21/** 19/**
@@ -54,7 +52,7 @@ enum pingpong
54struct pingpong_msg 52struct pingpong_msg
55{ 53{
56 int peer; 54 int peer;
57 enum pingpong msg; 55 enum pingpong msg;
58}; 56};
59 57
60static void service_connect (void *cls, 58static void service_connect (void *cls,
@@ -143,13 +141,13 @@ member_join_request (void *cls,
143{ 141{
144 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 142 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 143 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
146 "Peer #%u (%s) sent a join request.\n", 144 "Peer #%u (%s) sent a join request.\n",
147 mc_peer->peer, 145 mc_peer->peer,
148 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 146 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
149} 147}
150 148
151 149
152static int 150static int
153notify (void *cls, 151notify (void *cls,
154 size_t *data_size, 152 size_t *data_size,
155 void *data) 153 void *data)
@@ -162,8 +160,9 @@ notify (void *cls,
162 160
163 *data_size = sizeof (struct pingpong_msg); 161 *data_size = sizeof (struct pingpong_msg);
164 GNUNET_memcpy(data, pp_msg, *data_size); 162 GNUNET_memcpy(data, pp_msg, *data_size);
163 GNUNET_free (pp_msg);
165 164
166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 165 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
167 "Peer #%u sents ping to origin\n", mc_peer->peer); 166 "Peer #%u sents ping to origin\n", mc_peer->peer);
168 167
169 return GNUNET_YES; 168 return GNUNET_YES;
@@ -179,20 +178,20 @@ member_join_decision (void *cls,
179 const struct GNUNET_MessageHeader *join_msg) 178 const struct GNUNET_MessageHeader *join_msg)
180{ 179{
181 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 180 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
182 181
183 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 182 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
184 "Peer #%u (%s) received a decision from origin: %s\n", 183 "Peer #%u (%s) received a decision from origin: %s\n",
185 mc_peer->peer, 184 mc_peer->peer,
186 GNUNET_i2s (multicast_peers[mc_peer->peer]->id), 185 GNUNET_i2s (multicast_peers[mc_peer->peer]->id),
187 (GNUNET_YES == is_admitted)?"accepted":"rejected"); 186 (GNUNET_YES == is_admitted)?"accepted":"rejected");
188 187
189 if (GNUNET_YES == is_admitted) 188 if (GNUNET_YES == is_admitted)
190 { 189 {
191 GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer], 190 GNUNET_MULTICAST_member_to_origin (members[mc_peer->peer],
192 0, 191 0,
193 notify, 192 notify,
194 cls); 193 cls);
195 194
196 } 195 }
197} 196}
198 197
@@ -236,7 +235,7 @@ member_disconnected_cb (void *cls)
236 235
237 236
238static void 237static void
239member_message (void *cls, 238member_message (void *cls,
240 const struct GNUNET_MULTICAST_MessageHeader *msg) 239 const struct GNUNET_MULTICAST_MessageHeader *msg)
241{ 240{
242 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls; 241 struct MulticastPeerContext *mc_peer = (struct MulticastPeerContext*)cls;
@@ -245,7 +244,7 @@ member_message (void *cls,
245 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer) 244 if (PONG == pp_msg->msg && mc_peer->peer == pp_msg->peer)
246 { 245 {
247 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 246 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
248 "peer #%i (%s) receives a pong\n", 247 "peer #%i (%s) receives a pong\n",
249 mc_peer->peer, 248 mc_peer->peer,
250 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 249 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
251 mc_peer->test_ok = GNUNET_OK; 250 mc_peer->test_ok = GNUNET_OK;
@@ -269,9 +268,9 @@ origin_join_request (void *cls,
269 268
270 uint8_t data_size = ntohs (join_msg->size); 269 uint8_t data_size = ntohs (join_msg->size);
271 270
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 271 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
273 "origin got a join request...\n"); 272 "origin got a join request...\n");
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
275 "origin receives: '%s'\n", (char *)&join_msg[1]); 274 "origin receives: '%s'\n", (char *)&join_msg[1]);
276 275
277 char data[] = "Come in!"; 276 char data[] = "Come in!";
@@ -281,7 +280,7 @@ origin_join_request (void *cls,
281 join_resp->type = htons (123); 280 join_resp->type = htons (123);
282 GNUNET_memcpy (&join_resp[1], data, data_size); 281 GNUNET_memcpy (&join_resp[1], data, data_size);
283 282
284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 283 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
285 "origin sends: '%s'\n", data); 284 "origin sends: '%s'\n", data);
286 285
287 GNUNET_MULTICAST_join_decision (jh, 286 GNUNET_MULTICAST_join_decision (jh,
@@ -311,7 +310,7 @@ origin_replay_msg (void *cls,
311 uint64_t message_id, 310 uint64_t message_id,
312 uint64_t fragment_offset, 311 uint64_t fragment_offset,
313 uint64_t flags, 312 uint64_t flags,
314 struct GNUNET_MULTICAST_ReplayHandle *rh) 313 struct GNUNET_MULTICAST_ReplayHandle *rh)
315{ 314{
316 315
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n"); 316 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
@@ -319,8 +318,8 @@ origin_replay_msg (void *cls,
319 318
320 319
321static int 320static int
322origin_notify (void *cls, 321origin_notify (void *cls,
323 size_t *data_size, 322 size_t *data_size,
324 void *data) 323 void *data)
325{ 324{
326 struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls; 325 struct pingpong_msg *rcv_pp_msg = (struct pingpong_msg*)cls;
@@ -329,11 +328,12 @@ origin_notify (void *cls,
329 pp_msg->peer = rcv_pp_msg->peer; 328 pp_msg->peer = rcv_pp_msg->peer;
330 pp_msg->msg = PONG; 329 pp_msg->msg = PONG;
331 *data_size = sizeof (struct pingpong_msg); 330 *data_size = sizeof (struct pingpong_msg);
332 memcpy(data, pp_msg, *data_size); 331 GNUNET_memcpy(data, pp_msg, *data_size);
332 GNUNET_free (pp_msg);
333 333
334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n"); 334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends pong\n");
335 335
336 return GNUNET_YES; 336 return GNUNET_YES;
337} 337}
338 338
339 339
@@ -345,7 +345,7 @@ origin_request (void *cls,
345 345
346 req++; 346 req++;
347 struct pingpong_msg *pp_msg = (struct pingpong_msg *) req; 347 struct pingpong_msg *pp_msg = (struct pingpong_msg *) req;
348 348
349 if (1 != pp_msg->msg) { 349 if (1 != pp_msg->msg) {
350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); 350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
351 } 351 }
@@ -360,7 +360,7 @@ origin_request (void *cls,
360 360
361static void 361static void
362origin_message (void *cls, 362origin_message (void *cls,
363 const struct GNUNET_MULTICAST_MessageHeader *msg) 363 const struct GNUNET_MULTICAST_MessageHeader *msg)
364{ 364{
365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); 365 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
366} 366}
@@ -386,7 +386,7 @@ multicast_connect (void *cls,
386 { 386 {
387 group_key = GNUNET_CRYPTO_eddsa_key_create (); 387 group_key = GNUNET_CRYPTO_eddsa_key_create ();
388 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); 388 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
389 389
390 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash); 390 GNUNET_CRYPTO_hash (&group_pub_key, sizeof (group_pub_key), &group_pub_key_hash);
391 origin = GNUNET_MULTICAST_origin_start (cfg, 391 origin = GNUNET_MULTICAST_origin_start (cfg,
392 group_key, 392 group_key,
@@ -414,7 +414,7 @@ multicast_connect (void *cls,
414 { 414 {
415 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create (); 415 multicast_peer->key = GNUNET_CRYPTO_ecdsa_key_create ();
416 416
417 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?", 417 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
418 multicast_peer->peer, 418 multicast_peer->peer,
419 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id)); 419 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id));
420 uint8_t data_size = strlen (data) + 1; 420 uint8_t data_size = strlen (data) + 1;
@@ -424,7 +424,7 @@ multicast_connect (void *cls,
424 GNUNET_memcpy (&join_msg[1], data, data_size); 424 GNUNET_memcpy (&join_msg[1], data, data_size);
425 425
426 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 426 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
427 "Peer #%u (%s) tries to join multicast group %s\n", 427 "Peer #%u (%s) tries to join multicast group %s\n",
428 multicast_peer->peer, 428 multicast_peer->peer,
429 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id), 429 GNUNET_i2s (multicast_peers[multicast_peer->peer]->id),
430 GNUNET_h2s (&group_pub_key_hash)); 430 GNUNET_h2s (&group_pub_key_hash));
@@ -465,12 +465,12 @@ peer_information_cb (void *cls,
465 multicast_peers[mc_peer->peer]->id = pinfo->result.id; 465 multicast_peers[mc_peer->peer]->id = pinfo->result.id;
466 466
467 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 467 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
468 "Got peer information of %s (%s)\n", 468 "Got peer information of %s (%s)\n",
469 (0 == mc_peer->peer)? "origin" : "member", 469 (0 == mc_peer->peer)? "origin" : "member",
470 GNUNET_i2s (pinfo->result.id)); 470 GNUNET_i2s (pinfo->result.id));
471 471
472 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 472 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
473 "Create peer #%u (%s)\n", 473 "Create peer #%u (%s)\n",
474 mc_peer->peer, 474 mc_peer->peer,
475 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 475 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
476 476
@@ -479,7 +479,7 @@ peer_information_cb (void *cls,
479 /* connect to multicast service of members */ 479 /* connect to multicast service of members */
480 op[mc_peer->peer] = 480 op[mc_peer->peer] =
481 GNUNET_TESTBED_service_connect (/* Closure for operation */ 481 GNUNET_TESTBED_service_connect (/* Closure for operation */
482 NULL, 482 NULL,
483 /* The peer whose service to connect to */ 483 /* The peer whose service to connect to */
484 peers[mc_peer->peer], 484 peers[mc_peer->peer],
485 /* The name of the service */ 485 /* The name of the service */
@@ -508,8 +508,8 @@ service_connect (void *cls,
508 508
509 if (NULL == ca_result) 509 if (NULL == ca_result)
510 { 510 {
511 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 511 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
512 "Connection adapter not created for peer #%u (%s)\n", 512 "Connection adapter not created for peer #%u (%s)\n",
513 mc_peer->peer, 513 mc_peer->peer,
514 GNUNET_i2s (multicast_peers[mc_peer->peer]->id)); 514 GNUNET_i2s (multicast_peers[mc_peer->peer]->id));
515 515
@@ -519,8 +519,8 @@ service_connect (void *cls,
519 519
520 if (0 == mc_peer->peer) 520 if (0 == mc_peer->peer)
521 { 521 {
522 // Get GNUnet identity of members 522 // Get GNUnet identity of members
523 for (int i = 0; i<PEERS_REQUESTED; i++) 523 for (int i = 0; i<PEERS_REQUESTED; i++)
524 { 524 {
525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i], 525 pi_op[i] = GNUNET_TESTBED_peer_get_information (peers[i],
526 GNUNET_TESTBED_PIT_IDENTITY, 526 GNUNET_TESTBED_PIT_IDENTITY,
@@ -547,7 +547,7 @@ service_connect (void *cls,
547 * @param PEERS_REQUESTED size of the 'peers' array 547 * @param PEERS_REQUESTED size of the 'peers' array
548 * @param links_succeeded number of links between peers that were created 548 * @param links_succeeded number of links between peers that were created
549 * @param links_failed number of links testbed was unable to establish 549 * @param links_failed number of links testbed was unable to establish
550 */ 550 */
551static void 551static void
552testbed_master (void *cls, 552testbed_master (void *cls,
553 struct GNUNET_TESTBED_RunHandle *h, 553 struct GNUNET_TESTBED_RunHandle *h,
@@ -562,7 +562,7 @@ testbed_master (void *cls,
562 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*); 562 multicast_peers = GNUNET_new_array (PEERS_REQUESTED, struct MulticastPeerContext*);
563 563
564 // Create test contexts for members 564 // Create test contexts for members
565 for (int i = 0; i<PEERS_REQUESTED; i++) 565 for (int i = 0; i<PEERS_REQUESTED; i++)
566 { 566 {
567 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext); 567 multicast_peers[i] = GNUNET_new (struct MulticastPeerContext);
568 multicast_peers[i]->peer = i; 568 multicast_peers[i]->peer = i;
@@ -604,7 +604,7 @@ main (int argc, char *argv[])
604 int ret; 604 int ret;
605 char const *config_file; 605 char const *config_file;
606 606
607 if (strstr (argv[0], "_line") != NULL) 607 if (strstr (argv[0], "_line") != NULL)
608 { 608 {
609 config_file = "test_multicast_line.conf"; 609 config_file = "test_multicast_line.conf";
610 } 610 }
@@ -612,7 +612,7 @@ main (int argc, char *argv[])
612 { 612 {
613 config_file = "test_multicast_star.conf"; 613 config_file = "test_multicast_star.conf";
614 } 614 }
615 else 615 else
616 { 616 {
617 config_file = "test_multicast_star.conf"; 617 config_file = "test_multicast_star.conf";
618 } 618 }
@@ -620,19 +620,19 @@ main (int argc, char *argv[])
620 result = GNUNET_SYSERR; 620 result = GNUNET_SYSERR;
621 ret = 621 ret =
622 GNUNET_TESTBED_test_run ("test-multicast-multipeer", 622 GNUNET_TESTBED_test_run ("test-multicast-multipeer",
623 config_file, 623 config_file,
624 /* number of peers to start */ 624 /* number of peers to start */
625 PEERS_REQUESTED, 625 PEERS_REQUESTED,
626 /* Event mask - set to 0 for no event notifications */ 626 /* Event mask - set to 0 for no event notifications */
627 0LL, 627 0LL,
628 /* Controller event callback */ 628 /* Controller event callback */
629 NULL, 629 NULL,
630 /* Closure for controller event callback */ 630 /* Closure for controller event callback */
631 NULL, 631 NULL,
632 /* called when testbed setup is complete */ 632 /* called when testbed setup is complete */
633 testbed_master, 633 testbed_master,
634 /* Closure for the test_master callback */ 634 /* Closure for the test_master callback */
635 NULL); 635 NULL);
636 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 636 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
637 return 1; 637 return 1;
638 return 0; 638 return 0;