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 | |
parent | 7bb3c61cc23266e4ab91583f183dcb23f3d5c55e (diff) | |
download | gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.tar.gz gnunet-4d299a3c4088f9e72244d4cbf513a77ec8b50328.zip |
peer service connect and its test case
-rw-r--r-- | src/testbed/Makefile.am | 1 | ||||
-rw-r--r-- | src/testbed/test_testbed_api.c | 77 | ||||
-rw-r--r-- | src/testbed/testbed_api_services.c | 72 |
3 files changed, 134 insertions, 16 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 22870bd9a..d7262d62e 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -96,6 +96,7 @@ test_testbed_api_SOURCES = \ | |||
96 | test_testbed_api_LDADD = \ | 96 | test_testbed_api_LDADD = \ |
97 | $(top_builddir)/src/util/libgnunetutil.la \ | 97 | $(top_builddir)/src/util/libgnunetutil.la \ |
98 | $(top_builddir)/src/testing/libgnunettesting.la \ | 98 | $(top_builddir)/src/testing/libgnunettesting.la \ |
99 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
99 | libgnunettestbed.la | 100 | libgnunettestbed.la |
100 | 101 | ||
101 | test_testbed_api_2peers_SOURCES = \ | 102 | test_testbed_api_2peers_SOURCES = \ |
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); |
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); |