aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_oc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-testbed_oc.c')
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c141
1 files changed, 73 insertions, 68 deletions
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index c437f8225..75c7f4975 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -41,7 +41,12 @@ struct TryConnectContext
41 /** 41 /**
42 * The transport handle 42 * The transport handle
43 */ 43 */
44 struct GNUNET_TRANSPORT_Handle *th; 44 struct GNUNET_TRANSPORT_Handle *th_;
45
46 /**
47 * The GetCacheHandle for the p1th transport handle
48 */
49 struct GSTCacheGetHandle *cgh_th;
45 50
46 /** 51 /**
47 * the try connect handle 52 * the try connect handle
@@ -97,6 +102,11 @@ struct OverlayConnectContext
97 struct GNUNET_TRANSPORT_Handle *p1th; 102 struct GNUNET_TRANSPORT_Handle *p1th;
98 103
99 /** 104 /**
105 * The GetCacheHandle for the p1th transport handle
106 */
107 struct GSTGetCacheHandle *gch_p1th;
108
109 /**
100 * Core handles of the first peer; used to notify when second peer connects to it 110 * Core handles of the first peer; used to notify when second peer connects to it
101 */ 111 */
102 struct GNUNET_CORE_Handle *ch; 112 struct GNUNET_CORE_Handle *ch;
@@ -219,11 +229,6 @@ struct RemoteOverlayConnectCtx
219 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; 229 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
220 230
221 /** 231 /**
222 * The local operation we create for this overlay connection
223 */
224 struct GNUNET_TESTBED_Operation *lop;
225
226 /**
227 * The transport try connect context 232 * The transport try connect context
228 */ 233 */
229 struct TryConnectContext tcc; 234 struct TryConnectContext tcc;
@@ -415,9 +420,9 @@ cleanup_occ (struct OverlayConnectContext *occ)
415 GNUNET_TRANSPORT_disconnect (occ->p1th); 420 GNUNET_TRANSPORT_disconnect (occ->p1th);
416 occ->peer->reference_cnt--; 421 occ->peer->reference_cnt--;
417 } 422 }
418 if (NULL != occ->tcc.th) 423 if (NULL != occ->tcc.cgh_th)
419 { 424 {
420 GNUNET_TRANSPORT_disconnect (occ->tcc.th); 425 GST_cache_get_handle_done (occ->tcc.cgh_th);
421 GST_peer_list[occ->other_peer_id]->reference_cnt--; 426 GST_peer_list[occ->other_peer_id]->reference_cnt--;
422 } 427 }
423 if ((GNUNET_YES == occ->peer->destroy_flag) && 428 if ((GNUNET_YES == occ->peer->destroy_flag) &&
@@ -590,11 +595,12 @@ try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
590 return; 595 return;
591 GNUNET_assert (NULL == tcc->tch); 596 GNUNET_assert (NULL == tcc->tch);
592 GNUNET_assert (NULL != tcc->pid); 597 GNUNET_assert (NULL != tcc->pid);
593 GNUNET_assert (NULL != tcc->th); 598 GNUNET_assert (NULL != tcc->th_);
599 GNUNET_assert (NULL != tcc->cgh_th);
594 LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id, 600 LOG_DEBUG ("0x%llx: Trail %u to connect to peer %s\n", tcc->op_id,
595 tcc->retries, GNUNET_i2s (tcc->pid)); 601 tcc->retries, GNUNET_i2s (tcc->pid));
596 tcc->tch = 602 tcc->tch =
597 GNUNET_TRANSPORT_try_connect (tcc->th, tcc->pid, &try_connect_cb, tcc); 603 GNUNET_TRANSPORT_try_connect (tcc->th_, tcc->pid, &try_connect_cb, tcc);
598} 604}
599 605
600 606
@@ -690,7 +696,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
690 LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", occ->op_id, 696 LOG_DEBUG ("0x%llx: Offering HELLO of %s to %s\n", occ->op_id,
691 GNUNET_i2s (&occ->peer_identity), other_peer_str); 697 GNUNET_i2s (&occ->peer_identity), other_peer_str);
692 occ->ohh = 698 occ->ohh =
693 GNUNET_TRANSPORT_offer_hello (occ->tcc.th, occ->hello, 699 GNUNET_TRANSPORT_offer_hello (occ->tcc.th_, occ->hello,
694 occ_hello_sent_cb, occ); 700 occ_hello_sent_cb, occ);
695 if (NULL == occ->ohh) 701 if (NULL == occ->ohh)
696 { 702 {
@@ -709,6 +715,35 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
709 715
710 716
711/** 717/**
718 * Callback from cache with needed handles set
719 *
720 * @param cls the closure passed to GST_cache_get_handle_transport()
721 * @param ch the handle to CORE. Can be NULL if it is not requested
722 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
723 */
724static void
725p2_transport_connect_cache_callback (void *cls, struct GNUNET_CORE_Handle *ch,
726 struct GNUNET_TRANSPORT_Handle *th)
727{
728 struct OverlayConnectContext *occ = cls;
729
730 if (NULL == th)
731 {
732 GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s",
733 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
734 GNUNET_SCHEDULER_cancel (occ->timeout_task);
735 occ->timeout_task =
736 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
737 return;
738 }
739 occ->tcc.th_ = th;
740 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s",
741 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
742 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
743}
744
745
746/**
712 * Connects to the transport of the other peer if it is a local peer and 747 * Connects to the transport of the other peer if it is a local peer and
713 * schedules the send hello task 748 * schedules the send hello task
714 * 749 *
@@ -724,19 +759,13 @@ p2_transport_connect (struct OverlayConnectContext *occ)
724 if (NULL == occ->peer2_controller) 759 if (NULL == occ->peer2_controller)
725 { 760 {
726 GST_peer_list[occ->other_peer_id]->reference_cnt++; 761 GST_peer_list[occ->other_peer_id]->reference_cnt++;
727 occ->tcc.th = 762 occ->tcc.cgh_th =
728 GNUNET_TRANSPORT_connect (GST_peer_list[occ->other_peer_id]-> 763 GST_cache_get_handle_transport (occ->other_peer_id,
729 details.local.cfg, &occ->other_peer_identity, 764 GST_peer_list[occ->other_peer_id]->
730 NULL, NULL, NULL, NULL); 765 details.local.cfg,
731 if (NULL == occ->tcc.th) 766 &p2_transport_connect_cache_callback,
732 { 767 occ);
733 GNUNET_asprintf (&occ->emsg, "0x%llx: Cannot connect to TRANSPORT of %s", 768 return;
734 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
735 GNUNET_SCHEDULER_cancel (occ->timeout_task);
736 occ->timeout_task =
737 GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
738 return;
739 }
740 } 769 }
741 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s", 770 GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while offering HELLO to %s",
742 occ->op_id, GNUNET_i2s (&occ->other_peer_identity)); 771 occ->op_id, GNUNET_i2s (&occ->other_peer_identity));
@@ -1282,11 +1311,6 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
1282static void 1311static void
1283cleanup_rocc (struct RemoteOverlayConnectCtx *rocc) 1312cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
1284{ 1313{
1285 if (NULL != rocc->lop)
1286 {
1287 GNUNET_TESTBED_operation_release_ (rocc->lop);
1288 return;
1289 }
1290 LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id); 1314 LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id);
1291 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id) 1315 if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
1292 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id); 1316 GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
@@ -1298,7 +1322,8 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
1298 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch); 1322 GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
1299 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task) 1323 if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
1300 GNUNET_SCHEDULER_cancel (rocc->tcc.task); 1324 GNUNET_SCHEDULER_cancel (rocc->tcc.task);
1301 GNUNET_TRANSPORT_disconnect (rocc->tcc.th); 1325 //GNUNET_TRANSPORT_disconnect (rocc->tcc.th_);
1326 GST_cache_get_handle_done (rocc->tcc.cgh_th);
1302 rocc->peer->reference_cnt--; 1327 rocc->peer->reference_cnt--;
1303 if ((GNUNET_YES == rocc->peer->destroy_flag) && 1328 if ((GNUNET_YES == rocc->peer->destroy_flag) &&
1304 (0 == rocc->peer->reference_cnt)) 1329 (0 == rocc->peer->reference_cnt))
@@ -1410,7 +1435,7 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1410 LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n", 1435 LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n",
1411 rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id); 1436 rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
1412 rocc->ohh = 1437 rocc->ohh =
1413 GNUNET_TRANSPORT_offer_hello (rocc->tcc.th, rocc->hello, 1438 GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_, rocc->hello,
1414 rocc_hello_sent_cb, rocc); 1439 rocc_hello_sent_cb, rocc);
1415 if (NULL == rocc->ohh) 1440 if (NULL == rocc->ohh)
1416 rocc->attempt_connect_task_id = 1441 rocc->attempt_connect_task_id =
@@ -1424,52 +1449,32 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1424 1449
1425 1450
1426/** 1451/**
1427 * Callback which will be called when remote overlay connect operation is 1452 * Callback from cache with needed handles set
1428 * started
1429 * 1453 *
1430 * @param cls the remote overlay connect context 1454 * @param cls the closure passed to GST_cache_get_handle_transport()
1455 * @param ch the handle to CORE. Can be NULL if it is not requested
1456 * @param th the handle to TRANSPORT. Can be NULL if it is not requested
1431 */ 1457 */
1432static void 1458static void
1433opstart_remote_overlay_connect (void *cls) 1459rocc_cache_get_handle_transport_cb (void *cls, struct GNUNET_CORE_Handle *ch,
1460 struct GNUNET_TRANSPORT_Handle *th)
1434{ 1461{
1435 struct RemoteOverlayConnectCtx *rocc = cls; 1462 struct RemoteOverlayConnectCtx *rocc = cls;
1436 1463
1437 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->timeout_rocc_task_id); 1464 if (NULL == th)
1438 rocc->tcc.op_id = rocc->op_id;
1439 rocc->tcc.th =
1440 GNUNET_TRANSPORT_connect (rocc->peer->details.local.cfg, NULL, rocc, NULL,
1441 &transport_connect_notify, NULL);
1442 if (NULL == rocc->tcc.th)
1443 { 1465 {
1444 rocc->timeout_rocc_task_id = 1466 rocc->timeout_rocc_task_id =
1445 GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc); 1467 GNUNET_SCHEDULER_add_now (&timeout_rocc_task, rocc);
1446 return; 1468 return;
1447 } 1469 }
1470 rocc->tcc.th_ = th;
1448 rocc->tcc.pid = &rocc->a_id; 1471 rocc->tcc.pid = &rocc->a_id;
1449 rocc->attempt_connect_task_id = 1472 rocc->attempt_connect_task_id =
1450 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc); 1473 GNUNET_SCHEDULER_add_now (&attempt_connect_task, rocc);
1451 rocc->timeout_rocc_task_id =
1452 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
1453} 1474}
1454 1475
1455 1476
1456/** 1477/**
1457 * Callback which will be called when remote overlay connect operation is
1458 * released
1459 *
1460 * @param cls the remote overlay connect context
1461 */
1462static void
1463oprelease_remote_overlay_connect (void *cls)
1464{
1465 struct RemoteOverlayConnectCtx *rocc = cls;
1466
1467 GNUNET_assert (NULL != rocc->lop);
1468 rocc->lop = NULL;
1469 cleanup_rocc (rocc);
1470}
1471
1472/**
1473 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages 1478 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_REQUESTCONNECT messages
1474 * 1479 *
1475 * @param cls NULL 1480 * @param cls NULL
@@ -1541,12 +1546,12 @@ GST_handle_remote_overlay_connect (void *cls,
1541 rocc->peer->reference_cnt++; 1546 rocc->peer->reference_cnt++;
1542 rocc->hello = GNUNET_malloc (hsize); 1547 rocc->hello = GNUNET_malloc (hsize);
1543 memcpy (rocc->hello, msg->hello, hsize); 1548 memcpy (rocc->hello, msg->hello, hsize);
1544 rocc->lop = 1549 rocc->tcc.cgh_th = GST_cache_get_handle_transport (peer_id,
1545 GNUNET_TESTBED_operation_create_ (rocc, &opstart_remote_overlay_connect, 1550 rocc->peer->details.local.cfg,
1546 &oprelease_remote_overlay_connect); 1551 &rocc_cache_get_handle_transport_cb,
1547 /* This operation needs only 1 connection to transport */ 1552 rocc);
1548 GNUNET_TESTBED_operation_queue_insert2_ (GST_opq_openfds, rocc->lop, 1); 1553 rocc->timeout_rocc_task_id =
1549 GNUNET_TESTBED_operation_begin_wait_ (rocc->lop); 1554 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_rocc_task, rocc);
1550 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1555 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1551} 1556}
1552 1557