diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 10:38:52 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 10:38:52 +0000 |
commit | 74e48d9e8b28918255d1fc113809d854ed7020e6 (patch) | |
tree | 90a28e37f762edc99f0d149d9da641fecedef2c5 /src/testbed | |
parent | 2b53a7542cd3c26defc24464efba7377fa0c5c89 (diff) | |
download | gnunet-74e48d9e8b28918255d1fc113809d854ed7020e6.tar.gz gnunet-74e48d9e8b28918255d1fc113809d854ed7020e6.zip |
Local and remote peers
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 107 |
1 files changed, 77 insertions, 30 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 017e8cea2..fa4f22375 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -278,22 +278,44 @@ struct LCFContextQueue | |||
278 | */ | 278 | */ |
279 | struct Peer | 279 | struct Peer |
280 | { | 280 | { |
281 | /** | 281 | union |
282 | * The peer handle from testing API | 282 | { |
283 | */ | 283 | struct |
284 | struct GNUNET_TESTING_Peer *peer; | 284 | { |
285 | /** | ||
286 | * The peer handle from testing API | ||
287 | */ | ||
288 | struct GNUNET_TESTING_Peer *peer; | ||
289 | |||
290 | /** | ||
291 | * The modified (by GNUNET_TESTING_peer_configure) configuration this | ||
292 | * peer is configured with | ||
293 | */ | ||
294 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
295 | |||
296 | } local; | ||
297 | |||
298 | struct | ||
299 | { | ||
300 | /** | ||
301 | * The controller this peer is started through | ||
302 | */ | ||
303 | struct GNUNET_TESTBED_Controller *controller; | ||
285 | 304 | ||
286 | /** | 305 | } remote; |
287 | * The modified (by GNUNET_TESTING_peer_configure) configuration this peer is | 306 | |
288 | * configured with | 307 | } details; |
289 | */ | ||
290 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
291 | 308 | ||
292 | /** | 309 | /** |
293 | * Our local reference id for this peer | 310 | * Our local reference id for this peer |
294 | */ | 311 | */ |
295 | uint32_t id; | 312 | uint32_t id; |
296 | 313 | ||
314 | /** | ||
315 | * Is this peer local created? | ||
316 | */ | ||
317 | uint32_t is_remote; | ||
318 | |||
297 | }; | 319 | }; |
298 | 320 | ||
299 | 321 | ||
@@ -1430,14 +1452,16 @@ handle_peer_create (void *cls, | |||
1430 | } | 1452 | } |
1431 | GNUNET_free (config); | 1453 | GNUNET_free (config); |
1432 | peer = GNUNET_malloc (sizeof (struct Peer)); | 1454 | peer = GNUNET_malloc (sizeof (struct Peer)); |
1433 | peer->cfg = cfg; | 1455 | peer->is_remote = GNUNET_NO; |
1456 | peer->details.local.cfg = cfg; | ||
1434 | peer->id = ntohl (msg->peer_id); | 1457 | peer->id = ntohl (msg->peer_id); |
1435 | LOG_DEBUG ("Creating peer with id: %u\n", peer->id); | 1458 | LOG_DEBUG ("Creating peer with id: %u\n", peer->id); |
1436 | peer->peer = GNUNET_TESTING_peer_configure (master_context->system, peer->cfg, | 1459 | peer->details.local.peer = |
1437 | peer->id, | 1460 | GNUNET_TESTING_peer_configure (master_context->system, |
1438 | NULL /* Peer id */, | 1461 | peer->details.local.cfg, peer->id, |
1439 | &emsg); | 1462 | NULL /* Peer id */, |
1440 | if (NULL == peer->peer) | 1463 | &emsg); |
1464 | if (NULL == peer->details.local.peer) | ||
1441 | { | 1465 | { |
1442 | LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg); | 1466 | LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg); |
1443 | GNUNET_free (emsg); | 1467 | GNUNET_free (emsg); |
@@ -1501,8 +1525,15 @@ handle_peer_destroy (void *cls, | |||
1501 | return; | 1525 | return; |
1502 | } | 1526 | } |
1503 | peer = peer_list[peer_id]; | 1527 | peer = peer_list[peer_id]; |
1504 | GNUNET_TESTING_peer_destroy (peer->peer); | 1528 | if (GNUNET_YES == peer->is_remote) |
1505 | GNUNET_CONFIGURATION_destroy (peer->cfg); | 1529 | { |
1530 | /* Forward the destory message to sub controller */ | ||
1531 | GNUNET_break (0); | ||
1532 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1533 | return; | ||
1534 | } | ||
1535 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | ||
1536 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | ||
1506 | peer_list_remove (peer); | 1537 | peer_list_remove (peer); |
1507 | GNUNET_free (peer); | 1538 | GNUNET_free (peer); |
1508 | reply_size = | 1539 | reply_size = |
@@ -1543,7 +1574,8 @@ handle_peer_start (void *cls, | |||
1543 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1574 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1544 | return; | 1575 | return; |
1545 | } | 1576 | } |
1546 | if (GNUNET_OK != GNUNET_TESTING_peer_start (peer_list[peer_id]->peer)) | 1577 | if (GNUNET_OK != |
1578 | GNUNET_TESTING_peer_start (peer_list[peer_id]->details.local.peer)) | ||
1547 | { | 1579 | { |
1548 | /* FIXME: return FAILURE message */ | 1580 | /* FIXME: return FAILURE message */ |
1549 | GNUNET_break (0); | 1581 | GNUNET_break (0); |
@@ -1586,7 +1618,8 @@ handle_peer_stop (void *cls, | |||
1586 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1618 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1587 | return; | 1619 | return; |
1588 | } | 1620 | } |
1589 | if (GNUNET_OK != GNUNET_TESTING_peer_stop (peer_list[peer_id]->peer)) | 1621 | if (GNUNET_OK != |
1622 | GNUNET_TESTING_peer_stop (peer_list[peer_id]->details.local.peer)) | ||
1590 | { | 1623 | { |
1591 | /* FIXME: return FAILURE message */ | 1624 | /* FIXME: return FAILURE message */ |
1592 | GNUNET_break (0); | 1625 | GNUNET_break (0); |
@@ -1619,6 +1652,7 @@ handle_peer_get_config (void *cls, | |||
1619 | { | 1652 | { |
1620 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 1653 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; |
1621 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply; | 1654 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply; |
1655 | struct Peer *peer; | ||
1622 | char *config; | 1656 | char *config; |
1623 | char *xconfig; | 1657 | char *xconfig; |
1624 | size_t c_size; | 1658 | size_t c_size; |
@@ -1633,9 +1667,19 @@ handle_peer_get_config (void *cls, | |||
1633 | /* FIXME: return FAILURE message */ | 1667 | /* FIXME: return FAILURE message */ |
1634 | GNUNET_break (0); | 1668 | GNUNET_break (0); |
1635 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1669 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1670 | return; | ||
1671 | } | ||
1672 | peer = peer_list[peer_id]; | ||
1673 | if (GNUNET_YES == peer->is_remote) | ||
1674 | { | ||
1675 | /* FIXME: forward to sub controller */ | ||
1676 | GNUNET_break (0); | ||
1677 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1678 | return; | ||
1636 | } | 1679 | } |
1637 | config = GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->cfg, | 1680 | config = |
1638 | &c_size); | 1681 | GNUNET_CONFIGURATION_serialize (peer_list[peer_id]->details.local.cfg, |
1682 | &c_size); | ||
1639 | xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); | 1683 | xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); |
1640 | GNUNET_free (config); | 1684 | GNUNET_free (config); |
1641 | msize = xc_size + sizeof (struct | 1685 | msize = xc_size + sizeof (struct |
@@ -1646,7 +1690,7 @@ handle_peer_get_config (void *cls, | |||
1646 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG); | 1690 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG); |
1647 | reply->peer_id = msg->peer_id; | 1691 | reply->peer_id = msg->peer_id; |
1648 | reply->operation_id = msg->operation_id; | 1692 | reply->operation_id = msg->operation_id; |
1649 | GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->peer, | 1693 | GNUNET_TESTING_peer_get_identity (peer_list[peer_id]->details.local.peer, |
1650 | &reply->peer_identity); | 1694 | &reply->peer_identity); |
1651 | reply->config_size = htons ((uint16_t) c_size); | 1695 | reply->config_size = htons ((uint16_t) c_size); |
1652 | queue_message (client, &reply->header); | 1696 | queue_message (client, &reply->header); |
@@ -1870,14 +1914,15 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle * server, | |||
1870 | occ->emsg = NULL; | 1914 | occ->emsg = NULL; |
1871 | memcpy (&occ->peer_identity, my_identity, sizeof (struct GNUNET_PeerIdentity)); | 1915 | memcpy (&occ->peer_identity, my_identity, sizeof (struct GNUNET_PeerIdentity)); |
1872 | occ->p1th = | 1916 | occ->p1th = |
1873 | GNUNET_TRANSPORT_connect (occ->peer->cfg, &occ->peer_identity, NULL, NULL, | 1917 | GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg, |
1874 | NULL, NULL); | 1918 | &occ->peer_identity, NULL, NULL, NULL, NULL); |
1875 | /* Connect to the transport of 2nd peer and get its HELLO message */ | 1919 | /* Connect to the transport of 2nd peer and get its HELLO message */ |
1876 | GNUNET_TESTING_peer_get_identity (occ->other_peer->peer, | 1920 | GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer, |
1877 | &occ->other_peer_identity); | 1921 | &occ->other_peer_identity); |
1878 | occ->p2th = | 1922 | occ->p2th = |
1879 | GNUNET_TRANSPORT_connect (occ->other_peer->cfg, &occ->other_peer_identity, | 1923 | GNUNET_TRANSPORT_connect (occ->other_peer->details.local.cfg, |
1880 | NULL, NULL, NULL, NULL); | 1924 | &occ->other_peer_identity, |
1925 | NULL, NULL, NULL, NULL); | ||
1881 | if ((NULL == occ->p1th) || (NULL == occ->p2th)) | 1926 | if ((NULL == occ->p1th) || (NULL == occ->p2th)) |
1882 | { | 1927 | { |
1883 | occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORTs of peers"); | 1928 | occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORTs of peers"); |
@@ -1922,6 +1967,8 @@ handle_overlay_connect (void *cls, | |||
1922 | GNUNET_assert (NULL != peer_list[p1]); | 1967 | GNUNET_assert (NULL != peer_list[p1]); |
1923 | GNUNET_assert (p2 < peer_list_size); | 1968 | GNUNET_assert (p2 < peer_list_size); |
1924 | GNUNET_assert (NULL != peer_list[p2]); | 1969 | GNUNET_assert (NULL != peer_list[p2]); |
1970 | /* FIXME: Add cases where we have to forward overlay connect message to sub | ||
1971 | controllers */ | ||
1925 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); | 1972 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); |
1926 | GNUNET_SERVER_client_keep (client); | 1973 | GNUNET_SERVER_client_keep (client); |
1927 | occ->client = client; | 1974 | occ->client = client; |
@@ -1936,7 +1983,7 @@ handle_overlay_connect (void *cls, | |||
1936 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ | 1983 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ |
1937 | occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); | 1984 | occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); |
1938 | occ->ch = | 1985 | occ->ch = |
1939 | GNUNET_CORE_connect (occ->peer->cfg, occ, &core_startup_cb, | 1986 | GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, |
1940 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, | 1987 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, |
1941 | GNUNET_NO, no_handlers); | 1988 | GNUNET_NO, no_handlers); |
1942 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1989 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -2007,8 +2054,8 @@ shutdown_task (void *cls, | |||
2007 | for (id = 0; id < peer_list_size; id++) | 2054 | for (id = 0; id < peer_list_size; id++) |
2008 | if (NULL != peer_list[id]) | 2055 | if (NULL != peer_list[id]) |
2009 | { | 2056 | { |
2010 | GNUNET_TESTING_peer_destroy (peer_list[id]->peer); | 2057 | GNUNET_TESTING_peer_destroy (peer_list[id]->details.local.peer); |
2011 | GNUNET_CONFIGURATION_destroy (peer_list[id]->cfg); | 2058 | GNUNET_CONFIGURATION_destroy (peer_list[id]->details.local.cfg); |
2012 | GNUNET_free (peer_list[id]); | 2059 | GNUNET_free (peer_list[id]); |
2013 | } | 2060 | } |
2014 | GNUNET_free_non_null (peer_list); | 2061 | GNUNET_free_non_null (peer_list); |