diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-27 09:10:37 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-27 09:10:37 +0000 |
commit | a4d753e8d938081ec51efa816966a2d6153d29c4 (patch) | |
tree | 0ecd659a201e4175b653f0b7e5d1ee3cc1a1e3ee | |
parent | 7476213458c4d38472250031c50c667e765a67f7 (diff) | |
download | gnunet-a4d753e8d938081ec51efa816966a2d6153d29c4.tar.gz gnunet-a4d753e8d938081ec51efa816966a2d6153d29c4.zip |
service connect checkpoint save
-rw-r--r-- | src/testbed/testbed_api.c | 82 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 17 | ||||
-rw-r--r-- | src/testbed/testbed_api_services.c | 95 |
3 files changed, 151 insertions, 43 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 1a779c3c1..f302cb57b 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -538,6 +538,18 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
538 | LOG_DEBUG ("Operation not found\n"); | 538 | LOG_DEBUG ("Operation not found\n"); |
539 | return GNUNET_YES; | 539 | return GNUNET_YES; |
540 | } | 540 | } |
541 | if (OP_FORWARDED == opc->type) | ||
542 | { | ||
543 | struct ForwardedOperationData *fo_data; | ||
544 | |||
545 | fo_data = opc->data; | ||
546 | if (NULL != fo_data->cc) | ||
547 | fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); | ||
548 | GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); | ||
549 | GNUNET_free (fo_data); | ||
550 | GNUNET_free (opc); | ||
551 | return GNUNET_YES; | ||
552 | } | ||
541 | data = opc->data; | 553 | data = opc->data; |
542 | GNUNET_assert (NULL != data); | 554 | GNUNET_assert (NULL != data); |
543 | peer = data->peer; | 555 | peer = data->peer; |
@@ -571,29 +583,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
571 | } | 583 | } |
572 | break; | 584 | break; |
573 | case GNUNET_TESTBED_PIT_CONFIGURATION: | 585 | case GNUNET_TESTBED_PIT_CONFIGURATION: |
574 | { | 586 | response_data->details.cfg = /* Freed in oprelease_peer_getinfo */ |
575 | struct GNUNET_CONFIGURATION_Handle *cfg; | 587 | GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); |
576 | char *config; | 588 | info.details.operation_finished.op_result.cfg = response_data->details.cfg; |
577 | uLong config_size; | ||
578 | int ret; | ||
579 | uint16_t msize; | ||
580 | |||
581 | config_size = (uLong) ntohs (msg->config_size); | ||
582 | config = GNUNET_malloc (config_size); | ||
583 | msize = ntohs (msg->header.size); | ||
584 | msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | ||
585 | if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, | ||
586 | (const Bytef *) &msg[1], (uLong) msize))) | ||
587 | GNUNET_assert (0); | ||
588 | cfg = GNUNET_CONFIGURATION_create (); /* Freed in oprelease_peer_getinfo */ | ||
589 | GNUNET_assert (GNUNET_OK == | ||
590 | GNUNET_CONFIGURATION_deserialize (cfg, config, | ||
591 | (size_t) config_size, | ||
592 | GNUNET_NO)); | ||
593 | GNUNET_free (config); | ||
594 | response_data->details.cfg = cfg; | ||
595 | info.details.operation_finished.op_result.cfg = cfg; | ||
596 | } | ||
597 | break; | 589 | break; |
598 | case GNUNET_TESTBED_PIT_GENERIC: | 590 | case GNUNET_TESTBED_PIT_GENERIC: |
599 | GNUNET_assert (0); /* never reach here */ | 591 | GNUNET_assert (0); /* never reach here */ |
@@ -602,7 +594,13 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
602 | opc->data = response_data; | 594 | opc->data = response_data; |
603 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 595 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
604 | opc->state = OPC_STATE_FINISHED; | 596 | opc->state = OPC_STATE_FINISHED; |
605 | c->cc (c->cc_cls, &info); | 597 | if (0 != ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) |
598 | & c->event_mask)) | ||
599 | { | ||
600 | if (NULL != c->cc) | ||
601 | c->cc (c->cc_cls, &info); | ||
602 | } | ||
603 | |||
606 | return GNUNET_YES; | 604 | return GNUNET_YES; |
607 | } | 605 | } |
608 | 606 | ||
@@ -1292,6 +1290,8 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controll | |||
1292 | if (GNUNET_YES == controller->aux_host) | 1290 | if (GNUNET_YES == controller->aux_host) |
1293 | GNUNET_TESTBED_host_destroy (controller->host); | 1291 | GNUNET_TESTBED_host_destroy (controller->host); |
1294 | GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations); | 1292 | GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations); |
1293 | GNUNET_TESTBED_operation_queue_destroy_ | ||
1294 | (controller->opq_parallel_service_connections); | ||
1295 | GNUNET_free (controller); | 1295 | GNUNET_free (controller); |
1296 | } | 1296 | } |
1297 | 1297 | ||
@@ -1622,4 +1622,38 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1622 | } | 1622 | } |
1623 | } | 1623 | } |
1624 | 1624 | ||
1625 | |||
1626 | /** | ||
1627 | * Generates configuration by parsing Peer configuration information reply message | ||
1628 | * | ||
1629 | * @param msg the peer configuration information message | ||
1630 | * @return handle to the parsed configuration | ||
1631 | */ | ||
1632 | struct GNUNET_CONFIGURATION_Handle * | ||
1633 | GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct | ||
1634 | GNUNET_TESTBED_PeerConfigurationInformationMessage | ||
1635 | *msg) | ||
1636 | { | ||
1637 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
1638 | char *config; | ||
1639 | uLong config_size; | ||
1640 | int ret; | ||
1641 | uint16_t msize; | ||
1642 | |||
1643 | config_size = (uLong) ntohs (msg->config_size); | ||
1644 | config = GNUNET_malloc (config_size); | ||
1645 | msize = ntohs (msg->header.size); | ||
1646 | msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | ||
1647 | if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, | ||
1648 | (const Bytef *) &msg[1], (uLong) msize))) | ||
1649 | GNUNET_assert (0); | ||
1650 | cfg = GNUNET_CONFIGURATION_create (); | ||
1651 | GNUNET_assert (GNUNET_OK == | ||
1652 | GNUNET_CONFIGURATION_deserialize (cfg, config, | ||
1653 | (size_t) config_size, | ||
1654 | GNUNET_NO)); | ||
1655 | GNUNET_free (config); | ||
1656 | return cfg; | ||
1657 | } | ||
1658 | |||
1625 | /* end of testbed_api.c */ | 1659 | /* end of testbed_api.c */ |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index 09fb52569..7f7ab6c94 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #define TESTBED_API_H | 28 | #define TESTBED_API_H |
29 | 29 | ||
30 | #include "gnunet_testbed_service.h" | 30 | #include "gnunet_testbed_service.h" |
31 | #include "testbed.h" | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Enumeration of operations | 34 | * Enumeration of operations |
@@ -74,11 +75,6 @@ enum OperationType | |||
74 | */ | 75 | */ |
75 | OP_LINK_CONTROLLERS, | 76 | OP_LINK_CONTROLLERS, |
76 | 77 | ||
77 | /** | ||
78 | * Service connect operation | ||
79 | */ | ||
80 | OP_SERVICE_CONNECT | ||
81 | |||
82 | }; | 78 | }; |
83 | 79 | ||
84 | 80 | ||
@@ -392,5 +388,16 @@ void | |||
392 | GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); | 388 | GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); |
393 | 389 | ||
394 | 390 | ||
391 | /** | ||
392 | * Generates configuration by parsing Peer configuration information reply message | ||
393 | * | ||
394 | * @param msg the peer configuration information message | ||
395 | * @return handle to the parsed configuration | ||
396 | */ | ||
397 | struct GNUNET_CONFIGURATION_Handle * | ||
398 | GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct | ||
399 | GNUNET_TESTBED_PeerConfigurationInformationMessage | ||
400 | *msg); | ||
401 | |||
395 | #endif | 402 | #endif |
396 | /* end of testbed_api.h */ | 403 | /* end of testbed_api.h */ |
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index 9fbb92797..09b94e196 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c | |||
@@ -55,6 +55,31 @@ struct ServiceConnectData | |||
55 | */ | 55 | */ |
56 | void *op_cls; | 56 | void *op_cls; |
57 | 57 | ||
58 | /** | ||
59 | * The operation which created this structure | ||
60 | */ | ||
61 | struct GNUNET_TESTBED_Operation *operation; | ||
62 | |||
63 | /** | ||
64 | * The operation context from GNUNET_TESTBED_forward_operation_msg_() | ||
65 | */ | ||
66 | struct OperationContext *opc; | ||
67 | |||
68 | /** | ||
69 | * The peer handle | ||
70 | */ | ||
71 | struct GNUNET_TESTBED_Peer *peer; | ||
72 | |||
73 | /** | ||
74 | * The acquired configuration of the peer | ||
75 | */ | ||
76 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
77 | |||
78 | /** | ||
79 | * The op_result pointer from ConnectAdapter | ||
80 | */ | ||
81 | void *op_result; | ||
82 | |||
58 | }; | 83 | }; |
59 | 84 | ||
60 | 85 | ||
@@ -67,6 +92,38 @@ struct SCFOContext | |||
67 | }; | 92 | }; |
68 | 93 | ||
69 | 94 | ||
95 | /** | ||
96 | * Type of a function to call when we receive a message | ||
97 | * from the service. | ||
98 | * | ||
99 | * @param cls ServiceConnectData | ||
100 | * @param msg message received, NULL on timeout or fatal error | ||
101 | */ | ||
102 | static void | ||
103 | configuration_receiver (void *cls, | ||
104 | const struct GNUNET_MessageHeader *msg) | ||
105 | { | ||
106 | struct ServiceConnectData *data = cls; | ||
107 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; | ||
108 | struct GNUNET_TESTBED_Controller *c; | ||
109 | struct GNUNET_TESTBED_EventInformation info; | ||
110 | |||
111 | imsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) | ||
112 | msg; | ||
113 | data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg); | ||
114 | data->op_result = data->ca (data->cada_cls, data->cfg); | ||
115 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | ||
116 | info.details.operation_finished.operation = data->operation; | ||
117 | info.details.operation_finished.op_cls = data->op_cls; | ||
118 | info.details.operation_finished.emsg = NULL; | ||
119 | info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | ||
120 | info.details.operation_finished.op_result.generic = data->op_result; | ||
121 | c = data->peer->controller; | ||
122 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) | ||
123 | && (NULL != c->cc)) | ||
124 | c->cc (c->cc_cls, &info); | ||
125 | } | ||
126 | |||
70 | 127 | ||
71 | /** | 128 | /** |
72 | * Function called when a service connect operation is ready | 129 | * Function called when a service connect operation is ready |
@@ -76,7 +133,21 @@ struct SCFOContext | |||
76 | static void | 133 | static void |
77 | opstart_service_connect (void *cls) | 134 | opstart_service_connect (void *cls) |
78 | { | 135 | { |
79 | GNUNET_break (0); | 136 | struct ServiceConnectData *data = cls; |
137 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | ||
138 | struct GNUNET_TESTBED_Controller *c; | ||
139 | uint64_t op_id; | ||
140 | |||
141 | GNUNET_assert (NULL != data); | ||
142 | GNUNET_assert (NULL != data->peer); | ||
143 | c = data->peer->controller; | ||
144 | op_id = c->operation_counter++; | ||
145 | msg = GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, | ||
146 | op_id); | ||
147 | data->opc = | ||
148 | GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, | ||
149 | &configuration_receiver, data); | ||
150 | |||
80 | } | 151 | } |
81 | 152 | ||
82 | 153 | ||
@@ -120,26 +191,22 @@ GNUNET_TESTBED_service_connect (void *op_cls, | |||
120 | GNUNET_TESTBED_DisconnectAdapter da, | 191 | GNUNET_TESTBED_DisconnectAdapter da, |
121 | void *cada_cls) | 192 | void *cada_cls) |
122 | { | 193 | { |
123 | struct OperationContext *opc; | ||
124 | struct ServiceConnectData *data; | 194 | struct ServiceConnectData *data; |
125 | 195 | ||
126 | data = GNUNET_malloc (sizeof (struct ServiceConnectData)); | 196 | data = GNUNET_malloc (sizeof (struct ServiceConnectData)); |
127 | data->ca = ca; | 197 | data->ca = ca; |
128 | data->da = da; | 198 | data->da = da; |
129 | data->cada_cls = cada_cls; | 199 | data->cada_cls = cada_cls; |
130 | data->op_cls = op_cls; | 200 | data->op_cls = op_cls; |
131 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 201 | data->peer = peer; |
132 | opc->data = data; | 202 | data->operation = |
133 | opc->c = peer->controller; | 203 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, |
134 | opc->id = peer->controller->operation_counter++; | 204 | &oprelease_service_connect); |
135 | opc->type = OP_SERVICE_CONNECT; | 205 | GNUNET_TESTBED_operation_queue_insert_ |
136 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_service_connect, | 206 | (peer->controller->opq_parallel_service_connections, data->operation); |
137 | &oprelease_service_connect); | ||
138 | GNUNET_TESTBED_operation_queue_insert_ | 207 | GNUNET_TESTBED_operation_queue_insert_ |
139 | (opc->c->opq_parallel_service_connections, opc->op); | 208 | (peer->controller->opq_parallel_operations, data->operation); |
140 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | 209 | return data->operation; |
141 | opc->op); | ||
142 | return opc->op; | ||
143 | } | 210 | } |
144 | 211 | ||
145 | /* end of testbed_api_services.c */ | 212 | /* end of testbed_api_services.c */ |