diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-01 15:03:57 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-01 15:03:57 +0000 |
commit | 97c6db0188f20f05fcb657d448a213b05df76bde (patch) | |
tree | 678e23d9e824539bb1b680489698d9aa7e255154 /src/testbed | |
parent | 17e705b6e90fbeca4fa98c36ebbab83f5d9dc9cd (diff) | |
download | gnunet-97c6db0188f20f05fcb657d448a213b05df76bde.tar.gz gnunet-97c6db0188f20f05fcb657d448a213b05df76bde.zip |
improved overlay connect handling
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 182 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 78 |
2 files changed, 205 insertions, 55 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 31112ce00..169a9e6c7 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -296,49 +296,81 @@ struct Peer | |||
296 | 296 | ||
297 | 297 | ||
298 | /** | 298 | /** |
299 | * State information for overlay connect context | ||
300 | */ | ||
301 | enum OCCState | ||
302 | { | ||
303 | /** | ||
304 | * Initial state | ||
305 | */ | ||
306 | OCC_STATE_INIT, | ||
307 | |||
308 | /** | ||
309 | * Peer 1 has connected to peer0 | ||
310 | */ | ||
311 | OCC_STATE_PEER0_SUCCESS, | ||
312 | |||
313 | /** | ||
314 | * Peer 2 has connected to peer1 | ||
315 | */ | ||
316 | OCC_STATE_PEER1_SUCCESS, | ||
317 | |||
318 | }; | ||
319 | |||
320 | |||
321 | /** | ||
299 | * Context information for connecting 2 peers in overlay | 322 | * Context information for connecting 2 peers in overlay |
300 | */ | 323 | */ |
301 | struct OverlayConnectContext | 324 | struct OverlayConnectContext |
302 | { | 325 | { |
303 | /** | 326 | /** |
304 | * peer 1 | 327 | * peer 1 and peer2 |
305 | */ | 328 | */ |
306 | struct Peer *peer1; | 329 | struct Peer * peers[2]; |
307 | 330 | ||
308 | /** | 331 | /** |
309 | * peer 2 | 332 | * Transport handle of peers |
310 | */ | 333 | */ |
311 | struct Peer *peer2; | 334 | struct GNUNET_TRANSPORT_Handle *peers_transport[2]; |
312 | 335 | ||
313 | /** | 336 | /** |
314 | * Transport handle of peer1 | 337 | * HELLO of peers |
315 | */ | 338 | */ |
316 | struct GNUNET_TRANSPORT_Handle *peer1_transport; | 339 | struct GNUNET_MessageHeader *peers_hello[2]; |
317 | 340 | ||
318 | /** | 341 | /** |
319 | * Transport handle of peer2 | 342 | * Get hello handle for peers |
320 | */ | 343 | */ |
321 | struct GNUNET_TRANSPORT_Handle *peer2_transport; | 344 | struct GNUNET_TRANSPORT_GetHelloHandle *peers_ghh[2]; |
322 | 345 | ||
323 | /** | 346 | /** |
324 | * HELLO of peer1 | 347 | * The peer identity of peers |
325 | */ | 348 | */ |
326 | struct GNUNET_MessageHeader *peer1_hello; | 349 | struct GNUNET_PeerIdentity peers_identity[2]; |
327 | 350 | ||
328 | /** | 351 | /** |
329 | * HELLO of peer2 | 352 | * State information for determining whose HELLOs have been successfully |
353 | * exchanged | ||
330 | */ | 354 | */ |
331 | struct GNUNET_MessageHeader *peer2_hello; | 355 | enum OCCState state; |
332 | 356 | ||
357 | }; | ||
358 | |||
359 | |||
360 | /** | ||
361 | * Wrapper around OverlayConnectContext | ||
362 | */ | ||
363 | struct OverlayConnectContextWrapper | ||
364 | { | ||
333 | /** | 365 | /** |
334 | * Get hello handle for peer1 | 366 | * The overlay connect context |
335 | */ | 367 | */ |
336 | struct GNUNET_TRANSPORT_GetHelloHandle *peer1_ghh; | 368 | struct OverlayConnectContext *occ; |
337 | 369 | ||
338 | /** | 370 | /** |
339 | * Get hello handle for peer2 | 371 | * The peer number in reference; should be 0 or 1 |
340 | */ | 372 | */ |
341 | struct GNUNET_TRANSPORT_GetHelloHandle *peer2_ghh; | 373 | unsigned int peer; |
342 | }; | 374 | }; |
343 | 375 | ||
344 | 376 | ||
@@ -1495,19 +1527,97 @@ handle_peer_get_config (void *cls, | |||
1495 | } | 1527 | } |
1496 | 1528 | ||
1497 | 1529 | ||
1530 | /** | ||
1531 | * Task to be executed when HELLO has been sent | ||
1532 | * | ||
1533 | * @param cls overlay connect context wrapper | ||
1534 | * @param tc the task context from scheduler | ||
1535 | */ | ||
1536 | static void | ||
1537 | overlay_connect_finalize (void *cls, | ||
1538 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1539 | { | ||
1540 | struct OverlayConnectContextWrapper *occw = cls; | ||
1541 | struct OverlayConnectContext *occ; | ||
1542 | unsigned int peer; | ||
1543 | |||
1544 | peer = occw->peer; | ||
1545 | occ = occw->occ; | ||
1546 | GNUNET_free (occw); | ||
1547 | GNUNET_free (occ->peers_hello[peer ^ 1]); | ||
1548 | } | ||
1549 | |||
1550 | |||
1551 | /** | ||
1552 | * Exchanges HELLO of peers among them | ||
1553 | * | ||
1554 | * @param occ the OverlayConnectContext to look into for HELLO messages | ||
1555 | */ | ||
1556 | static void | ||
1557 | exchange_hellos (struct OverlayConnectContext *occ) | ||
1558 | { | ||
1559 | struct OverlayConnectContextWrapper *occw; | ||
1560 | unsigned int peer; | ||
1561 | |||
1562 | GNUNET_assert (NULL != occ->peers_hello[0]); | ||
1563 | GNUNET_assert (NULL != occ->peers_hello[1]); | ||
1564 | LOG_DEBUG ("Exchanging hellos\n"); | ||
1565 | for (peer = 0; peer < 2; peer++) | ||
1566 | { | ||
1567 | occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper)); | ||
1568 | occw->occ = occ; | ||
1569 | occw->peer = peer; | ||
1570 | GNUNET_TRANSPORT_offer_hello (occ->peers_transport[peer], | ||
1571 | occ->peers_hello[peer ^ 1], | ||
1572 | &overlay_connect_finalize, occw); | ||
1573 | } | ||
1574 | } | ||
1575 | |||
1498 | 1576 | ||
1499 | /** | 1577 | /** |
1500 | * Function called whenever there is an update to the | 1578 | * Function called whenever there is an update to the |
1501 | * HELLO of this peer. | 1579 | * HELLO of peers in the OverlayConnectClosure |
1502 | * | 1580 | * |
1503 | * @param cls closure | 1581 | * @param cls closure |
1504 | * @param hello our updated HELLO | 1582 | * @param hello our updated HELLO |
1505 | */ | 1583 | */ |
1506 | static void | 1584 | static void |
1507 | hello_update_cb (void *cls, | 1585 | hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello) |
1508 | const struct GNUNET_MessageHeader *hello) | ||
1509 | { | 1586 | { |
1510 | GNUNET_break(0); | 1587 | struct OverlayConnectContextWrapper *occw = cls; |
1588 | struct OverlayConnectContext *occ; | ||
1589 | unsigned int peer; | ||
1590 | uint16_t msize; | ||
1591 | |||
1592 | msize = ntohs (hello->size); | ||
1593 | peer = occw->peer; | ||
1594 | GNUNET_assert (peer <= 1); | ||
1595 | occ = occw->occ; | ||
1596 | occ->peers_hello[peer] = GNUNET_malloc (msize); | ||
1597 | memcpy (occ->peers_hello[peer], hello, msize); | ||
1598 | GNUNET_TRANSPORT_get_hello_cancel (occ->peers_ghh[peer]); | ||
1599 | occ->peers_ghh[peer] = NULL; | ||
1600 | if (NULL != occ->peers_hello[peer ^ 1]) | ||
1601 | exchange_hellos (occ); | ||
1602 | } | ||
1603 | |||
1604 | |||
1605 | /** | ||
1606 | * Function called to notify transport users that another | ||
1607 | * peer connected to us. | ||
1608 | * | ||
1609 | * @param cls closure | ||
1610 | * @param peer the peer that connected | ||
1611 | * @param ats performance data | ||
1612 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
1613 | */ | ||
1614 | static void | ||
1615 | overlay_connect_notify (void *cls, | ||
1616 | const struct GNUNET_PeerIdentity * peer, | ||
1617 | const struct GNUNET_ATS_Information * ats, | ||
1618 | uint32_t ats_count) | ||
1619 | { | ||
1620 | GNUNET_break (0); /* To be implemented */ | ||
1511 | } | 1621 | } |
1512 | 1622 | ||
1513 | 1623 | ||
@@ -1525,6 +1635,8 @@ handle_overlay_connect (void *cls, | |||
1525 | { | 1635 | { |
1526 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; | 1636 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; |
1527 | struct OverlayConnectContext *occ; | 1637 | struct OverlayConnectContext *occ; |
1638 | struct OverlayConnectContextWrapper *occw; | ||
1639 | unsigned int peer; | ||
1528 | uint32_t p1; | 1640 | uint32_t p1; |
1529 | uint32_t p2; | 1641 | uint32_t p2; |
1530 | 1642 | ||
@@ -1536,14 +1648,24 @@ handle_overlay_connect (void *cls, | |||
1536 | GNUNET_assert (p2 < peer_list_size); | 1648 | GNUNET_assert (p2 < peer_list_size); |
1537 | GNUNET_assert (NULL != peer_list[p2]); | 1649 | GNUNET_assert (NULL != peer_list[p2]); |
1538 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); | 1650 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); |
1539 | occ->peer1 = peer_list[p1]; | 1651 | occ->state = OCC_STATE_INIT; |
1540 | occ->peer2 = peer_list[p2]; | 1652 | occ->peers[0] = peer_list[p1]; |
1541 | occ->peer1_transport = GNUNET_TRANSPORT_connect (occ->peer1->cfg, NULL, occ, | 1653 | occ->peers[1] = peer_list[p2]; |
1542 | NULL, NULL, NULL); | 1654 | for (peer = 0; peer < 2; peer++) |
1543 | occ->peer2_transport = GNUNET_TRANSPORT_connect (occ->peer2->cfg, NULL, occ, | 1655 | { |
1544 | NULL, NULL, NULL); | 1656 | occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper)); |
1545 | occ->peer1_ghh = GNUNET_TRANSPORT_get_hello (occ->peer1_transport, &hello_update_cb, occ); | 1657 | occw->occ = occ; |
1546 | occ->peer2_ghh = GNUNET_TRANSPORT_get_hello (occ->peer2_transport, &hello_update_cb, occ); | 1658 | occw->peer = peer; |
1659 | GNUNET_TESTING_peer_get_identity (occ->peers[peer]->peer, | ||
1660 | &occ->peers_identity[peer]); | ||
1661 | occ->peers_transport[peer] = | ||
1662 | GNUNET_TRANSPORT_connect (occ->peers[peer]->cfg, | ||
1663 | &occ->peers_identity[peer], occw, NULL, | ||
1664 | &overlay_connect_notify, NULL); | ||
1665 | occ->peers_ghh[peer] = | ||
1666 | GNUNET_TRANSPORT_get_hello (occ->peers_transport[peer], | ||
1667 | &hello_update_cb, occw); | ||
1668 | } | ||
1547 | } | 1669 | } |
1548 | 1670 | ||
1549 | 1671 | ||
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 69c3aaac8..e6d709e0b 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -95,7 +95,7 @@ oprelease_peer_create (void *cls) | |||
95 | 95 | ||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Function to called when a peer destroy operation is ready | 98 | * Function called when a peer destroy operation is ready |
99 | * | 99 | * |
100 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 100 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
101 | */ | 101 | */ |
@@ -138,7 +138,7 @@ oprelease_peer_destroy (void *cls) | |||
138 | 138 | ||
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Function to called when a peer start operation is ready | 141 | * Function called when a peer start operation is ready |
142 | * | 142 | * |
143 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 143 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
144 | */ | 144 | */ |
@@ -181,7 +181,7 @@ oprelease_peer_start (void *cls) | |||
181 | 181 | ||
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Function to called when a peer stop operation is ready | 184 | * Function called when a peer stop operation is ready |
185 | * | 185 | * |
186 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 186 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
187 | */ | 187 | */ |
@@ -223,7 +223,7 @@ oprelease_peer_stop (void *cls) | |||
223 | 223 | ||
224 | 224 | ||
225 | /** | 225 | /** |
226 | * Function to called when a peer get information operation is ready | 226 | * Function called when a peer get information operation is ready |
227 | * | 227 | * |
228 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 228 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
229 | */ | 229 | */ |
@@ -286,6 +286,44 @@ oprelease_peer_getinfo (void *cls) | |||
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | /** | ||
290 | * Function called when a overlay connect operation is ready | ||
291 | * | ||
292 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
293 | */ | ||
294 | static void | ||
295 | opstart_overlay_connect (void *cls) | ||
296 | { | ||
297 | struct OperationContext *opc = cls; | ||
298 | struct GNUNET_TESTBED_OverlayConnectMessage *msg; | ||
299 | struct OverlayConnectData *data; | ||
300 | |||
301 | opc->state = OPC_STATE_STARTED; | ||
302 | data = opc->data; | ||
303 | GNUNET_assert (NULL != data); | ||
304 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); | ||
305 | msg->header.size = htons (sizeof | ||
306 | (struct GNUNET_TESTBED_OverlayConnectMessage)); | ||
307 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT); | ||
308 | msg->peer1 = htonl (data->p1->unique_id); | ||
309 | msg->peer2 = htonl (data->p2->unique_id); | ||
310 | msg->operation_id = GNUNET_htonll (opc->id); | ||
311 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
312 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | ||
313 | } | ||
314 | |||
315 | |||
316 | /** | ||
317 | * Callback which will be called when overlay connect operation is released | ||
318 | * | ||
319 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
320 | */ | ||
321 | static void | ||
322 | oprelease_overlay_connect (void *cls) | ||
323 | { | ||
324 | GNUNET_break (0); | ||
325 | } | ||
326 | |||
289 | 327 | ||
290 | /** | 328 | /** |
291 | * Lookup a peer by ID. | 329 | * Lookup a peer by ID. |
@@ -578,32 +616,22 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, | |||
578 | struct GNUNET_TESTBED_Peer *p1, | 616 | struct GNUNET_TESTBED_Peer *p1, |
579 | struct GNUNET_TESTBED_Peer *p2) | 617 | struct GNUNET_TESTBED_Peer *p2) |
580 | { | 618 | { |
581 | struct GNUNET_TESTBED_Operation *op; | 619 | struct OperationContext *opc; |
582 | struct OverlayConnectData *data; | 620 | struct OverlayConnectData *data; |
583 | struct GNUNET_TESTBED_OverlayConnectMessage *msg; | 621 | |
584 | |||
585 | GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state)); | 622 | GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state)); |
586 | GNUNET_assert (p1->controller == p2->controller); | 623 | GNUNET_assert (p1->controller == p2->controller); |
587 | data = GNUNET_malloc (sizeof (struct OverlayConnectData)); | 624 | data = GNUNET_malloc (sizeof (struct OverlayConnectData)); |
588 | data->p1 = p1; | 625 | data->p1 = p1; |
589 | data->p2 = p2; | 626 | data->p2 = p2; |
590 | op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); | 627 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
591 | op->controller = p1->controller; | 628 | opc->data = data; |
592 | op->operation_id = op->controller->operation_counter++; | 629 | opc->c = p1->controller; |
593 | op->type = OP_OVERLAY_CONNECT; | 630 | opc->id = opc->c->operation_counter++; |
594 | op->data = data; | 631 | opc->type = OP_OVERLAY_CONNECT; |
595 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); | 632 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, |
596 | msg->header.size = htons (sizeof (struct | 633 | &oprelease_overlay_connect); |
597 | GNUNET_TESTBED_OverlayConnectMessage)); | 634 | return opc->op; |
598 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT); | ||
599 | msg->peer1 = htonl (p1->unique_id); | ||
600 | msg->peer2 = htonl (p2->unique_id); | ||
601 | msg->operation_id = GNUNET_htonll (op->operation_id); | ||
602 | GNUNET_CONTAINER_DLL_insert_tail (op->controller->op_head, | ||
603 | op->controller->op_tail, op); | ||
604 | GNUNET_TESTBED_queue_message_ (op->controller, | ||
605 | (struct GNUNET_MessageHeader *) msg); | ||
606 | return NULL; | ||
607 | } | 635 | } |
608 | 636 | ||
609 | 637 | ||