diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 15:13:06 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 15:13:06 +0000 |
commit | dcc664503c7f346c97e32c5232c2f3cb82e3c7d7 (patch) | |
tree | 5c17fe5cea4d19eb0c282b62d28f8afde6660556 | |
parent | 055b09ed1535ff02bb02503aaa88d1d02b9d366b (diff) | |
download | gnunet-dcc664503c7f346c97e32c5232c2f3cb82e3c7d7.tar.gz gnunet-dcc664503c7f346c97e32c5232c2f3cb82e3c7d7.zip |
implemented peer create operation forwarding
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 100 |
1 files changed, 91 insertions, 9 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index faa1570a8..a9e050344 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -50,9 +50,19 @@ | |||
50 | #define LOG_DEBUG(...) \ | 50 | #define LOG_DEBUG(...) \ |
51 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 51 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
52 | 52 | ||
53 | 53 | /** | |
54 | * By how much should the arrays lists grow | ||
55 | */ | ||
54 | #define LIST_GROW_STEP 10 | 56 | #define LIST_GROW_STEP 10 |
55 | 57 | ||
58 | /** | ||
59 | * Default timeout for operations which may take some time | ||
60 | */ | ||
61 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) | ||
62 | |||
63 | /** | ||
64 | * The main context information associated with the client which started us | ||
65 | */ | ||
56 | struct Context | 66 | struct Context |
57 | { | 67 | { |
58 | /** | 68 | /** |
@@ -433,14 +443,29 @@ struct OverlayConnectContext | |||
433 | struct ForwardedOperationContext | 443 | struct ForwardedOperationContext |
434 | { | 444 | { |
435 | /** | 445 | /** |
446 | * The generated operation context | ||
447 | */ | ||
448 | struct OperationContext *opc; | ||
449 | |||
450 | /** | ||
451 | * The client to which we have to reply | ||
452 | */ | ||
453 | struct GNUNET_SERVER_Client *client; | ||
454 | |||
455 | /** | ||
436 | * Task ID for the timeout task | 456 | * Task ID for the timeout task |
437 | */ | 457 | */ |
438 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 458 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
439 | 459 | ||
440 | /** | 460 | /** |
441 | * The ID of the operation that is forwarded | 461 | * The id of the operation that has been forwarded |
462 | */ | ||
463 | uint64_t operation_id; | ||
464 | |||
465 | /** | ||
466 | * The ID of the peer we are going to create | ||
442 | */ | 467 | */ |
443 | uint64_t operation_id; | 468 | uint32_t peer_id; |
444 | }; | 469 | }; |
445 | 470 | ||
446 | 471 | ||
@@ -1378,6 +1403,56 @@ handle_link_controllers (void *cls, | |||
1378 | 1403 | ||
1379 | 1404 | ||
1380 | /** | 1405 | /** |
1406 | * The task to be executed if the forwarded peer create operation has been | ||
1407 | * timed out | ||
1408 | * | ||
1409 | * @param cls the FowardedOperationContext | ||
1410 | * @param tc the TaskContext from the scheduler | ||
1411 | */ | ||
1412 | static void | ||
1413 | peer_create_forward_timeout (void *cls, | ||
1414 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1415 | { | ||
1416 | struct ForwardedOperationContext *fo_ctxt = cls; | ||
1417 | |||
1418 | /* send error msg to client */ | ||
1419 | send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, | ||
1420 | "Timedout"); | ||
1421 | GNUNET_SERVER_client_drop (fo_ctxt->client); | ||
1422 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fo_ctxt->opc); | ||
1423 | GNUNET_free (fo_ctxt); | ||
1424 | } | ||
1425 | |||
1426 | |||
1427 | /** | ||
1428 | * Callback to be called when forwarded peer create operation is | ||
1429 | * successfull. We have to relay the reply msg back to the client | ||
1430 | * | ||
1431 | * @param cls ForwardedOperationContext | ||
1432 | * @param msg the peer create success message | ||
1433 | */ | ||
1434 | static void | ||
1435 | peer_create_success_cb (void *cls, | ||
1436 | const struct GNUNET_MessageHeader *msg) | ||
1437 | { | ||
1438 | struct ForwardedOperationContext *fo_ctxt = cls; | ||
1439 | struct GNUNET_MessageHeader *dup_msg; | ||
1440 | uint16_t msize; | ||
1441 | |||
1442 | GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task); | ||
1443 | GNUNET_assert (ntohs (msg->type) == | ||
1444 | GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS); | ||
1445 | msize = ntohs (msg->size); | ||
1446 | dup_msg = GNUNET_malloc (msize); | ||
1447 | (void) memcpy (dup_msg, msg, msize); | ||
1448 | queue_message (fo_ctxt->client, dup_msg); | ||
1449 | GNUNET_SERVER_client_drop (fo_ctxt->client); | ||
1450 | GNUNET_free (fo_ctxt); | ||
1451 | } | ||
1452 | |||
1453 | |||
1454 | |||
1455 | /** | ||
1381 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages | 1456 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages |
1382 | * | 1457 | * |
1383 | * @param cls NULL | 1458 | * @param cls NULL |
@@ -1390,7 +1465,6 @@ handle_peer_create (void *cls, | |||
1390 | const struct GNUNET_MessageHeader *message) | 1465 | const struct GNUNET_MessageHeader *message) |
1391 | { | 1466 | { |
1392 | const struct GNUNET_TESTBED_PeerCreateMessage *msg; | 1467 | const struct GNUNET_TESTBED_PeerCreateMessage *msg; |
1393 | struct GNUNET_TESTBED_PeerCreateMessage *dup_msg; | ||
1394 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; | 1468 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; |
1395 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1469 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1396 | struct ForwardedOperationContext *fo_ctxt; | 1470 | struct ForwardedOperationContext *fo_ctxt; |
@@ -1485,11 +1559,19 @@ handle_peer_create (void *cls, | |||
1485 | return; | 1559 | return; |
1486 | } | 1560 | } |
1487 | fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); | 1561 | fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); |
1488 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); | 1562 | GNUNET_SERVER_client_keep (client); |
1489 | dup_msg = GNUNET_malloc (msize); | 1563 | fo_ctxt->client = client; |
1490 | (void) memcpy (dup_msg, msg, msize); | 1564 | fo_ctxt->peer_id = ntohl (msg->peer_id); |
1491 | GNUNET_TESTBED_queue_message_ (slave_list[route->dest]->controller, | 1565 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); |
1492 | &dup_msg->header); | 1566 | fo_ctxt->opc = |
1567 | GNUNET_TESTBED_forward_operation_msg_ (slave_list[route->dest]->controller, | ||
1568 | fo_ctxt->operation_id, | ||
1569 | &msg->header, | ||
1570 | peer_create_success_cb, fo_ctxt); | ||
1571 | fo_ctxt->timeout_task = | ||
1572 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
1573 | &peer_create_forward_timeout, fo_ctxt); | ||
1574 | |||
1493 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1575 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1494 | } | 1576 | } |
1495 | 1577 | ||