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.c93
1 files changed, 57 insertions, 36 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index c2078abf9..5c3664f35 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -33,14 +33,15 @@
33#include "gnunet_testbed_service.h" 33#include "gnunet_testbed_service.h"
34#include "gnunet_multicast_service.h" 34#include "gnunet_multicast_service.h"
35 35
36#define NUM_PEERS 3 36#define NUM_PEERS 2
37 37
38struct multicast_peer 38struct multicast_peer
39{ 39{
40 int peer; /* peer number */ 40 int peer; /* peer number */
41 const struct GNUNET_PeerIdentity *id;
41 struct GNUNET_TESTBED_Operation *op; /* not yet in use */ 42 struct GNUNET_TESTBED_Operation *op; /* not yet in use */
42 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */ 43 struct GNUNET_TESTBED_Operation *pi_op; /* not yet in use */
43 uint8_t test_ok; 44 int test_ok;
44}; 45};
45 46
46static void service_connect (void *cls, 47static void service_connect (void *cls,
@@ -54,7 +55,6 @@ static struct GNUNET_TESTBED_Peer **peers;
54// FIXME: refactor 55// FIXME: refactor
55static struct GNUNET_TESTBED_Operation *op[NUM_PEERS]; 56static struct GNUNET_TESTBED_Operation *op[NUM_PEERS];
56static struct GNUNET_TESTBED_Operation *pi_op[NUM_PEERS]; 57static struct GNUNET_TESTBED_Operation *pi_op[NUM_PEERS];
57static const struct GNUNET_PeerIdentity *peer_id[NUM_PEERS];
58 58
59static struct GNUNET_MULTICAST_Origin *origin; 59static struct GNUNET_MULTICAST_Origin *origin;
60static struct GNUNET_MULTICAST_Member *member[NUM_PEERS]; /* first element always empty */ 60static struct GNUNET_MULTICAST_Member *member[NUM_PEERS]; /* first element always empty */
@@ -80,16 +80,6 @@ static int result;
80static void 80static void
81shutdown_task (void *cls) 81shutdown_task (void *cls)
82{ 82{
83 if (NULL != mc_peers)
84 {
85 for (int i=0; i < NUM_PEERS; i++)
86 {
87 GNUNET_free (mc_peers[i]);
88 mc_peers[i] = NULL;
89 }
90 GNUNET_free (mc_peers);
91 }
92
93 for (int i=0;i<NUM_PEERS;i++) 83 for (int i=0;i<NUM_PEERS;i++)
94 { 84 {
95 if (NULL != op[i]) 85 if (NULL != op[i])
@@ -104,6 +94,16 @@ shutdown_task (void *cls)
104 } 94 }
105 } 95 }
106 96
97 if (NULL != mc_peers)
98 {
99 for (int i=0; i < NUM_PEERS; i++)
100 {
101 GNUNET_free (mc_peers[i]);
102 mc_peers[i] = NULL;
103 }
104 GNUNET_free (mc_peers);
105 }
106
107 if (NULL != timeout_tid) 107 if (NULL != timeout_tid)
108 { 108 {
109 GNUNET_SCHEDULER_cancel (timeout_tid); 109 GNUNET_SCHEDULER_cancel (timeout_tid);
@@ -130,8 +130,9 @@ member_join_request (void *cls,
130{ 130{
131 struct multicast_peer *mc_peer = (struct multicast_peer*)cls; 131 struct multicast_peer *mc_peer = (struct multicast_peer*)cls;
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 132 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
133 "Peer #%u sent a join request.\n", mc_peer->peer); 133 "Peer #%u (%s) sent a join request.\n",
134 134 mc_peer->peer,
135 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
135} 136}
136 137
137 138
@@ -165,7 +166,10 @@ member_join_decision (void *cls,
165 struct GNUNET_MULTICAST_MemberTransmitHandle *req; 166 struct GNUNET_MULTICAST_MemberTransmitHandle *req;
166 167
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 168 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
168 "Peer #%u received a decision from origin: %s\n", mc_peer->peer, (GNUNET_YES == is_admitted)?"accepted":"rejected"); 169 "Peer #%u (%s) received a decision from origin: %s\n",
170 mc_peer->peer,
171 GNUNET_i2s (mc_peers[mc_peer->peer]->id),
172 (GNUNET_YES == is_admitted)?"accepted":"rejected");
169 173
170 if (GNUNET_YES == is_admitted) 174 if (GNUNET_YES == is_admitted)
171 { 175 {
@@ -203,29 +207,30 @@ member_message (void *cls,
203 if (0 != strncmp ("pong", (char *)&msg[1], 4)) 207 if (0 != strncmp ("pong", (char *)&msg[1], 4))
204 { 208 {
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 "peer #%i did not receive pong\n", 210 "peer #%i (%s) did not receive pong\n",
207 mc_peer->peer); 211 mc_peer->peer,
212 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
208 213
209 result = GNUNET_SYSERR; 214 result = GNUNET_SYSERR;
210 GNUNET_SCHEDULER_shutdown (); 215 GNUNET_SCHEDULER_shutdown ();
211 } 216 }
212 217
213 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 218 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
214 "peer #%i receives: %s\n", 219 "peer #%i (%s) receives: %s\n",
215 mc_peer->peer, 220 mc_peer->peer,
221 GNUNET_i2s (mc_peers[mc_peer->peer]->id),
216 (char *)&msg[1]); 222 (char *)&msg[1]);
217 223
218 mc_peer->test_ok = GNUNET_OK; 224 mc_peer->test_ok = GNUNET_OK;
219 225
220 // FIXME: ugly test function 226 // FIXME: ugly test function
221 /* 227 // (we start with 1 because 0 is origin)
222 for (int i=1; i<NUM_PEERS; i++) 228 for (int i=1; i<NUM_PEERS; i++)
223 if (!mc_peers[i]->test_ok) 229 if (GNUNET_NO == mc_peers[i]->test_ok)
224 return; 230 return;
225 231
226 result = GNUNET_YES; 232 result = GNUNET_YES;
227 GNUNET_SCHEDULER_shutdown(); 233 GNUNET_SCHEDULER_shutdown();
228 */
229} 234}
230 235
231 236
@@ -345,7 +350,9 @@ multicast_da (void *cls,
345 else 350 else
346 { 351 {
347 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 352 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
348 "peer #%u parting from multicast group\n", mc_peer->peer); 353 "peer #%u (%s) parting from multicast group\n",
354 mc_peer->peer,
355 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
349 356
350 GNUNET_MULTICAST_member_part (member[mc_peer->peer], NULL, cls); 357 GNUNET_MULTICAST_member_part (member[mc_peer->peer], NULL, cls);
351 } 358 }
@@ -381,9 +388,12 @@ multicast_ca (void *cls,
381 // Get members keys 388 // Get members keys
382 member_pub_key[mc_peer->peer] = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); 389 member_pub_key[mc_peer->peer] = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
383 member_key[mc_peer->peer] = GNUNET_CRYPTO_ecdsa_key_create (); 390 member_key[mc_peer->peer] = GNUNET_CRYPTO_ecdsa_key_create ();
384 GNUNET_CRYPTO_ecdsa_key_get_public (member_key[mc_peer->peer], member_pub_key[mc_peer->peer]); 391 GNUNET_CRYPTO_ecdsa_key_get_public (member_key[mc_peer->peer],
392 member_pub_key[mc_peer->peer]);
385 393
386 sprintf(data, "Hi, I am peer #%u. Can I enter?", mc_peer->peer); 394 sprintf(data, "Hi, I am peer #%u (%s). Can I enter?",
395 mc_peer->peer,
396 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
387 uint8_t data_size = strlen (data) + 1; 397 uint8_t data_size = strlen (data) + 1;
388 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); 398 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
389 join_msg->size = htons (sizeof (join_msg) + data_size); 399 join_msg->size = htons (sizeof (join_msg) + data_size);
@@ -391,12 +401,14 @@ multicast_ca (void *cls,
391 GNUNET_memcpy (&join_msg[1], data, data_size); 401 GNUNET_memcpy (&join_msg[1], data, data_size);
392 402
393 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 403 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
394 "Peer #%u tries to join multicast group\n", mc_peer->peer); 404 "Peer #%u (%s) tries to join multicast group\n",
405 mc_peer->peer,
406 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
395 407
396 return GNUNET_MULTICAST_member_join (cfg, 408 return GNUNET_MULTICAST_member_join (cfg,
397 group_pub_key, 409 group_pub_key,
398 member_key[mc_peer->peer], 410 member_key[mc_peer->peer],
399 peer_id[0], 411 mc_peers[0]->id,
400 0, 412 0,
401 NULL, 413 NULL,
402 join_msg, /* join message */ 414 join_msg, /* join message */
@@ -424,13 +436,17 @@ peer_information_cb (void *cls,
424 GNUNET_SCHEDULER_shutdown (); 436 GNUNET_SCHEDULER_shutdown ();
425 } 437 }
426 438
427 peer_id[mc_peer->peer] = pinfo->result.id; 439 mc_peers[mc_peer->peer]->id = pinfo->result.id;
428 440
429 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 441 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
430 "Got peer information of %s (%s)\n", (0==mc_peer->peer)?"origin":"member" ,GNUNET_i2s(pinfo->result.id)); 442 "Got peer information of %s (%s)\n",
443 (0 == mc_peer->peer)? "origin" : "member",
444 GNUNET_i2s (pinfo->result.id));
431 445
432 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 446 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
433 "Create peer #%u\n", mc_peer->peer); 447 "Create peer #%u (%s)\n",
448 mc_peer->peer,
449 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
434 450
435 if (0 != mc_peer->peer) 451 if (0 != mc_peer->peer)
436 { 452 {
@@ -461,13 +477,18 @@ service_connect (void *cls,
461 if (NULL == ca_result) 477 if (NULL == ca_result)
462 { 478 {
463 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 479 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
464 "Connection adapter not created for peer #%u\n", mc_peer->peer); 480 "Connection adapter not created for peer #%u (%s)\n",
481 mc_peer->peer,
482 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
483
465 result = GNUNET_SYSERR; 484 result = GNUNET_SYSERR;
466 GNUNET_SCHEDULER_shutdown(); 485 GNUNET_SCHEDULER_shutdown();
467 } 486 }
468 487
469 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 488 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
470 "Connected to multicast service of peer #%u\n", mc_peer->peer); 489 "Connected to multicast service of peer #%u (%s)\n",
490 mc_peer->peer,
491 GNUNET_i2s (mc_peers[mc_peer->peer]->id));
471 492
472 if (0 == mc_peer->peer) 493 if (0 == mc_peer->peer)
473 { 494 {
@@ -525,9 +546,6 @@ testbed_master (void *cls,
525 546
526 peers = p; 547 peers = p;
527 548
528 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
529 "Create origin peer\n");
530
531 mc_peers = GNUNET_new_array (NUM_PEERS, struct multicast_peer*); 549 mc_peers = GNUNET_new_array (NUM_PEERS, struct multicast_peer*);
532 550
533 // Create test contexts for members 551 // Create test contexts for members
@@ -538,6 +556,9 @@ testbed_master (void *cls,
538 mc_peers[i]->test_ok = GNUNET_NO; 556 mc_peers[i]->test_ok = GNUNET_NO;
539 } 557 }
540 558
559 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
560 "Create origin peer\n");
561
541 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ 562 op[0] = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */
542 peers[0], /* The peer whose service to connect to */ 563 peers[0], /* The peer whose service to connect to */
543 "multicast", /* The name of the service */ 564 "multicast", /* The name of the service */
@@ -553,7 +574,7 @@ testbed_master (void *cls,
553 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ 574 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */
554 575
555 /* Schedule the shutdown task with a delay of a few Seconds */ 576 /* Schedule the shutdown task with a delay of a few Seconds */
556 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80), 577 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 400),
557 &timeout_task, NULL); 578 &timeout_task, NULL);
558} 579}
559 580