diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-27 17:36:43 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-27 17:36:43 +0000 |
commit | 4d299a3c4088f9e72244d4cbf513a77ec8b50328 (patch) | |
tree | a72f62cbb5488234fce616ef67577d6faba677a6 /src/testbed/testbed_api_services.c | |
parent | 7bb3c61cc23266e4ab91583f183dcb23f3d5c55e (diff) | |
download | gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.tar.gz gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.zip |
peer service connect and its test case
Diffstat (limited to 'src/testbed/testbed_api_services.c')
-rw-r--r-- | src/testbed/testbed_api_services.c | 72 |
1 files changed, 59 insertions, 13 deletions
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index 09b94e196..ea7b50def 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c | |||
@@ -28,6 +28,36 @@ | |||
28 | #include "testbed_api_peers.h" | 28 | #include "testbed_api_peers.h" |
29 | #include "testbed_api_operations.h" | 29 | #include "testbed_api_operations.h" |
30 | 30 | ||
31 | |||
32 | /** | ||
33 | * States for Service connect operations | ||
34 | */ | ||
35 | enum State | ||
36 | { | ||
37 | /** | ||
38 | * Initial state | ||
39 | */ | ||
40 | INIT, | ||
41 | |||
42 | /** | ||
43 | * The configuration request has been sent | ||
44 | */ | ||
45 | CFG_REQUEST_QUEUED, | ||
46 | |||
47 | /** | ||
48 | * connected to service | ||
49 | */ | ||
50 | SERVICE_CONNECTED, | ||
51 | |||
52 | /** | ||
53 | * | ||
54 | */ | ||
55 | }; | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Data accessed during service connections | ||
60 | */ | ||
31 | struct ServiceConnectData | 61 | struct ServiceConnectData |
32 | { | 62 | { |
33 | /** | 63 | /** |
@@ -79,15 +109,11 @@ struct ServiceConnectData | |||
79 | * The op_result pointer from ConnectAdapter | 109 | * The op_result pointer from ConnectAdapter |
80 | */ | 110 | */ |
81 | void *op_result; | 111 | void *op_result; |
82 | |||
83 | }; | ||
84 | |||
85 | 112 | ||
86 | /** | 113 | /** |
87 | * Context information for forwarded operation used in service connect | 114 | * State information |
88 | */ | 115 | */ |
89 | struct SCFOContext | 116 | enum State state; |
90 | { | ||
91 | 117 | ||
92 | }; | 118 | }; |
93 | 119 | ||
@@ -118,10 +144,11 @@ configuration_receiver (void *cls, | |||
118 | info.details.operation_finished.emsg = NULL; | 144 | info.details.operation_finished.emsg = NULL; |
119 | info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | 145 | info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; |
120 | info.details.operation_finished.op_result.generic = data->op_result; | 146 | info.details.operation_finished.op_result.generic = data->op_result; |
121 | c = data->peer->controller; | 147 | c = data->peer->controller; |
148 | data->state = SERVICE_CONNECTED; | ||
122 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) | 149 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) |
123 | && (NULL != c->cc)) | 150 | && (NULL != c->cc)) |
124 | c->cc (c->cc_cls, &info); | 151 | c->cc (c->cc_cls, &info); |
125 | } | 152 | } |
126 | 153 | ||
127 | 154 | ||
@@ -147,7 +174,8 @@ opstart_service_connect (void *cls) | |||
147 | data->opc = | 174 | data->opc = |
148 | GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, | 175 | GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, |
149 | &configuration_receiver, data); | 176 | &configuration_receiver, data); |
150 | 177 | GNUNET_free (msg); | |
178 | data->state = CFG_REQUEST_QUEUED; | ||
151 | } | 179 | } |
152 | 180 | ||
153 | 181 | ||
@@ -160,7 +188,24 @@ opstart_service_connect (void *cls) | |||
160 | static void | 188 | static void |
161 | oprelease_service_connect (void *cls) | 189 | oprelease_service_connect (void *cls) |
162 | { | 190 | { |
163 | GNUNET_break (0); | 191 | struct ServiceConnectData *data = cls; |
192 | |||
193 | switch (data->state) | ||
194 | { | ||
195 | case INIT: | ||
196 | break; | ||
197 | case CFG_REQUEST_QUEUED: | ||
198 | GNUNET_assert (NULL != data->opc); | ||
199 | GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc); | ||
200 | break; | ||
201 | case SERVICE_CONNECTED: | ||
202 | GNUNET_assert (NULL != data->cfg); | ||
203 | GNUNET_CONFIGURATION_destroy (data->cfg); | ||
204 | if (NULL != data->da) | ||
205 | data->da (data->cada_cls, data->op_result); | ||
206 | break; | ||
207 | } | ||
208 | GNUNET_free (data); | ||
164 | } | 209 | } |
165 | 210 | ||
166 | 211 | ||
@@ -198,7 +243,8 @@ GNUNET_TESTBED_service_connect (void *op_cls, | |||
198 | data->da = da; | 243 | data->da = da; |
199 | data->cada_cls = cada_cls; | 244 | data->cada_cls = cada_cls; |
200 | data->op_cls = op_cls; | 245 | data->op_cls = op_cls; |
201 | data->peer = peer; | 246 | data->peer = peer; |
247 | data->state = INIT; | ||
202 | data->operation = | 248 | data->operation = |
203 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, | 249 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, |
204 | &oprelease_service_connect); | 250 | &oprelease_service_connect); |