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.c430
1 files changed, 335 insertions, 95 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 3edf0153e..58e43d4ba 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -35,16 +35,24 @@
35 35
36#define NUM_PEERS 2 36#define NUM_PEERS 2
37 37
38static struct GNUNET_TESTBED_Operation *peer0; 38static struct GNUNET_TESTBED_Operation *op0;
39static struct GNUNET_TESTBED_Operation *peer1; 39static struct GNUNET_TESTBED_Operation *op1;
40static struct GNUNET_TESTBED_Operation *pi_op0;
41static struct GNUNET_TESTBED_Operation *pi_op1;
42
43static struct GNUNET_TESTBED_Peer **peers;
44const struct GNUNET_PeerIdentity *peer_id[2];
40 45
41static struct GNUNET_SCHEDULER_Task *timeout_tid; 46static struct GNUNET_SCHEDULER_Task *timeout_tid;
42 47
48static struct GNUNET_MULTICAST_Origin *origin;
49static struct GNUNET_MULTICAST_Member *member;
50
43struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; 51struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
44struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; 52struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
45 53
46struct GNUNET_CRYPTO_EcdsaPrivateKey *member1_key; 54struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key;
47struct GNUNET_CRYPTO_EcdsaPublicKey member1_pub_key; 55struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
48 56
49 57
50enum 58enum
@@ -68,10 +76,25 @@ static int result;
68static void 76static void
69shutdown_task (void *cls) 77shutdown_task (void *cls)
70{ 78{
71 if (NULL != peer0) 79 if (NULL != op0)
80 {
81 GNUNET_TESTBED_operation_done (op0);
82 op0 = NULL;
83 }
84 if (NULL != op1)
85 {
86 GNUNET_TESTBED_operation_done (op1);
87 op1 = NULL;
88 }
89 if (NULL != pi_op0)
90 {
91 GNUNET_TESTBED_operation_done (pi_op0);
92 pi_op0 = NULL;
93 }
94 if (NULL != pi_op1)
72 { 95 {
73 GNUNET_TESTBED_operation_done (peer0); 96 GNUNET_TESTBED_operation_done (pi_op1);
74 peer0 = NULL; 97 pi_op1 = NULL;
75 } 98 }
76 if (NULL != timeout_tid) 99 if (NULL != timeout_tid)
77 { 100 {
@@ -84,7 +107,6 @@ shutdown_task (void *cls)
84static void 107static void
85timeout_task (void *cls) 108timeout_task (void *cls)
86{ 109{
87 timeout_tid = NULL;
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 "Timeout!\n"); 111 "Timeout!\n");
90 result = GNUNET_SYSERR; 112 result = GNUNET_SYSERR;
@@ -93,112 +115,275 @@ timeout_task (void *cls)
93 115
94 116
95static void 117static void
96origin_recv_replay_msg (void *cls, 118member_join_request (void *cls,
97 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, 119 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
98 uint64_t message_id, 120 const struct GNUNET_MessageHeader *join_msg,
99 uint64_t fragment_offset, 121 struct GNUNET_MULTICAST_JoinHandle *jh)
100 uint64_t flags,
101 struct GNUNET_MULTICAST_ReplayHandle *rh)
102{ 122{
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 123 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Test #%u: origin_recv_replay_msg()\n", test); 124 "Member sent a join request.\n");
105 GNUNET_assert (0); 125
126}
127
128int 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;
106} 141}
107 142
108 143
109static void 144static void
110member_recv_replay_msg (void *cls, 145member_join_decision (void *cls,
111 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, 146 int is_admitted,
112 uint64_t message_id, 147 const struct GNUNET_PeerIdentity *peer,
113 uint64_t fragment_offset, 148 uint16_t relay_count,
114 uint64_t flags, 149 const struct GNUNET_PeerIdentity *relays,
115 struct GNUNET_MULTICAST_ReplayHandle *rh) 150 const struct GNUNET_MessageHeader *join_msg)
116{ 151{
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 152 struct GNUNET_MULTICAST_MemberTransmitHandle *req;
118 "Test #%u: member_recv_replay_msg()\n", test); 153
119 GNUNET_assert (0); 154 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
155 "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected");
156
157 if (GNUNET_YES == is_admitted)
158 {
159 req = GNUNET_MULTICAST_member_to_origin (member,
160 0,
161 notify,
162 NULL);
163
164 }
120} 165}
121 166
122
123static void 167static void
124origin_recv_replay_frag (void *cls, 168member_replay_frag ()
125 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
126 uint64_t fragment_id,
127 uint64_t flags,
128 struct GNUNET_MULTICAST_ReplayHandle *rh)
129{ 169{
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 170 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "Test #%u: origin_recv_replay_frag()" 171 "member replay frag...\n");
132 " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
133 test, fragment_id, flags);
134} 172}
135 173
174static void
175member_replay_msg ()
176{
177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
178 "member replay msg...\n");
179}
136 180
137/**
138 * Test: origin receives join request
139 */
140static void 181static void
141origin_recv_join_request (void *cls, 182member_message ()
142 const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
143 const struct GNUNET_MessageHeader *join_msg,
144 struct GNUNET_MULTICAST_JoinHandle *jh)
145{ 183{
146 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 184 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
147 "Test #%u: origin_recv_join_request()\n", test); 185 "member message...\n");
186
187 // FIXME: not finished here
188 result = GNUNET_YES;
189 GNUNET_SCHEDULER_shutdown ();
148} 190}
149 191
192static void
193origin_join_request (void *cls,
194 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
195 const struct GNUNET_MessageHeader *join_msg,
196 struct GNUNET_MULTICAST_JoinHandle *jh)
197{
198 struct GNUNET_MessageHeader *join_resp;
199
200 uint8_t data_size = ntohs (join_msg->size);
201
202 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
203 "origin got a join request...\n");
204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
205 "origin receives: '%s'\n", (char *)&join_msg[1]);
206
207 char data[] = "Come in!";
208 data_size = strlen (data) + 1;
209 join_resp = GNUNET_malloc (sizeof (join_resp) + data_size);
210 join_resp->size = htons (sizeof (join_resp) + data_size);
211 join_resp->type = htons (123);
212 GNUNET_memcpy (&join_resp[1], data, data_size);
213
214 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
215 "origin sends: '%s'\n", data);
216
217 GNUNET_MULTICAST_join_decision (jh,
218 GNUNET_YES,
219 0,
220 NULL,
221 join_resp);
222
223 result = GNUNET_OK;
224}
150 225
151static void 226static void
152origin_recv_request (void *cls, 227origin_replay_frag (void *cls,
153 const struct GNUNET_MULTICAST_RequestHeader *req) 228 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
229 uint64_t fragment_id,
230 uint64_t flags,
231 struct GNUNET_MULTICAST_ReplayHandle *rh)
154{ 232{
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n");
156 "Test #%u: origin_recv_request()\n", 234}
157 test); 235
236static void
237origin_replay_msg (void *cls,
238 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
239 uint64_t message_id,
240 uint64_t fragment_offset,
241 uint64_t flags,
242 struct GNUNET_MULTICAST_ReplayHandle *rh)
243{
244
245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
246}
247
248
249int
250origin_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;
158} 261}
159 262
160 263
161static void 264static void
162origin_recv_message (void *cls, 265origin_request (void *cls,
163 const struct GNUNET_MULTICAST_MessageHeader *msg) 266 const struct GNUNET_MULTICAST_RequestHeader *req)
164{ 267{
165 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 268 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]);
166 "Test #%u: origin_recv_message()\n", 269
167 test); 270 if (0 != strncmp ("ping", (char *)&req[1], 4)) {
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request");
272 }
273
274 GNUNET_MULTICAST_origin_to_all (origin,
275 0,
276 0,
277 origin_notify,
278 NULL);
168} 279}
169 280
281static void
282origin_message (void *cls,
283 const struct GNUNET_MULTICAST_MessageHeader *msg)
284{
285 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n");
286}
287
288
289static void
290service_connect1 (void *cls,
291 struct GNUNET_TESTBED_Operation *op,
292 void *ca_result,
293 const char *emsg)
294{
295 member = ca_result;
296
297 if (NULL != member)
298 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n");
299 else
300 result = GNUNET_SYSERR;
301}
170 302
171static void 303static void
172service_close_peer0 (void *cls, 304multicast_da1 (void *cls,
173 void *op_result) 305 void * op_result)
174{ 306{
175 struct GNUNET_MULTICAST_Origin *orig = op_result; 307 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
308 "Member parting from multicast group\n");
176 309
177 GNUNET_MULTICAST_origin_stop (orig, NULL, NULL); 310 GNUNET_MULTICAST_member_part (member, NULL, NULL);
178} 311}
179 312
180 313
181/**
182 * Function run when service multicast has started and is providing us
183 * with a configuration file.
184 */
185static void * 314static void *
186service_conf_peer0 (void *cls, 315multicast_ca1 (void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg) 316 const struct GNUNET_CONFIGURATION_Handle *cfg)
188{ 317{
189 group_key = GNUNET_CRYPTO_eddsa_key_create (); 318 struct GNUNET_MessageHeader *join_msg;
190 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); 319
320 // Get members keys
321 member_key = GNUNET_CRYPTO_ecdsa_key_create ();
322 GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key);
323
324 char data[] = "Hi, can I enter?";
325 uint8_t data_size = strlen (data) + 1;
326 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
327 join_msg->size = htons (sizeof (join_msg) + data_size);
328 join_msg->type = htons (123);
329 GNUNET_memcpy (&join_msg[1], data, data_size);
191 330
192 return GNUNET_MULTICAST_origin_start (cfg, group_key, 0, 331 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
193 origin_recv_join_request, 332 "Members tries to join multicast group\n");
194 origin_recv_replay_frag, 333
195 origin_recv_replay_msg, 334 return GNUNET_MULTICAST_member_join (cfg,
196 origin_recv_request, 335 &group_pub_key,
197 origin_recv_message, 336 member_key,
198 NULL); 337 peer_id[0],
338 0,
339 NULL,
340 join_msg, /* join message */
341 member_join_request,
342 member_join_decision,
343 member_replay_frag,
344 member_replay_msg,
345 member_message,
346 NULL);
199} 347}
200 348
201 349
350static void
351peer_information_cb (void *cls,
352 struct GNUNET_TESTBED_Operation *op,
353 const struct GNUNET_TESTBED_PeerInformation *pinfo,
354 const char *emsg)
355{
356 int i = (int) (long) cls;
357
358 if (NULL == pinfo) {
359 result = GNUNET_SYSERR;
360 GNUNET_SCHEDULER_shutdown ();
361 }
362
363 peer_id[i] = pinfo->result.id;
364
365 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
366 "Got peer information of %s (%s)\n", (0==i)?"origin":"member" ,GNUNET_i2s(pinfo->result.id));
367
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
369 "Create member peer\n");
370
371 if (0 == i) {
372 /* connect to multicast service of member */
373 op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */
374 peers[1], /* The peer whose service to connect to */
375 "multicast", /* The name of the service */
376 service_connect1, /* callback to call after a handle to service
377 is opened */
378 NULL, /* closure for the above callback */
379 multicast_ca1, /* callback to call with peer's configuration;
380 this should open the needed service connection */
381 multicast_da1, /* callback to be called when closing the
382 opened service connection */
383 NULL); /* closure for the above two callbacks */
384 }
385}
386
202/** 387/**
203 * Test logic of peer "0" being origin starts here. 388 * Test logic of peer "0" being origin starts here.
204 * 389 *
@@ -210,17 +395,65 @@ service_conf_peer0 (void *cls,
210 * connect to the DHT. 395 * connect to the DHT.
211 */ 396 */
212static void 397static void
213service_connect_peer0 (void *cls, 398service_connect0 (void *cls,
214 struct GNUNET_TESTBED_Operation *op, 399 struct GNUNET_TESTBED_Operation *op,
215 void *ca_result, 400 void *ca_result,
216 const char *emsg) 401 const char *emsg)
217{ 402{
218 struct GNUNET_MULTICAST_Origin *orig = ca_result; 403 origin = ca_result;
404
405 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
406 "Connected to multicast service of origin\n");
407
408 // Get GNUnet identity of origin
409 pi_op0 = GNUNET_TESTBED_peer_get_information (peers[0],
410 GNUNET_TESTBED_PIT_IDENTITY,
411 peer_information_cb,
412 (void *) 0);
413 // Get GNUnet identity of member
414 pi_op1 = GNUNET_TESTBED_peer_get_information (peers[1],
415 GNUNET_TESTBED_PIT_IDENTITY,
416 peer_information_cb,
417 (void *) 1);
219 418
220 /* Connection to service successful. Here we'd usually do something with 419 /* Connection to service successful. Here we'd usually do something with
221 * the service. */ 420 * the service. */
222 result = GNUNET_OK; 421 result = GNUNET_OK;
223 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */ 422 //GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
423}
424
425
426
427/**
428 * Function run when service multicast has started and is providing us
429 * with a configuration file.
430 */
431static void *
432multicast_ca0 (void *cls,
433 const struct GNUNET_CONFIGURATION_Handle *cfg)
434{
435 group_key = GNUNET_CRYPTO_eddsa_key_create ();
436 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
437
438 return GNUNET_MULTICAST_origin_start (cfg,
439 group_key,
440 0,
441 origin_join_request,
442 origin_replay_frag,
443 origin_replay_msg,
444 origin_request,
445 origin_message,
446 NULL);
447}
448
449static void
450multicast_da0 (void *cls,
451 void *op_result)
452{
453 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
454 "Origin closes multicast group\n");
455
456 GNUNET_MULTICAST_origin_stop (origin, NULL, NULL);
224} 457}
225 458
226 459
@@ -241,31 +474,38 @@ service_connect_peer0 (void *cls,
241 * @param links_failed number of links testbed was unable to establish 474 * @param links_failed number of links testbed was unable to establish
242 */ 475 */
243static void 476static void
244run (void *cls, 477testbed_master (void *cls,
245 struct GNUNET_TESTBED_RunHandle *h, 478 struct GNUNET_TESTBED_RunHandle *h,
246 unsigned int num_peers, 479 unsigned int num_peers,
247 struct GNUNET_TESTBED_Peer **peers, 480 struct GNUNET_TESTBED_Peer **p,
248 unsigned int links_succeeded, 481 unsigned int links_succeeded,
249 unsigned int links_failed) 482 unsigned int links_failed)
250{ 483{
251 /* Testbed is ready with peers running and connected in a pre-defined overlay 484 /* Testbed is ready with peers running and connected in a pre-defined overlay
252 topology (FIXME) */ 485 topology (FIXME) */
486 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
487 "Connected to testbed_master()\n");
488
489 peers = p;
253 490
254 /* connect to a peers service */ 491 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
255 peer0 = GNUNET_TESTBED_service_connect 492 "Create origin peer\n");
256 (NULL, /* Closure for operation */ 493 op0 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */
257 peers[0], /* The peer whose service to connect to */ 494 peers[0], /* The peer whose service to connect to */
258 "multicast", /* The name of the service */ 495 "multicast", /* The name of the service */
259 &service_connect_peer0, /* callback to call after a handle to service 496 service_connect0, /* callback to call after a handle to service
260 is opened */ 497 is opened */
261 NULL, /* closure for the above callback */ 498 NULL, /* closure for the above callback */
262 &service_conf_peer0, /* callback to call with peer's configuration; 499 multicast_ca0, /* callback to call with peer's configuration;
263 this should open the needed service connection */ 500 this should open the needed service connection */
264 &service_close_peer0, /* callback to be called when closing the 501 multicast_da0, /* callback to be called when closing the
265 opened service connection */ 502 opened service connection */
266 NULL); /* closure for the above two callbacks */ 503 NULL); /* closure for the above two callbacks */
267 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 504
268 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 505 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */
506
507 /* Schedule the shutdown task with a delay of a few Seconds */
508 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 48),
269 &timeout_task, NULL); 509 &timeout_task, NULL);
270} 510}
271 511
@@ -283,7 +523,7 @@ main (int argc, char *argv[])
283 0LL, /* Event mask - set to 0 for no event notifications */ 523 0LL, /* Event mask - set to 0 for no event notifications */
284 NULL, /* Controller event callback */ 524 NULL, /* Controller event callback */
285 NULL, /* Closure for controller event callback */ 525 NULL, /* Closure for controller event callback */
286 run, /* continuation callback to be called when testbed setup is complete */ 526 testbed_master, /* continuation callback to be called when testbed setup is complete */
287 NULL); /* Closure for the test_master callback */ 527 NULL); /* Closure for the test_master callback */
288 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 528 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
289 return 1; 529 return 1;