aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport-testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r--src/transport/transport-testing.c146
1 files changed, 80 insertions, 66 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 899ef7851..defafbbc6 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -86,6 +86,16 @@ set_p1c (void *cls,
86 86
87 87
88static void 88static void
89set_mq (void *cls,
90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
91{
92 struct GNUNET_MQ_Handle *mq = cls;
93
94 cx->mq = mq;
95}
96
97
98static void
89set_p2c (void *cls, 99set_p2c (void *cls,
90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 100 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
91{ 101{
@@ -121,9 +131,10 @@ clear_p2c (void *cls,
121} 131}
122 132
123 133
124static void 134static void *
125notify_connect (void *cls, 135notify_connect (void *cls,
126 const struct GNUNET_PeerIdentity *peer) 136 const struct GNUNET_PeerIdentity *peer,
137 struct GNUNET_MQ_Handle *mq)
127{ 138{
128 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 139 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
129 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 140 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -132,12 +143,16 @@ notify_connect (void *cls,
132 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 143 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
133 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 144 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
134 int found; 145 int found;
146 void *ret;
135 147
136 p2 = find_peer_context (p->tth, 148 p2 = find_peer_context (p->tth,
137 peer); 149 peer);
138 if (NULL != p->nc) 150 if (NULL != p->nc)
139 p->nc (p->cb_cls, 151 ret = p->nc (p->cb_cls,
140 peer); 152 peer,
153 mq);
154 else
155 ret = NULL;
141 156
142 if (p2 != NULL) 157 if (p2 != NULL)
143 GNUNET_asprintf (&p2_s, 158 GNUNET_asprintf (&p2_s,
@@ -185,6 +200,10 @@ notify_connect (void *cls,
185 tth->cc_tail, 200 tth->cc_tail,
186 cc); 201 cc);
187 } 202 }
203 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
204 p2,
205 &set_mq,
206 mq);
188 /* update set connected flag for all requests */ 207 /* update set connected flag for all requests */
189 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 208 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
190 { 209 {
@@ -223,6 +242,7 @@ notify_connect (void *cls,
223 cc->cb = NULL; /* only notify once! */ 242 cc->cb = NULL; /* only notify once! */
224 } 243 }
225 } 244 }
245 return ret;
226} 246}
227 247
228 248
@@ -237,7 +257,8 @@ offer_hello (void *cls);
237 257
238static void 258static void
239notify_disconnect (void *cls, 259notify_disconnect (void *cls,
240 const struct GNUNET_PeerIdentity *peer) 260 const struct GNUNET_PeerIdentity *peer,
261 void *handler_cls)
241{ 262{
242 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 263 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
243 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 264 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -245,8 +266,6 @@ notify_disconnect (void *cls,
245 /* Find PeerContext */ 266 /* Find PeerContext */
246 int no = 0; 267 int no = 0;
247 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; 268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
248 struct TRANSPORT_TESTING_SendJob *sj;
249 struct TRANSPORT_TESTING_SendJob *sjn;
250 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 269 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
251 270
252 p2 = find_peer_context (p->tth, 271 p2 = find_peer_context (p->tth,
@@ -270,25 +289,15 @@ notify_disconnect (void *cls,
270 /* notify about disconnect */ 289 /* notify about disconnect */
271 if (NULL != p->nd) 290 if (NULL != p->nd)
272 p->nd (p->cb_cls, 291 p->nd (p->cb_cls,
273 peer); 292 peer,
293 handler_cls);
274 if (NULL == p2) 294 if (NULL == p2)
275 return; 295 return;
276 /* abort all transmissions this disconnected pair is involved in */ 296 /* clear MQ, it is now invalid */
277 for (sj = tth->sj_head; NULL != sj; sj = sjn) 297 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
278 { 298 p2,
279 sjn = sj->next; 299 &set_mq,
280 if ( ( (sj->sender == p2) && 300 NULL);
281 (sj->receiver == p) ) ||
282 ( (sj->receiver == p2) &&
283 (sj->sender == p) ) )
284 {
285 GNUNET_CONTAINER_DLL_remove (tth->sj_head,
286 tth->sj_tail,
287 sj);
288 GNUNET_TRANSPORT_notify_transmit_ready_cancel (sj->th);
289 GNUNET_free (sj);
290 }
291 }
292 /* update set connected flags for all requests */ 301 /* update set connected flags for all requests */
293 GNUNET_TRANSPORT_TESTING_find_connecting_context (p, 302 GNUNET_TRANSPORT_TESTING_find_connecting_context (p,
294 p2, 303 p2,
@@ -322,22 +331,6 @@ notify_disconnect (void *cls,
322 331
323 332
324static void 333static void
325notify_receive (void *cls,
326 const struct GNUNET_PeerIdentity *peer,
327 const struct GNUNET_MessageHeader *message)
328{
329 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
330
331 if (NULL == p)
332 return;
333 if (NULL != p->rec)
334 p->rec (p->cb_cls,
335 peer,
336 message);
337}
338
339
340static void
341get_hello (void *cb_cls, 334get_hello (void *cb_cls,
342 const struct GNUNET_MessageHeader *message) 335 const struct GNUNET_MessageHeader *message)
343{ 336{
@@ -359,8 +352,7 @@ get_hello (void *cb_cls,
359 "Peer %u (`%s') successfully started\n", 352 "Peer %u (`%s') successfully started\n",
360 p->no, 353 p->no,
361 GNUNET_i2s (&p->id)); 354 GNUNET_i2s (&p->id));
362 p->start_cb (p, 355 p->start_cb (p->start_cb_cls);
363 p->start_cb_cls);
364 p->start_cb = NULL; 356 p->start_cb = NULL;
365 } 357 }
366} 358}
@@ -371,7 +363,7 @@ get_hello (void *cb_cls,
371 * @param tth the testing handle 363 * @param tth the testing handle
372 * @param cfgname configuration file 364 * @param cfgname configuration file
373 * @param peer_id a unique number to identify the peer 365 * @param peer_id a unique number to identify the peer
374 * @param rec receive callback 366 * @param handlers functions for receiving messages
375 * @param nc connect callback 367 * @param nc connect callback
376 * @param nd disconnect callback 368 * @param nd disconnect callback
377 * @param cb_cls closure for callback 369 * @param cb_cls closure for callback
@@ -383,17 +375,18 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext *
383GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, 375GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
384 const char *cfgname, 376 const char *cfgname,
385 int peer_id, 377 int peer_id,
386 GNUNET_TRANSPORT_ReceiveCallback rec, 378 const struct GNUNET_MQ_MessageHandler *handlers,
387 GNUNET_TRANSPORT_NotifyConnect nc, 379 GNUNET_TRANSPORT_NotifyConnecT nc,
388 GNUNET_TRANSPORT_NotifyDisconnect nd, 380 GNUNET_TRANSPORT_NotifyDisconnecT nd,
389 void *cb_cls, 381 void *cb_cls,
390 GNUNET_TRANSPORT_TESTING_StartCallback start_cb, 382 GNUNET_SCHEDULER_TaskCallback start_cb,
391 void *start_cb_cls) 383 void *start_cb_cls)
392{ 384{
393 char *emsg = NULL; 385 char *emsg = NULL;
394 struct GNUNET_TRANSPORT_TESTING_PeerContext *p; 386 struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
395 struct GNUNET_PeerIdentity *dummy; 387 struct GNUNET_PeerIdentity *dummy;
396 388 unsigned int i;
389
397 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) 390 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname))
398 { 391 {
399 LOG (GNUNET_ERROR_TYPE_ERROR, 392 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -406,7 +399,15 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
406 p->tth = tth; 399 p->tth = tth;
407 p->nc = nc; 400 p->nc = nc;
408 p->nd = nd; 401 p->nd = nd;
409 p->rec = rec; 402 if (NULL != handlers)
403 {
404 for (i=0;NULL != handlers[i].cb;i++) ;
405 p->handlers = GNUNET_new_array (i + 1,
406 struct GNUNET_MQ_MessageHandler);
407 GNUNET_memcpy (p->handlers,
408 handlers,
409 i * sizeof (struct GNUNET_MQ_MessageHandler));
410 }
410 if (NULL != cb_cls) 411 if (NULL != cb_cls)
411 p->cb_cls = cb_cls; 412 p->cb_cls = cb_cls;
412 else 413 else
@@ -479,14 +480,16 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
479 "Peer %u configured with identity `%s'\n", 480 "Peer %u configured with identity `%s'\n",
480 p->no, 481 p->no,
481 GNUNET_i2s_full (&p->id)); 482 GNUNET_i2s_full (&p->id));
482 483 p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg);
483 p->th = GNUNET_TRANSPORT_connect (p->cfg, 484 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
484 NULL, 485 NULL,
485 p, 486 handlers,
486 &notify_receive, 487 p,
487 &notify_connect, 488 &notify_connect,
488 &notify_disconnect); 489 &notify_disconnect,
489 if (NULL == p->th) 490 NULL);
491 if ( (NULL == p->th) ||
492 (NULL == p->tmh) )
490 { 493 {
491 LOG (GNUNET_ERROR_TYPE_ERROR, 494 LOG (GNUNET_ERROR_TYPE_ERROR,
492 "Failed to connect to transport service for peer `%s': `%s'\n", 495 "Failed to connect to transport service for peer `%s': `%s'\n",
@@ -523,7 +526,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
523 */ 526 */
524int 527int
525GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 528GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
526 GNUNET_TRANSPORT_TESTING_StartCallback restart_cb, 529 GNUNET_SCHEDULER_TaskCallback restart_cb,
527 void *restart_cb_cls) 530 void *restart_cb_cls)
528{ 531{
529 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 532 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
@@ -541,9 +544,14 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
541 } 544 }
542 if (NULL != p->th) 545 if (NULL != p->th)
543 { 546 {
544 GNUNET_TRANSPORT_disconnect (p->th); 547 GNUNET_TRANSPORT_core_disconnect (p->th);
545 p->th = NULL; 548 p->th = NULL;
546 } 549 }
550 if (NULL != p->tmh)
551 {
552 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
553 p->tmh = NULL;
554 }
547 for (cc = p->tth->cc_head; NULL != cc; cc = ccn) 555 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
548 { 556 {
549 ccn = cc->next; 557 ccn = cc->next;
@@ -586,12 +594,13 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
586 p->start_cb = restart_cb; 594 p->start_cb = restart_cb;
587 p->start_cb_cls = restart_cb_cls; 595 p->start_cb_cls = restart_cb_cls;
588 596
589 p->th = GNUNET_TRANSPORT_connect (p->cfg, 597 p->th = GNUNET_TRANSPORT_core_connect (p->cfg,
590 NULL, 598 NULL,
591 p, 599 p->handlers,
592 &notify_receive, 600 p,
593 &notify_connect, 601 &notify_connect,
594 &notify_disconnect); 602 &notify_disconnect,
603 NULL);
595 GNUNET_assert (NULL != p->th); 604 GNUNET_assert (NULL != p->th);
596 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 605 p->ats = GNUNET_ATS_connectivity_init (p->cfg);
597 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg, 606 p->ghh = GNUNET_TRANSPORT_get_hello (p->cfg,
@@ -626,9 +635,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
626 GNUNET_TRANSPORT_get_hello_cancel (p->ghh); 635 GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
627 p->ghh = NULL; 636 p->ghh = NULL;
628 } 637 }
638 if (NULL != p->tmh)
639 {
640 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh);
641 p->tmh = NULL;
642 }
629 if (NULL != p->th) 643 if (NULL != p->th)
630 { 644 {
631 GNUNET_TRANSPORT_disconnect (p->th); 645 GNUNET_TRANSPORT_core_disconnect (p->th);
632 p->th = NULL; 646 p->th = NULL;
633 } 647 }
634 if (NULL != p->peer) 648 if (NULL != p->peer)