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/test_testbed_api.c | |
parent | 7bb3c61cc23266e4ab91583f183dcb23f3d5c55e (diff) | |
download | gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.tar.gz gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.zip |
peer service connect and its test case
Diffstat (limited to 'src/testbed/test_testbed_api.c')
-rw-r--r-- | src/testbed/test_testbed_api.c | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 2544ae464..32f65542c 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -26,10 +26,10 @@ | |||
26 | 26 | ||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_dht_service.h" | ||
29 | #include "gnunet_testing_lib-new.h" | 30 | #include "gnunet_testing_lib-new.h" |
30 | #include "gnunet_testbed_service.h" | 31 | #include "gnunet_testbed_service.h" |
31 | 32 | ||
32 | |||
33 | /** | 33 | /** |
34 | * Generic logging shortcut | 34 | * Generic logging shortcut |
35 | */ | 35 | */ |
@@ -83,6 +83,11 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
83 | static struct GNUNET_TESTBED_Operation *operation; | 83 | static struct GNUNET_TESTBED_Operation *operation; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Handle to peer's DHT service | ||
87 | */ | ||
88 | static struct GNUNET_DHT_Handle *dht_handle; | ||
89 | |||
90 | /** | ||
86 | * Abort task identifier | 91 | * Abort task identifier |
87 | */ | 92 | */ |
88 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 93 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
@@ -109,6 +114,11 @@ enum Test | |||
109 | PEER_GETCONFIG, | 114 | PEER_GETCONFIG, |
110 | 115 | ||
111 | /** | 116 | /** |
117 | * Test where we connect to a service running on the peer | ||
118 | */ | ||
119 | PEER_SERVICE_CONNECT, | ||
120 | |||
121 | /** | ||
112 | * Test where we get a peer's identity from controller | 122 | * Test where we get a peer's identity from controller |
113 | */ | 123 | */ |
114 | PEER_DESTROY, | 124 | PEER_DESTROY, |
@@ -158,6 +168,49 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
158 | 168 | ||
159 | 169 | ||
160 | /** | 170 | /** |
171 | * Adapter function called to establish a connection to | ||
172 | * a service. | ||
173 | * | ||
174 | * @param cls closure | ||
175 | * @param cfg configuration of the peer to connect to; will be available until | ||
176 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
177 | * from GNUNET_TESTBED_service_connect() | ||
178 | * @return service handle to return in 'op_result', NULL on error | ||
179 | */ | ||
180 | static void * | ||
181 | dht_connect_adapter (void *cls, | ||
182 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
183 | { | ||
184 | GNUNET_assert (NULL == cls); | ||
185 | GNUNET_assert (OTHER == sub_test); | ||
186 | sub_test = PEER_SERVICE_CONNECT; | ||
187 | dht_handle = GNUNET_DHT_connect (cfg, 10); | ||
188 | return dht_handle; | ||
189 | } | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Adapter function called to destroy a connection to | ||
194 | * a service. | ||
195 | * | ||
196 | * @param cls closure | ||
197 | * @param op_result service handle returned from the connect adapter | ||
198 | */ | ||
199 | static void | ||
200 | dht_disconnect_adapter (void *cls, | ||
201 | void *op_result) | ||
202 | { | ||
203 | if (NULL != op_result) | ||
204 | GNUNET_DHT_disconnect (op_result); | ||
205 | GNUNET_assert (PEER_SERVICE_CONNECT == sub_test); | ||
206 | GNUNET_assert (NULL != operation); | ||
207 | operation = GNUNET_TESTBED_peer_stop (peer); | ||
208 | GNUNET_assert (NULL != operation); | ||
209 | } | ||
210 | |||
211 | |||
212 | |||
213 | /** | ||
161 | * Signature of the event handler function called by the | 214 | * Signature of the event handler function called by the |
162 | * respective event controller. | 215 | * respective event controller. |
163 | * | 216 | * |
@@ -194,6 +247,18 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
194 | GNUNET_TESTBED_operation_done (operation); | 247 | GNUNET_TESTBED_operation_done (operation); |
195 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 248 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
196 | break; | 249 | break; |
250 | case PEER_SERVICE_CONNECT: | ||
251 | GNUNET_assert (event->details.operation_finished.operation == operation); | ||
252 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
253 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
254 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | ||
255 | event->details.operation_finished.pit); | ||
256 | GNUNET_assert (NULL != dht_handle); | ||
257 | GNUNET_assert (event->details.operation_finished.op_result.generic | ||
258 | == dht_handle); | ||
259 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | ||
260 | * disconnect adapter */ | ||
261 | break; | ||
197 | case OTHER: | 262 | case OTHER: |
198 | GNUNET_assert (0); | 263 | GNUNET_assert (0); |
199 | break; | 264 | break; |
@@ -202,11 +267,17 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
202 | case GNUNET_TESTBED_ET_PEER_START: | 267 | case GNUNET_TESTBED_ET_PEER_START: |
203 | GNUNET_assert (event->details.peer_start.host == host); | 268 | GNUNET_assert (event->details.peer_start.host == host); |
204 | GNUNET_assert (event->details.peer_start.peer == peer); | 269 | GNUNET_assert (event->details.peer_start.peer == peer); |
270 | GNUNET_assert (OTHER == sub_test); | ||
205 | GNUNET_TESTBED_operation_done (operation); | 271 | GNUNET_TESTBED_operation_done (operation); |
206 | operation = GNUNET_TESTBED_peer_stop (peer); | 272 | operation = GNUNET_TESTBED_service_connect (NULL, peer, "dht", |
273 | &dht_connect_adapter, | ||
274 | &dht_disconnect_adapter, | ||
275 | NULL); | ||
276 | GNUNET_assert (NULL != operation); | ||
207 | break; | 277 | break; |
208 | case GNUNET_TESTBED_ET_PEER_STOP: | 278 | case GNUNET_TESTBED_ET_PEER_STOP: |
209 | GNUNET_assert (event->details.peer_stop.peer == peer); | 279 | GNUNET_assert (event->details.peer_stop.peer == peer); |
280 | GNUNET_assert (PEER_SERVICE_CONNECT == sub_test); | ||
210 | result = GNUNET_YES; | 281 | result = GNUNET_YES; |
211 | sub_test = PEER_GETCONFIG; | 282 | sub_test = PEER_GETCONFIG; |
212 | GNUNET_TESTBED_operation_done (operation); | 283 | GNUNET_TESTBED_operation_done (operation); |