diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 12:46:05 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-11 12:46:05 +0000 |
commit | 526fd6adbac1b3ef92edf457e035d6388921fd26 (patch) | |
tree | 901c213ad31ae8eb560b70810b7965b637ec0019 /src/testbed | |
parent | 74e48d9e8b28918255d1fc113809d854ed7020e6 (diff) | |
download | gnunet-526fd6adbac1b3ef92edf457e035d6388921fd26.tar.gz gnunet-526fd6adbac1b3ef92edf457e035d6388921fd26.zip |
api forward operation message
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 31 | ||||
-rw-r--r-- | src/testbed/testbed.h | 1 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 74 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 26 |
4 files changed, 115 insertions, 17 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index fa4f22375..faa1570a8 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -428,25 +428,19 @@ struct OverlayConnectContext | |||
428 | 428 | ||
429 | 429 | ||
430 | /** | 430 | /** |
431 | * Context data to be used when forwarding peer create messages | 431 | * Context information for operations forward to subcontrollers |
432 | */ | 432 | */ |
433 | struct PeerCreateContext | 433 | struct ForwardedOperationContext |
434 | { | 434 | { |
435 | /** | 435 | /** |
436 | * The operation handle to peer create | 436 | * Task ID for the timeout task |
437 | */ | 437 | */ |
438 | struct GNUNET_TESTBED_operation *operation; | 438 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
439 | 439 | ||
440 | /** | 440 | /** |
441 | * The ID of the operation which created this context | 441 | * The ID of the operation that is forwarded |
442 | */ | 442 | */ |
443 | uint64_t operation_id; | 443 | uint64_t operation_id; |
444 | |||
445 | /** | ||
446 | * The peer create timeout task id | ||
447 | */ | ||
448 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
449 | |||
450 | }; | 444 | }; |
451 | 445 | ||
452 | 446 | ||
@@ -1396,10 +1390,12 @@ handle_peer_create (void *cls, | |||
1396 | const struct GNUNET_MessageHeader *message) | 1390 | const struct GNUNET_MessageHeader *message) |
1397 | { | 1391 | { |
1398 | const struct GNUNET_TESTBED_PeerCreateMessage *msg; | 1392 | const struct GNUNET_TESTBED_PeerCreateMessage *msg; |
1393 | struct GNUNET_TESTBED_PeerCreateMessage *dup_msg; | ||
1399 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; | 1394 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; |
1400 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1395 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1401 | struct PeerCreateContext *pc_ctxt; | 1396 | struct ForwardedOperationContext *fo_ctxt; |
1402 | struct Route *route; | 1397 | struct Route *route; |
1398 | struct Peer *peer; | ||
1403 | char *config; | 1399 | char *config; |
1404 | size_t dest_size; | 1400 | size_t dest_size; |
1405 | int ret; | 1401 | int ret; |
@@ -1419,7 +1415,6 @@ handle_peer_create (void *cls, | |||
1419 | host_id = ntohl (msg->host_id); | 1415 | host_id = ntohl (msg->host_id); |
1420 | if (host_id == master_context->host_id) | 1416 | if (host_id == master_context->host_id) |
1421 | { | 1417 | { |
1422 | struct Peer *peer; | ||
1423 | char *emsg; | 1418 | char *emsg; |
1424 | 1419 | ||
1425 | /* We are responsible for this peer */ | 1420 | /* We are responsible for this peer */ |
@@ -1489,9 +1484,13 @@ handle_peer_create (void *cls, | |||
1489 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1484 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1490 | return; | 1485 | return; |
1491 | } | 1486 | } |
1492 | pc_ctxt = GNUNET_malloc (sizeof (struct PeerCreateContext)); | 1487 | fo_ctxt = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); |
1493 | pc_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); | 1488 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); |
1494 | /* To be continued .. :) */ | 1489 | dup_msg = GNUNET_malloc (msize); |
1490 | (void) memcpy (dup_msg, msg, msize); | ||
1491 | GNUNET_TESTBED_queue_message_ (slave_list[route->dest]->controller, | ||
1492 | &dup_msg->header); | ||
1493 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1495 | } | 1494 | } |
1496 | 1495 | ||
1497 | 1496 | ||
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index d0f2accb4..b6a0e30cc 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -606,4 +606,5 @@ struct GNUNET_TESTBED_PeerConfigurationInformationMessage | |||
606 | 606 | ||
607 | }; | 607 | }; |
608 | 608 | ||
609 | |||
609 | #endif | 610 | #endif |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 7f1c292be..62f16d300 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -156,6 +156,25 @@ struct GNUNET_TESTBED_HostRegistrationHandle | |||
156 | 156 | ||
157 | 157 | ||
158 | /** | 158 | /** |
159 | * Context data for forwarded Operation | ||
160 | */ | ||
161 | struct ForwardedOperationData | ||
162 | { | ||
163 | |||
164 | /** | ||
165 | * The callback to call when reply is available | ||
166 | */ | ||
167 | GNUNET_CLIENT_MessageHandler cc; | ||
168 | |||
169 | /** | ||
170 | * The closure for the above callback | ||
171 | */ | ||
172 | void *cc_cls; | ||
173 | |||
174 | }; | ||
175 | |||
176 | |||
177 | /** | ||
159 | * Returns the operation context with the given id if found in the Operation | 178 | * Returns the operation context with the given id if found in the Operation |
160 | * context queues of the controller | 179 | * context queues of the controller |
161 | * | 180 | * |
@@ -326,6 +345,18 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c, | |||
326 | LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n"); | 345 | LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n"); |
327 | return GNUNET_YES; | 346 | return GNUNET_YES; |
328 | } | 347 | } |
348 | if (OP_FORWARDED == opc->type) | ||
349 | { | ||
350 | struct ForwardedOperationData *fo_data; | ||
351 | |||
352 | fo_data = opc->data; | ||
353 | if (NULL != fo_data->cc) | ||
354 | fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); | ||
355 | GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); | ||
356 | GNUNET_free (fo_data); | ||
357 | GNUNET_free (opc); | ||
358 | return GNUNET_YES; | ||
359 | } | ||
329 | GNUNET_assert (OP_PEER_CREATE == opc->type); | 360 | GNUNET_assert (OP_PEER_CREATE == opc->type); |
330 | GNUNET_assert (NULL != opc->data); | 361 | GNUNET_assert (NULL != opc->data); |
331 | data = opc->data; | 362 | data = opc->data; |
@@ -719,6 +750,48 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | |||
719 | 750 | ||
720 | 751 | ||
721 | /** | 752 | /** |
753 | * Sends the given message as an operation. The given callback is called when a | ||
754 | * reply for the operation is available | ||
755 | * | ||
756 | * @param controller the controller to which the message has to be sent | ||
757 | * @param operation_id the operation id of the message | ||
758 | * @param msg the message to send | ||
759 | * @param cc the callback to call when reply is available | ||
760 | * @param cc_cls the closure for the above callback | ||
761 | * @return the operation context which can be used to cancel the forwarded | ||
762 | * operation | ||
763 | */ | ||
764 | struct OperationContext * | ||
765 | GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller | ||
766 | * controller, | ||
767 | uint64_t operation_id, | ||
768 | const struct GNUNET_MessageHeader *msg, | ||
769 | GNUNET_CLIENT_MessageHandler cc, | ||
770 | void *cc_cls) | ||
771 | { | ||
772 | struct OperationContext *opc; | ||
773 | struct ForwardedOperationData *data; | ||
774 | struct GNUNET_MessageHeader *dup_msg; | ||
775 | uint16_t msize; | ||
776 | |||
777 | data = GNUNET_malloc (sizeof (struct ForwardedOperationData)); | ||
778 | data->cc = cc; | ||
779 | data->cc_cls = cc_cls; | ||
780 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | ||
781 | opc->type = OP_FORWARDED; | ||
782 | opc->data = data; | ||
783 | opc->id = operation_id; | ||
784 | msize = ntohs (msg->size); | ||
785 | dup_msg = GNUNET_malloc (msize); | ||
786 | (void) memcpy (dup_msg, msg, msize); | ||
787 | GNUNET_TESTBED_queue_message_ (opc->c, dup_msg); | ||
788 | GNUNET_CONTAINER_DLL_insert_tail (controller->ocq_head, | ||
789 | controller->ocq_tail, opc); | ||
790 | return opc; | ||
791 | } | ||
792 | |||
793 | |||
794 | /** | ||
722 | * Handle for controller process | 795 | * Handle for controller process |
723 | */ | 796 | */ |
724 | struct GNUNET_TESTBED_ControllerProc | 797 | struct GNUNET_TESTBED_ControllerProc |
@@ -1434,5 +1507,4 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1434 | } | 1507 | } |
1435 | } | 1508 | } |
1436 | 1509 | ||
1437 | |||
1438 | /* end of testbed_api.c */ | 1510 | /* end of testbed_api.c */ |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index c5520a8c1..d12d9aa96 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -63,6 +63,11 @@ enum OperationType | |||
63 | */ | 63 | */ |
64 | OP_OVERLAY_CONNECT, | 64 | OP_OVERLAY_CONNECT, |
65 | 65 | ||
66 | /** | ||
67 | * Forwarded operation | ||
68 | */ | ||
69 | OP_FORWARDED | ||
70 | |||
66 | }; | 71 | }; |
67 | 72 | ||
68 | 73 | ||
@@ -349,4 +354,25 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, | |||
349 | GNUNET_CONFIGURATION_Handle *cfg); | 354 | GNUNET_CONFIGURATION_Handle *cfg); |
350 | 355 | ||
351 | 356 | ||
357 | /** | ||
358 | * Sends the given message as an operation. The given callback is called when a | ||
359 | * reply for the operation is available | ||
360 | * | ||
361 | * @param controller the controller to which the message has to be sent | ||
362 | * @param operation_id the operation id of the message | ||
363 | * @param msg the message to send | ||
364 | * @param cc the callback to call when reply is available | ||
365 | * @param cc_cls the closure for the above callback | ||
366 | * @return the operation context which can be used to cancel the forwarded | ||
367 | * operation | ||
368 | */ | ||
369 | struct OperationContext * | ||
370 | GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller | ||
371 | * controller, | ||
372 | uint64_t operation_id, | ||
373 | const struct GNUNET_MessageHeader *msg, | ||
374 | GNUNET_CLIENT_MessageHandler cc, | ||
375 | void *cc_cls); | ||
376 | |||
352 | #endif | 377 | #endif |
378 | /* end of testbed_api.h */ | ||