diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
commit | 93085e8a2991fde229400b588a5930e9fcca0d75 (patch) | |
tree | 0384246adbd96fa0138a46ad5fecb777aa40e789 /src/testbed/gnunet-service-testbed.c | |
parent | 2bf962c76bb82c1f38acea42c7bdfb241e2582e7 (diff) | |
download | gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.tar.gz gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.zip |
migrating testbed to new service API
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 730 |
1 files changed, 375 insertions, 355 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 9e181f85a..39697cb56 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -83,128 +83,16 @@ unsigned int GST_peer_list_size; | |||
83 | /***********************************/ | 83 | /***********************************/ |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * The message queue for sending messages to clients | ||
87 | */ | ||
88 | struct MessageQueue | ||
89 | { | ||
90 | /** | ||
91 | * The message to be sent | ||
92 | */ | ||
93 | struct GNUNET_MessageHeader *msg; | ||
94 | |||
95 | /** | ||
96 | * The client to send the message to | ||
97 | */ | ||
98 | struct GNUNET_SERVER_Client *client; | ||
99 | |||
100 | /** | ||
101 | * next pointer for DLL | ||
102 | */ | ||
103 | struct MessageQueue *next; | ||
104 | |||
105 | /** | ||
106 | * prev pointer for DLL | ||
107 | */ | ||
108 | struct MessageQueue *prev; | ||
109 | }; | ||
110 | |||
111 | /** | ||
112 | * Our hostname; we give this to all the peers we start | 86 | * Our hostname; we give this to all the peers we start |
113 | */ | 87 | */ |
114 | static char *hostname; | 88 | static char *hostname; |
115 | 89 | ||
116 | /** | ||
117 | * Current Transmit Handle; NULL if no notify transmit exists currently | ||
118 | */ | ||
119 | static struct GNUNET_SERVER_TransmitHandle *transmit_handle; | ||
120 | |||
121 | /** | ||
122 | * The message queue head | ||
123 | */ | ||
124 | static struct MessageQueue *mq_head; | ||
125 | |||
126 | /** | ||
127 | * The message queue tail | ||
128 | */ | ||
129 | static struct MessageQueue *mq_tail; | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Function called to notify a client about the connection begin ready to queue | ||
134 | * more data. "buf" will be NULL and "size" zero if the connection was closed | ||
135 | * for writing in the meantime. | ||
136 | * | ||
137 | * @param cls NULL | ||
138 | * @param size number of bytes available in buf | ||
139 | * @param buf where the callee should write the message | ||
140 | * @return number of bytes written to buf | ||
141 | */ | ||
142 | static size_t | ||
143 | transmit_ready_notify (void *cls, size_t size, void *buf) | ||
144 | { | ||
145 | struct MessageQueue *mq_entry; | ||
146 | |||
147 | transmit_handle = NULL; | ||
148 | mq_entry = mq_head; | ||
149 | GNUNET_assert (NULL != mq_entry); | ||
150 | if (0 == size) | ||
151 | return 0; | ||
152 | GNUNET_assert (ntohs (mq_entry->msg->size) <= size); | ||
153 | size = ntohs (mq_entry->msg->size); | ||
154 | GNUNET_memcpy (buf, mq_entry->msg, size); | ||
155 | GNUNET_free (mq_entry->msg); | ||
156 | GNUNET_SERVER_client_drop (mq_entry->client); | ||
157 | GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry); | ||
158 | GNUNET_free (mq_entry); | ||
159 | mq_entry = mq_head; | ||
160 | if (NULL != mq_entry) | ||
161 | transmit_handle = | ||
162 | GNUNET_SERVER_notify_transmit_ready (mq_entry->client, | ||
163 | ntohs (mq_entry->msg->size), | ||
164 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
165 | &transmit_ready_notify, NULL); | ||
166 | return size; | ||
167 | } | ||
168 | |||
169 | |||
170 | /** | ||
171 | * Queues a message in send queue for sending to the service | ||
172 | * | ||
173 | * @param client the client to whom the queued message has to be sent | ||
174 | * @param msg the message to queue | ||
175 | */ | ||
176 | void | ||
177 | GST_queue_message (struct GNUNET_SERVER_Client *client, | ||
178 | struct GNUNET_MessageHeader *msg) | ||
179 | { | ||
180 | struct MessageQueue *mq_entry; | ||
181 | uint16_t type; | ||
182 | uint16_t size; | ||
183 | |||
184 | type = ntohs (msg->type); | ||
185 | size = ntohs (msg->size); | ||
186 | GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && | ||
187 | (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); | ||
188 | mq_entry = GNUNET_new (struct MessageQueue); | ||
189 | mq_entry->msg = msg; | ||
190 | mq_entry->client = client; | ||
191 | GNUNET_SERVER_client_keep (client); | ||
192 | LOG_DEBUG ("Queueing message of type %u, size %u for sending\n", type, | ||
193 | ntohs (msg->size)); | ||
194 | GNUNET_CONTAINER_DLL_insert_tail (mq_head, mq_tail, mq_entry); | ||
195 | if (NULL == transmit_handle) | ||
196 | transmit_handle = | ||
197 | GNUNET_SERVER_notify_transmit_ready (client, size, | ||
198 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
199 | &transmit_ready_notify, NULL); | ||
200 | } | ||
201 | |||
202 | 90 | ||
203 | /** | 91 | /** |
204 | * Function to add a host to the current list of known hosts | 92 | * Function to add a host to the current list of known hosts |
205 | * | 93 | * |
206 | * @param host the host to add | 94 | * @param host the host to add |
207 | * @return GNUNET_OK on success; GNUNET_SYSERR on failure due to host-id | 95 | * @return #GNUNET_OK on success; #GNUNET_SYSERR on failure due to host-id |
208 | * already in use | 96 | * already in use |
209 | */ | 97 | */ |
210 | static int | 98 | static int |
@@ -233,24 +121,25 @@ host_list_add (struct GNUNET_TESTBED_Host *host) | |||
233 | * @param emsg the error message; can be NULL | 121 | * @param emsg the error message; can be NULL |
234 | */ | 122 | */ |
235 | void | 123 | void |
236 | GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client, | 124 | GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, |
237 | uint64_t operation_id, const char *emsg) | 125 | uint64_t operation_id, |
126 | const char *emsg) | ||
238 | { | 127 | { |
128 | struct GNUNET_MQ_Envelope *env; | ||
239 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; | 129 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; |
240 | uint16_t msize; | ||
241 | uint16_t emsg_len; | 130 | uint16_t emsg_len; |
242 | 131 | ||
243 | msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); | ||
244 | emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; | 132 | emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; |
245 | msize += emsg_len; | 133 | env = GNUNET_MQ_msg_extra (msg, |
246 | msg = GNUNET_malloc (msize); | 134 | emsg_len, |
247 | msg->header.size = htons (msize); | 135 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); |
248 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); | ||
249 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | 136 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); |
250 | msg->operation_id = GNUNET_htonll (operation_id); | 137 | msg->operation_id = GNUNET_htonll (operation_id); |
251 | if (0 != emsg_len) | 138 | GNUNET_memcpy (&msg[1], |
252 | GNUNET_memcpy (&msg[1], emsg, emsg_len); | 139 | emsg, |
253 | GST_queue_message (client, &msg->header); | 140 | emsg_len); |
141 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
142 | env); | ||
254 | } | 143 | } |
255 | 144 | ||
256 | 145 | ||
@@ -261,22 +150,21 @@ GST_send_operation_fail_msg (struct GNUNET_SERVER_Client *client, | |||
261 | * @param operation_id the id of the operation which was successful | 150 | * @param operation_id the id of the operation which was successful |
262 | */ | 151 | */ |
263 | void | 152 | void |
264 | GST_send_operation_success_msg (struct GNUNET_SERVER_Client *client, | 153 | GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, |
265 | uint64_t operation_id) | 154 | uint64_t operation_id) |
266 | { | 155 | { |
156 | struct GNUNET_MQ_Envelope *env; | ||
267 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; | 157 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; |
268 | uint16_t msize; | ||
269 | 158 | ||
270 | msize = sizeof (struct GNUNET_TESTBED_GenericOperationSuccessEventMessage); | 159 | env = GNUNET_MQ_msg (msg, |
271 | msg = GNUNET_malloc (msize); | 160 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); |
272 | msg->header.size = htons (msize); | ||
273 | msg->header.type = | ||
274 | htons (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); | ||
275 | msg->operation_id = GNUNET_htonll (operation_id); | 161 | msg->operation_id = GNUNET_htonll (operation_id); |
276 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); | 162 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); |
277 | GST_queue_message (client, &msg->header); | 163 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
164 | env); | ||
278 | } | 165 | } |
279 | 166 | ||
167 | |||
280 | /** | 168 | /** |
281 | * Callback which will be called after a host registration succeeded or failed | 169 | * Callback which will be called after a host registration succeeded or failed |
282 | * | 170 | * |
@@ -284,7 +172,8 @@ GST_send_operation_success_msg (struct GNUNET_SERVER_Client *client, | |||
284 | * @param emsg the error message; NULL if host registration is successful | 172 | * @param emsg the error message; NULL if host registration is successful |
285 | */ | 173 | */ |
286 | static void | 174 | static void |
287 | hr_completion (void *cls, const char *emsg); | 175 | hr_completion (void *cls, |
176 | const char *emsg); | ||
288 | 177 | ||
289 | 178 | ||
290 | /** | 179 | /** |
@@ -304,8 +193,10 @@ register_next_host (struct Slave *slave) | |||
304 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", | 193 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", |
305 | GNUNET_TESTBED_host_get_id_ (hr->host), | 194 | GNUNET_TESTBED_host_get_id_ (hr->host), |
306 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); | 195 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); |
307 | slave->rhandle = | 196 | slave->rhandle |
308 | GNUNET_TESTBED_register_host (slave->controller, hr->host, hr_completion, | 197 | = GNUNET_TESTBED_register_host (slave->controller, |
198 | hr->host, | ||
199 | hr_completion, | ||
309 | slave); | 200 | slave); |
310 | } | 201 | } |
311 | 202 | ||
@@ -317,7 +208,8 @@ register_next_host (struct Slave *slave) | |||
317 | * @param emsg the error message; NULL if host registration is successful | 208 | * @param emsg the error message; NULL if host registration is successful |
318 | */ | 209 | */ |
319 | static void | 210 | static void |
320 | hr_completion (void *cls, const char *emsg) | 211 | hr_completion (void *cls, |
212 | const char *emsg) | ||
321 | { | 213 | { |
322 | struct Slave *slave = cls; | 214 | struct Slave *slave = cls; |
323 | struct HostRegistration *hr; | 215 | struct HostRegistration *hr; |
@@ -325,12 +217,16 @@ hr_completion (void *cls, const char *emsg) | |||
325 | slave->rhandle = NULL; | 217 | slave->rhandle = NULL; |
326 | hr = slave->hr_dll_head; | 218 | hr = slave->hr_dll_head; |
327 | GNUNET_assert (NULL != hr); | 219 | GNUNET_assert (NULL != hr); |
328 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u successful\n", | 220 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
221 | "Registering host %u at %u successful\n", | ||
329 | GNUNET_TESTBED_host_get_id_ (hr->host), | 222 | GNUNET_TESTBED_host_get_id_ (hr->host), |
330 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); | 223 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); |
331 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, slave->hr_dll_tail, hr); | 224 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, |
225 | slave->hr_dll_tail, | ||
226 | hr); | ||
332 | if (NULL != hr->cb) | 227 | if (NULL != hr->cb) |
333 | hr->cb (hr->cb_cls, emsg); | 228 | hr->cb (hr->cb_cls, |
229 | emsg); | ||
334 | GNUNET_free (hr); | 230 | GNUNET_free (hr); |
335 | if (NULL != slave->hr_dll_head) | 231 | if (NULL != slave->hr_dll_head) |
336 | register_next_host (slave); | 232 | register_next_host (slave); |
@@ -349,7 +245,8 @@ hr_completion (void *cls, const char *emsg) | |||
349 | void | 245 | void |
350 | GST_queue_host_registration (struct Slave *slave, | 246 | GST_queue_host_registration (struct Slave *slave, |
351 | GNUNET_TESTBED_HostRegistrationCompletion cb, | 247 | GNUNET_TESTBED_HostRegistrationCompletion cb, |
352 | void *cb_cls, struct GNUNET_TESTBED_Host *host) | 248 | void *cb_cls, |
249 | struct GNUNET_TESTBED_Host *host) | ||
353 | { | 250 | { |
354 | struct HostRegistration *hr; | 251 | struct HostRegistration *hr; |
355 | int call_register; | 252 | int call_register; |
@@ -363,7 +260,9 @@ GST_queue_host_registration (struct Slave *slave, | |||
363 | hr->cb_cls = cb_cls; | 260 | hr->cb_cls = cb_cls; |
364 | hr->host = host; | 261 | hr->host = host; |
365 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; | 262 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; |
366 | GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, slave->hr_dll_tail, hr); | 263 | GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, |
264 | slave->hr_dll_tail, | ||
265 | hr); | ||
367 | if (GNUNET_YES == call_register) | 266 | if (GNUNET_YES == call_register) |
368 | register_next_host (slave); | 267 | register_next_host (slave); |
369 | } | 268 | } |
@@ -380,23 +279,24 @@ GST_forwarded_operation_reply_relay (void *cls, | |||
380 | const struct GNUNET_MessageHeader *msg) | 279 | const struct GNUNET_MessageHeader *msg) |
381 | { | 280 | { |
382 | struct ForwardedOperationContext *fopc = cls; | 281 | struct ForwardedOperationContext *fopc = cls; |
383 | struct GNUNET_MessageHeader *dup_msg; | 282 | struct GNUNET_MQ_Envelope *env; |
384 | uint16_t msize; | ||
385 | 283 | ||
386 | msize = ntohs (msg->size); | 284 | LOG_DEBUG ("Relaying message with type: %u, size: %u\n", |
387 | LOG_DEBUG ("Relaying message with type: %u, size: %u\n", ntohs (msg->type), | 285 | ntohs (msg->type), |
388 | msize); | 286 | ntohs (msg->size)); |
389 | dup_msg = GNUNET_copy_message (msg); | 287 | env = GNUNET_MQ_msg_copy (msg); |
390 | GST_queue_message (fopc->client, dup_msg); | 288 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (fopc->client), |
391 | GNUNET_SERVER_client_drop (fopc->client); | 289 | env); |
392 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 290 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); |
393 | GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc); | 291 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
292 | fopcq_tail, | ||
293 | fopc); | ||
394 | GNUNET_free (fopc); | 294 | GNUNET_free (fopc); |
395 | } | 295 | } |
396 | 296 | ||
397 | 297 | ||
398 | /** | 298 | /** |
399 | * Task to free resources when forwarded operation has been timedout | 299 | * Task to free resources when forwarded operation has been timed out |
400 | * | 300 | * |
401 | * @param cls the ForwardedOperationContext | 301 | * @param cls the ForwardedOperationContext |
402 | */ | 302 | */ |
@@ -405,12 +305,16 @@ GST_forwarded_operation_timeout (void *cls) | |||
405 | { | 305 | { |
406 | struct ForwardedOperationContext *fopc = cls; | 306 | struct ForwardedOperationContext *fopc = cls; |
407 | 307 | ||
308 | fopc->timeout_task = NULL; | ||
408 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | 309 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); |
409 | LOG (GNUNET_ERROR_TYPE_DEBUG, "A forwarded operation has timed out\n"); | 310 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
410 | GST_send_operation_fail_msg (fopc->client, fopc->operation_id, | 311 | "A forwarded operation has timed out\n"); |
312 | GST_send_operation_fail_msg (fopc->client, | ||
313 | fopc->operation_id, | ||
411 | "A forwarded operation has timed out"); | 314 | "A forwarded operation has timed out"); |
412 | GNUNET_SERVER_client_drop (fopc->client); | 315 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
413 | GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc); | 316 | fopcq_tail, |
317 | fopc); | ||
414 | GNUNET_free (fopc); | 318 | GNUNET_free (fopc); |
415 | } | 319 | } |
416 | 320 | ||
@@ -425,7 +329,8 @@ GST_forwarded_operation_timeout (void *cls) | |||
425 | * upon empty service sharing specification. | 329 | * upon empty service sharing specification. |
426 | */ | 330 | */ |
427 | static struct GNUNET_TESTING_SharedService * | 331 | static struct GNUNET_TESTING_SharedService * |
428 | parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) | 332 | parse_shared_services (char *ss_str, |
333 | struct GNUNET_CONFIGURATION_Handle *cfg) | ||
429 | { | 334 | { |
430 | struct GNUNET_TESTING_SharedService ss; | 335 | struct GNUNET_TESTING_SharedService ss; |
431 | struct GNUNET_TESTING_SharedService *slist; | 336 | struct GNUNET_TESTING_SharedService *slist; |
@@ -446,19 +351,27 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
446 | { | 351 | { |
447 | ss.service = NULL; | 352 | ss.service = NULL; |
448 | ss.share = 0; | 353 | ss.share = 0; |
449 | if (2 != sscanf (arg, "%255[^:]:%u", service, &ss.share)) | 354 | if (2 != sscanf (arg, "%255[^:]:%u", |
355 | service, | ||
356 | &ss.share)) | ||
450 | { | 357 | { |
451 | LOG (GNUNET_ERROR_TYPE_WARNING, "Ignoring shared service spec: %s", arg); | 358 | LOG (GNUNET_ERROR_TYPE_WARNING, |
359 | "Ignoring shared service spec: %s", | ||
360 | arg); | ||
452 | continue; | 361 | continue; |
453 | } | 362 | } |
454 | LOG_DEBUG ("Will be sharing %s service among %u peers\n", service, ss.share); | 363 | LOG_DEBUG ("Will be sharing %s service among %u peers\n", |
364 | service, | ||
365 | ss.share); | ||
455 | ss.service = GNUNET_strdup (service); | 366 | ss.service = GNUNET_strdup (service); |
456 | GROW_SS; | 367 | GROW_SS; |
457 | } | 368 | } |
458 | if (NULL != slist) | 369 | if (NULL != slist) |
459 | { | 370 | { |
460 | /* Add trailing NULL block */ | 371 | /* Add trailing NULL block */ |
461 | (void) memset (&ss, 0, sizeof (struct GNUNET_TESTING_SharedService)); | 372 | (void) memset (&ss, |
373 | 0, | ||
374 | sizeof (struct GNUNET_TESTING_SharedService)); | ||
462 | GROW_SS; | 375 | GROW_SS; |
463 | } | 376 | } |
464 | return slist; | 377 | return slist; |
@@ -467,66 +380,78 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
467 | 380 | ||
468 | 381 | ||
469 | /** | 382 | /** |
470 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | 383 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_INIT messages |
471 | * | 384 | * |
472 | * @param cls NULL | 385 | * @param cls identification of the client |
473 | * @param client identification of the client | 386 | * @param message the actual message |
387 | * @return #GNUNET_OK if @a message is well-formed | ||
388 | */ | ||
389 | static int | ||
390 | check_init (void *cls, | ||
391 | const struct GNUNET_TESTBED_InitMessage *msg) | ||
392 | { | ||
393 | const char *controller_hostname; | ||
394 | uint16_t msize; | ||
395 | |||
396 | msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_InitMessage); | ||
397 | controller_hostname = (const char *) &msg[1]; | ||
398 | if ('\0' != controller_hostname[msize - 1]) | ||
399 | { | ||
400 | GNUNET_break (0); | ||
401 | return GNUNET_SYSERR; | ||
402 | } | ||
403 | return GNUNET_OK; | ||
404 | } | ||
405 | |||
406 | |||
407 | /** | ||
408 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_INIT messages | ||
409 | * | ||
410 | * @param cls identification of the client | ||
474 | * @param message the actual message | 411 | * @param message the actual message |
475 | */ | 412 | */ |
476 | static void | 413 | static void |
477 | handle_init (void *cls, | 414 | handle_init (void *cls, |
478 | struct GNUNET_SERVER_Client *client, | 415 | const struct GNUNET_TESTBED_InitMessage *msg) |
479 | const struct GNUNET_MessageHeader *message) | ||
480 | { | 416 | { |
481 | const struct GNUNET_TESTBED_InitMessage *msg; | 417 | struct GNUNET_SERVICE_Client *client = cls; |
482 | struct GNUNET_TESTBED_Host *host; | 418 | struct GNUNET_TESTBED_Host *host; |
483 | const char *controller_hostname; | 419 | const char *controller_hostname; |
484 | char *ss_str; | 420 | char *ss_str; |
485 | struct GNUNET_TESTING_SharedService *ss; | 421 | struct GNUNET_TESTING_SharedService *ss; |
486 | unsigned int cnt; | 422 | unsigned int cnt; |
487 | uint16_t msize; | ||
488 | 423 | ||
489 | if (NULL != GST_context) | 424 | if (NULL != GST_context) |
490 | { | 425 | { |
491 | LOG_DEBUG ("We are being connected to laterally\n"); | 426 | LOG_DEBUG ("We are being connected to laterally\n"); |
492 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 427 | GNUNET_SERVICE_client_continue (client); |
493 | return; | 428 | return; |
494 | } | 429 | } |
495 | msg = (const struct GNUNET_TESTBED_InitMessage *) message; | ||
496 | msize = ntohs (message->size); | ||
497 | if (msize <= sizeof (struct GNUNET_TESTBED_InitMessage)) | ||
498 | { | ||
499 | GNUNET_break (0); | ||
500 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
501 | return; | ||
502 | } | ||
503 | msize -= sizeof (struct GNUNET_TESTBED_InitMessage); | ||
504 | controller_hostname = (const char *) &msg[1]; | 430 | controller_hostname = (const char *) &msg[1]; |
505 | if ('\0' != controller_hostname[msize - 1]) | ||
506 | { | ||
507 | GNUNET_break (0); | ||
508 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
509 | return; | ||
510 | } | ||
511 | ss_str = NULL; | 431 | ss_str = NULL; |
512 | ss = NULL; | 432 | ss = NULL; |
513 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (GST_config, "TESTBED", | 433 | if (GNUNET_OK == |
514 | "SHARED_SERVICES", | 434 | GNUNET_CONFIGURATION_get_value_string (GST_config, |
515 | &ss_str)) | 435 | "TESTBED", |
436 | "SHARED_SERVICES", | ||
437 | &ss_str)) | ||
516 | { | 438 | { |
517 | ss = parse_shared_services (ss_str, GST_config); | 439 | ss = parse_shared_services (ss_str, |
440 | GST_config); | ||
518 | GNUNET_free (ss_str); | 441 | GNUNET_free (ss_str); |
519 | ss_str = NULL; | 442 | ss_str = NULL; |
520 | } | 443 | } |
521 | GST_context = GNUNET_new (struct Context); | 444 | GST_context = GNUNET_new (struct Context); |
522 | GNUNET_SERVER_client_keep (client); | ||
523 | GST_context->client = client; | 445 | GST_context->client = client; |
524 | GST_context->host_id = ntohl (msg->host_id); | 446 | GST_context->host_id = ntohl (msg->host_id); |
525 | GST_context->master_ip = GNUNET_strdup (controller_hostname); | 447 | GST_context->master_ip = GNUNET_strdup (controller_hostname); |
526 | LOG_DEBUG ("Our IP: %s\n", GST_context->master_ip); | 448 | LOG_DEBUG ("Our IP: %s\n", |
527 | GST_context->system = | 449 | GST_context->master_ip); |
528 | GNUNET_TESTING_system_create ("testbed", GST_context->master_ip, | 450 | GST_context->system |
529 | hostname, ss); | 451 | = GNUNET_TESTING_system_create ("testbed", |
452 | GST_context->master_ip, | ||
453 | hostname, | ||
454 | ss); | ||
530 | if (NULL != ss) | 455 | if (NULL != ss) |
531 | { | 456 | { |
532 | for (cnt = 0; NULL != ss[cnt].service; cnt++) | 457 | for (cnt = 0; NULL != ss[cnt].service; cnt++) |
@@ -539,28 +464,64 @@ handle_init (void *cls, | |||
539 | } | 464 | } |
540 | host = | 465 | host = |
541 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, | 466 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, |
542 | GST_context->master_ip, NULL, | 467 | GST_context->master_ip, |
543 | GST_config, 0); | 468 | NULL, |
469 | GST_config, | ||
470 | 0); | ||
544 | host_list_add (host); | 471 | host_list_add (host); |
545 | LOG_DEBUG ("Created master context with host ID: %u\n", GST_context->host_id); | 472 | LOG_DEBUG ("Created master context with host ID: %u\n", |
546 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 473 | GST_context->host_id); |
474 | GNUNET_SERVICE_client_continue (client); | ||
475 | } | ||
476 | |||
477 | |||
478 | /** | ||
479 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | ||
480 | * | ||
481 | * @param cls identification of the client | ||
482 | * @param msg the actual message | ||
483 | * @return #GNUNET_OK if @a message is well-formed | ||
484 | */ | ||
485 | static int | ||
486 | check_add_host (void *cls, | ||
487 | const struct GNUNET_TESTBED_AddHostMessage *msg) | ||
488 | { | ||
489 | uint16_t username_length; | ||
490 | uint16_t hostname_length; | ||
491 | uint16_t msize; | ||
492 | |||
493 | msize = ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_AddHostMessage); | ||
494 | username_length = ntohs (msg->username_length); | ||
495 | hostname_length = ntohs (msg->hostname_length); | ||
496 | /* msg must contain hostname */ | ||
497 | if ( (msize <= username_length) || | ||
498 | (0 == hostname_length) ) | ||
499 | { | ||
500 | GNUNET_break (0); | ||
501 | return GNUNET_SYSERR; | ||
502 | } | ||
503 | /* msg must contain configuration */ | ||
504 | if (msize <= username_length + hostname_length) | ||
505 | { | ||
506 | GNUNET_break (0); | ||
507 | return GNUNET_SYSERR; | ||
508 | } | ||
509 | return GNUNET_OK; | ||
547 | } | 510 | } |
548 | 511 | ||
549 | 512 | ||
550 | /** | 513 | /** |
551 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | 514 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages |
552 | * | 515 | * |
553 | * @param cls NULL | 516 | * @param cls identification of the client |
554 | * @param client identification of the client | 517 | * @param msg the actual message |
555 | * @param message the actual message | ||
556 | */ | 518 | */ |
557 | static void | 519 | static void |
558 | handle_add_host (void *cls, | 520 | handle_add_host (void *cls, |
559 | struct GNUNET_SERVER_Client *client, | 521 | const struct GNUNET_TESTBED_AddHostMessage *msg) |
560 | const struct GNUNET_MessageHeader *message) | ||
561 | { | 522 | { |
523 | struct GNUNET_SERVICE_Client *client = cls; | ||
562 | struct GNUNET_TESTBED_Host *host; | 524 | struct GNUNET_TESTBED_Host *host; |
563 | const struct GNUNET_TESTBED_AddHostMessage *msg; | ||
564 | struct GNUNET_TESTBED_HostConfirmedMessage *reply; | 525 | struct GNUNET_TESTBED_HostConfirmedMessage *reply; |
565 | struct GNUNET_CONFIGURATION_Handle *host_cfg; | 526 | struct GNUNET_CONFIGURATION_Handle *host_cfg; |
566 | char *username; | 527 | char *username; |
@@ -570,36 +531,10 @@ handle_add_host (void *cls, | |||
570 | uint32_t host_id; | 531 | uint32_t host_id; |
571 | uint16_t username_length; | 532 | uint16_t username_length; |
572 | uint16_t hostname_length; | 533 | uint16_t hostname_length; |
573 | uint16_t reply_size; | 534 | struct GNUNET_MQ_Envelope *env; |
574 | uint16_t msize; | ||
575 | 535 | ||
576 | msg = (const struct GNUNET_TESTBED_AddHostMessage *) message; | ||
577 | msize = ntohs (msg->header.size); | ||
578 | if (msize <= sizeof (struct GNUNET_TESTBED_AddHostMessage)) | ||
579 | { | ||
580 | GNUNET_break_op (0); | ||
581 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
582 | return; | ||
583 | } | ||
584 | username_length = ntohs (msg->username_length); | 536 | username_length = ntohs (msg->username_length); |
585 | hostname_length = ntohs (msg->hostname_length); | 537 | hostname_length = ntohs (msg->hostname_length); |
586 | /* msg must contain hostname */ | ||
587 | if ((msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) + | ||
588 | username_length)) | ||
589 | || (0 == hostname_length)) | ||
590 | { | ||
591 | GNUNET_break_op (0); | ||
592 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
593 | return; | ||
594 | } | ||
595 | /* msg must contain configuration */ | ||
596 | if (msize <= (sizeof (struct GNUNET_TESTBED_AddHostMessage) + | ||
597 | username_length + hostname_length)) | ||
598 | { | ||
599 | GNUNET_break_op (0); | ||
600 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
601 | return; | ||
602 | } | ||
603 | username = NULL; | 538 | username = NULL; |
604 | hostname = NULL; | 539 | hostname = NULL; |
605 | ptr = &msg[1]; | 540 | ptr = &msg[1]; |
@@ -610,13 +545,15 @@ handle_add_host (void *cls, | |||
610 | ptr += username_length; | 545 | ptr += username_length; |
611 | } | 546 | } |
612 | hostname = GNUNET_malloc (hostname_length + 1); | 547 | hostname = GNUNET_malloc (hostname_length + 1); |
613 | strncpy (hostname, ptr, hostname_length); | 548 | strncpy (hostname, |
614 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (message))) | 549 | ptr, |
550 | hostname_length); | ||
551 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header))) | ||
615 | { | 552 | { |
616 | GNUNET_free_non_null (username); | 553 | GNUNET_free_non_null (username); |
617 | GNUNET_free_non_null (hostname); | 554 | GNUNET_free_non_null (hostname); |
618 | GNUNET_break_op (0); | 555 | GNUNET_break_op (0); |
619 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 556 | GNUNET_SERVICE_client_drop (client); |
620 | return; | 557 | return; |
621 | } | 558 | } |
622 | host_id = ntohl (msg->host_id); | 559 | host_id = ntohl (msg->host_id); |
@@ -628,94 +565,108 @@ handle_add_host (void *cls, | |||
628 | else | 565 | else |
629 | LOG_DEBUG ("-------username: <not given>\n"); | 566 | LOG_DEBUG ("-------username: <not given>\n"); |
630 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); | 567 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); |
631 | host = | 568 | host = GNUNET_TESTBED_host_create_with_id (host_id, |
632 | GNUNET_TESTBED_host_create_with_id (host_id, hostname, username, | 569 | hostname, |
633 | host_cfg, ntohs (msg->ssh_port)); | 570 | username, |
571 | host_cfg, | ||
572 | ntohs (msg->ssh_port)); | ||
634 | GNUNET_free_non_null (username); | 573 | GNUNET_free_non_null (username); |
635 | GNUNET_free (hostname); | 574 | GNUNET_free (hostname); |
636 | GNUNET_CONFIGURATION_destroy (host_cfg); | 575 | GNUNET_CONFIGURATION_destroy (host_cfg); |
637 | if (NULL == host) | 576 | if (NULL == host) |
638 | { | 577 | { |
639 | GNUNET_break_op (0); | 578 | GNUNET_break_op (0); |
640 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 579 | GNUNET_SERVICE_client_drop (client); |
641 | return; | 580 | return; |
642 | } | 581 | } |
643 | reply_size = sizeof (struct GNUNET_TESTBED_HostConfirmedMessage); | ||
644 | if (GNUNET_OK != host_list_add (host)) | 582 | if (GNUNET_OK != host_list_add (host)) |
645 | { | 583 | { |
646 | /* We are unable to add a host */ | 584 | /* We are unable to add a host */ |
647 | emsg = "A host exists with given host-id"; | 585 | emsg = "A host exists with given host-id"; |
648 | LOG_DEBUG ("%s: %u", emsg, host_id); | 586 | LOG_DEBUG ("%s: %u", |
587 | emsg, | ||
588 | host_id); | ||
649 | GNUNET_TESTBED_host_destroy (host); | 589 | GNUNET_TESTBED_host_destroy (host); |
650 | reply_size += strlen (emsg) + 1; | 590 | env = GNUNET_MQ_msg_extra (reply, |
651 | reply = GNUNET_malloc (reply_size); | 591 | strlen (emsg) + 1, |
652 | GNUNET_memcpy (&reply[1], emsg, strlen (emsg) + 1); | 592 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); |
593 | GNUNET_memcpy (&reply[1], | ||
594 | emsg, | ||
595 | strlen (emsg) + 1); | ||
653 | } | 596 | } |
654 | else | 597 | else |
655 | { | 598 | { |
656 | LOG_DEBUG ("Added host %u at %u\n", host_id, GST_context->host_id); | 599 | LOG_DEBUG ("Added host %u at %u\n", |
657 | reply = GNUNET_malloc (reply_size); | 600 | host_id, |
601 | GST_context->host_id); | ||
602 | env = GNUNET_MQ_msg (reply, | ||
603 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | ||
658 | } | 604 | } |
659 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | ||
660 | reply->header.size = htons (reply_size); | ||
661 | reply->host_id = htonl (host_id); | 605 | reply->host_id = htonl (host_id); |
662 | GST_queue_message (client, &reply->header); | 606 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
663 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 607 | env); |
608 | GNUNET_SERVICE_client_continue (client); | ||
664 | } | 609 | } |
665 | 610 | ||
666 | 611 | ||
667 | /** | 612 | /** |
668 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages | 613 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages |
669 | * | 614 | * |
670 | * @param cls NULL | 615 | * @param cls identification of the client |
671 | * @param client identification of the client | 616 | * @param msg the actual message |
672 | * @param message the actual message | ||
673 | */ | 617 | */ |
674 | static void | 618 | static void |
675 | handle_slave_get_config (void *cls, | 619 | handle_slave_get_config (void *cls, |
676 | struct GNUNET_SERVER_Client *client, | 620 | const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) |
677 | const struct GNUNET_MessageHeader *message) | ||
678 | { | 621 | { |
679 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; | 622 | struct GNUNET_SERVICE_Client *client = cls; |
680 | struct Slave *slave; | 623 | struct Slave *slave; |
681 | struct GNUNET_TESTBED_SlaveConfiguration *reply; | 624 | struct GNUNET_TESTBED_SlaveConfiguration *reply; |
682 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 625 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
626 | struct GNUNET_MQ_Envelope *env; | ||
683 | char *config; | 627 | char *config; |
684 | char *xconfig; | 628 | char *xconfig; |
685 | size_t config_size; | 629 | size_t config_size; |
686 | size_t xconfig_size; | 630 | size_t xconfig_size; |
687 | size_t reply_size; | ||
688 | uint64_t op_id; | 631 | uint64_t op_id; |
689 | uint32_t slave_id; | 632 | uint32_t slave_id; |
690 | 633 | ||
691 | msg = (struct GNUNET_TESTBED_SlaveGetConfigurationMessage *) message; | ||
692 | slave_id = ntohl (msg->slave_id); | 634 | slave_id = ntohl (msg->slave_id); |
693 | op_id = GNUNET_ntohll (msg->operation_id); | 635 | op_id = GNUNET_ntohll (msg->operation_id); |
694 | if ((GST_slave_list_size <= slave_id) || (NULL == GST_slave_list[slave_id])) | 636 | if ( (GST_slave_list_size <= slave_id) || |
637 | (NULL == GST_slave_list[slave_id]) ) | ||
695 | { | 638 | { |
696 | /* FIXME: Add forwardings for this type of message here.. */ | 639 | /* FIXME: Add forwardings for this type of message here.. */ |
697 | GST_send_operation_fail_msg (client, op_id, "Slave not found"); | 640 | GST_send_operation_fail_msg (client, |
698 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 641 | op_id, |
642 | "Slave not found"); | ||
643 | GNUNET_SERVICE_client_continue (client); | ||
699 | return; | 644 | return; |
700 | } | 645 | } |
701 | slave = GST_slave_list[slave_id]; | 646 | slave = GST_slave_list[slave_id]; |
702 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id]))); | 647 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (GST_host_list[slave->host_id]))); |
703 | config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); | 648 | config = GNUNET_CONFIGURATION_serialize (cfg, |
704 | xconfig_size = | 649 | &config_size); |
705 | GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); | 650 | /* FIXME: maybe we want to transmit the delta to the default here? */ |
651 | xconfig_size = GNUNET_TESTBED_compress_config_ (config, | ||
652 | config_size, | ||
653 | &xconfig); | ||
706 | GNUNET_free (config); | 654 | GNUNET_free (config); |
707 | reply_size = xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration); | 655 | GNUNET_assert (xconfig_size + sizeof (struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); |
708 | GNUNET_break (reply_size <= UINT16_MAX); | 656 | GNUNET_assert (xconfig_size <= UINT16_MAX); |
709 | GNUNET_break (config_size <= UINT16_MAX); | 657 | env = GNUNET_MQ_msg_extra (reply, |
710 | reply = GNUNET_realloc (xconfig, reply_size); | 658 | xconfig_size, |
711 | (void) memmove (&reply[1], reply, xconfig_size); | 659 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); |
712 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); | ||
713 | reply->header.size = htons ((uint16_t) reply_size); | ||
714 | reply->slave_id = msg->slave_id; | 660 | reply->slave_id = msg->slave_id; |
715 | reply->operation_id = msg->operation_id; | 661 | reply->operation_id = msg->operation_id; |
716 | reply->config_size = htons ((uint16_t) config_size); | 662 | reply->config_size = htons ((uint16_t) config_size); |
717 | GST_queue_message (client, &reply->header); | 663 | GNUNET_memcpy (&reply[1], |
718 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 664 | xconfig, |
665 | xconfig_size); | ||
666 | GNUNET_free (xconfig); | ||
667 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
668 | env); | ||
669 | GNUNET_SERVICE_client_continue (client); | ||
719 | } | 670 | } |
720 | 671 | ||
721 | 672 | ||
@@ -729,11 +680,12 @@ GST_clear_fopcq () | |||
729 | 680 | ||
730 | while (NULL != (fopc = fopcq_head)) | 681 | while (NULL != (fopc = fopcq_head)) |
731 | { | 682 | { |
732 | GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc); | 683 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
684 | fopcq_tail, | ||
685 | fopc); | ||
733 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | 686 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); |
734 | if (NULL != fopc->timeout_task) | 687 | if (NULL != fopc->timeout_task) |
735 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 688 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); |
736 | GNUNET_SERVER_client_drop (fopc->client); | ||
737 | switch (fopc->type) | 689 | switch (fopc->type) |
738 | { | 690 | { |
739 | case OP_PEER_CREATE: | 691 | case OP_PEER_CREATE: |
@@ -775,13 +727,12 @@ GST_clear_fopcq () | |||
775 | static void | 727 | static void |
776 | shutdown_task (void *cls) | 728 | shutdown_task (void *cls) |
777 | { | 729 | { |
778 | struct MessageQueue *mq_entry; | ||
779 | uint32_t id; | 730 | uint32_t id; |
780 | 731 | ||
781 | LOG_DEBUG ("Shutting down testbed service\n"); | 732 | LOG_DEBUG ("Shutting down testbed service\n"); |
782 | /* cleanup any remaining forwarded operations */ | 733 | /* cleanup any remaining forwarded operations */ |
783 | GST_clear_fopcq (); | 734 | GST_clear_fopcq (); |
784 | GST_free_lcfq (); | 735 | GST_free_lcf (); |
785 | GST_free_mctxq (); | 736 | GST_free_mctxq (); |
786 | GST_free_occq (); | 737 | GST_free_occq (); |
787 | GST_free_roccq (); | 738 | GST_free_roccq (); |
@@ -803,20 +754,11 @@ shutdown_task (void *cls) | |||
803 | { | 754 | { |
804 | GNUNET_free_non_null (GST_context->master_ip); | 755 | GNUNET_free_non_null (GST_context->master_ip); |
805 | if (NULL != GST_context->system) | 756 | if (NULL != GST_context->system) |
806 | GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); | 757 | GNUNET_TESTING_system_destroy (GST_context->system, |
807 | GNUNET_SERVER_client_drop (GST_context->client); | 758 | GNUNET_YES); |
808 | GNUNET_free (GST_context); | 759 | GNUNET_free (GST_context); |
809 | GST_context = NULL; | 760 | GST_context = NULL; |
810 | } | 761 | } |
811 | if (NULL != transmit_handle) | ||
812 | GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle); | ||
813 | while (NULL != (mq_entry = mq_head)) | ||
814 | { | ||
815 | GNUNET_free (mq_entry->msg); | ||
816 | GNUNET_SERVER_client_drop (mq_entry->client); | ||
817 | GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry); | ||
818 | GNUNET_free (mq_entry); | ||
819 | } | ||
820 | GNUNET_free_non_null (hostname); | 762 | GNUNET_free_non_null (hostname); |
821 | /* Free hello cache */ | 763 | /* Free hello cache */ |
822 | GST_cache_clear (); | 764 | GST_cache_clear (); |
@@ -830,19 +772,58 @@ shutdown_task (void *cls) | |||
830 | 772 | ||
831 | 773 | ||
832 | /** | 774 | /** |
775 | * Callback for client connect | ||
776 | * | ||
777 | * @param cls NULL | ||
778 | * @param client the client which has disconnected | ||
779 | * @param mq queue for sending messages to @a client | ||
780 | * @return @a client | ||
781 | */ | ||
782 | static void * | ||
783 | client_connect_cb (void *cls, | ||
784 | struct GNUNET_SERVICE_Client *client, | ||
785 | struct GNUNET_MQ_Handle *mq) | ||
786 | { | ||
787 | return client; | ||
788 | } | ||
789 | |||
790 | |||
791 | /** | ||
833 | * Callback for client disconnect | 792 | * Callback for client disconnect |
834 | * | 793 | * |
835 | * @param cls NULL | 794 | * @param cls NULL |
836 | * @param client the client which has disconnected | 795 | * @param client the client which has disconnected |
796 | * @param app_ctx should match @a client | ||
837 | */ | 797 | */ |
838 | static void | 798 | static void |
839 | client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | 799 | client_disconnect_cb (void *cls, |
800 | struct GNUNET_SERVICE_Client *client, | ||
801 | void *app_ctx) | ||
840 | { | 802 | { |
803 | struct ForwardedOperationContext *fopc; | ||
804 | struct ForwardedOperationContext *fopcn; | ||
805 | |||
806 | GNUNET_assert (client == app_ctx); | ||
807 | GST_notify_client_disconnect_oc (client); | ||
808 | GST_link_notify_disconnect (client); | ||
809 | GST_notify_client_disconnect_peers (client); | ||
810 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | ||
811 | { | ||
812 | fopcn = fopc->next; | ||
813 | if (fopc->client == client) | ||
814 | { | ||
815 | /* handle as if it were a timeout */ | ||
816 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | ||
817 | GST_forwarded_operation_timeout (fopc); | ||
818 | } | ||
819 | } | ||
841 | if (NULL == GST_context) | 820 | if (NULL == GST_context) |
842 | return; | 821 | return; |
843 | if (client == GST_context->client) | 822 | if (client == GST_context->client) |
844 | { | 823 | { |
845 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n"); | 824 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
825 | "Master client disconnected\n"); | ||
826 | GST_context->client = NULL; | ||
846 | /* should not be needed as we're terminated by failure to read | 827 | /* should not be needed as we're terminated by failure to read |
847 | * from stdin, but if stdin fails for some reason, this shouldn't | 828 | * from stdin, but if stdin fails for some reason, this shouldn't |
848 | * hurt for now --- might need to revise this later if we ever | 829 | * hurt for now --- might need to revise this later if we ever |
@@ -857,51 +838,14 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client) | |||
857 | * Testbed setup | 838 | * Testbed setup |
858 | * | 839 | * |
859 | * @param cls closure | 840 | * @param cls closure |
860 | * @param server the initialized server | ||
861 | * @param cfg configuration to use | 841 | * @param cfg configuration to use |
842 | * @param service the initialized server | ||
862 | */ | 843 | */ |
863 | static void | 844 | static void |
864 | testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | 845 | testbed_run (void *cls, |
865 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 846 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
847 | struct GNUNET_SERVICE_Handle *service) | ||
866 | { | 848 | { |
867 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | ||
868 | {&handle_init, NULL, GNUNET_MESSAGE_TYPE_TESTBED_INIT, 0}, | ||
869 | {&handle_add_host, NULL, GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, 0}, | ||
870 | {&GST_handle_link_controllers, NULL, | ||
871 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | ||
872 | sizeof (struct GNUNET_TESTBED_ControllerLinkRequest)}, | ||
873 | {&GST_handle_peer_create, NULL, GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, 0}, | ||
874 | {&GST_handle_peer_destroy, NULL, GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, | ||
875 | sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)}, | ||
876 | {&GST_handle_peer_start, NULL, GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, | ||
877 | sizeof (struct GNUNET_TESTBED_PeerStartMessage)}, | ||
878 | {&GST_handle_peer_stop, NULL, GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, | ||
879 | sizeof (struct GNUNET_TESTBED_PeerStopMessage)}, | ||
880 | {&GST_handle_peer_get_config, NULL, | ||
881 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, | ||
882 | sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)}, | ||
883 | {&GST_handle_overlay_connect, NULL, | ||
884 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, | ||
885 | sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)}, | ||
886 | {&GST_handle_remote_overlay_connect, NULL, | ||
887 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, 0}, | ||
888 | {&GST_handle_manage_peer_service, NULL, | ||
889 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, 0}, | ||
890 | {&handle_slave_get_config, NULL, | ||
891 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, | ||
892 | sizeof (struct GNUNET_TESTBED_SlaveGetConfigurationMessage)}, | ||
893 | {&GST_handle_shutdown_peers, NULL, GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, | ||
894 | sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)}, | ||
895 | {&GST_handle_peer_reconfigure, NULL, | ||
896 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, 0}, | ||
897 | {&GST_handle_barrier_init, NULL, | ||
898 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, 0}, | ||
899 | {&GST_handle_barrier_cancel, NULL, | ||
900 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, 0}, | ||
901 | {&GST_handle_barrier_status, NULL, | ||
902 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, 0}, | ||
903 | {NULL, NULL, 0, 0} | ||
904 | }; | ||
905 | char *logfile; | 849 | char *logfile; |
906 | unsigned long long num; | 850 | unsigned long long num; |
907 | 851 | ||
@@ -910,32 +854,40 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
910 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", | 854 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", |
911 | &logfile)) | 855 | &logfile)) |
912 | { | 856 | { |
913 | GNUNET_break (GNUNET_OK == GNUNET_log_setup ("testbed", "DEBUG", logfile)); | 857 | GNUNET_break (GNUNET_OK == |
858 | GNUNET_log_setup ("testbed", | ||
859 | "DEBUG", | ||
860 | logfile)); | ||
914 | GNUNET_free (logfile); | 861 | GNUNET_free (logfile); |
915 | } | 862 | } |
916 | GNUNET_assert (GNUNET_OK == | 863 | GNUNET_assert (GNUNET_OK == |
917 | GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", | 864 | GNUNET_CONFIGURATION_get_value_number (cfg, |
918 | "CACHE_SIZE", &num)); | 865 | "TESTBED", |
866 | "CACHE_SIZE", | ||
867 | &num)); | ||
919 | GST_cache_init ((unsigned int) num); | 868 | GST_cache_init ((unsigned int) num); |
920 | GST_connection_pool_init ((unsigned int) num); | 869 | GST_connection_pool_init ((unsigned int) num); |
921 | GNUNET_assert (GNUNET_OK == | 870 | GNUNET_assert (GNUNET_OK == |
922 | GNUNET_CONFIGURATION_get_value_number (cfg, "TESTBED", | 871 | GNUNET_CONFIGURATION_get_value_number (cfg, |
923 | "MAX_OPEN_FDS", &num)); | 872 | "TESTBED", |
924 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ | 873 | "MAX_OPEN_FDS", |
925 | (OPERATION_QUEUE_TYPE_FIXED, (unsigned int) num); | 874 | &num)); |
875 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ (OPERATION_QUEUE_TYPE_FIXED, | ||
876 | (unsigned int) num); | ||
926 | GNUNET_assert (GNUNET_OK == | 877 | GNUNET_assert (GNUNET_OK == |
927 | GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED", | 878 | GNUNET_CONFIGURATION_get_value_time (cfg, |
879 | "TESTBED", | ||
928 | "OPERATION_TIMEOUT", | 880 | "OPERATION_TIMEOUT", |
929 | (struct | 881 | (struct GNUNET_TIME_Relative *) |
930 | GNUNET_TIME_Relative *) | ||
931 | &GST_timeout)); | 882 | &GST_timeout)); |
932 | GNUNET_assert (GNUNET_OK == | 883 | GNUNET_assert (GNUNET_OK == |
933 | GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", | 884 | GNUNET_CONFIGURATION_get_value_string (cfg, |
934 | "HOSTNAME", &hostname)); | 885 | "testbed", |
886 | "HOSTNAME", | ||
887 | &hostname)); | ||
935 | GST_config = GNUNET_CONFIGURATION_dup (cfg); | 888 | GST_config = GNUNET_CONFIGURATION_dup (cfg); |
936 | GNUNET_SERVER_add_handlers (server, message_handlers); | 889 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
937 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); | 890 | NULL); |
938 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
939 | LOG_DEBUG ("Testbed startup complete\n"); | 891 | LOG_DEBUG ("Testbed startup complete\n"); |
940 | GST_stats_init (GST_config); | 892 | GST_stats_init (GST_config); |
941 | GST_barriers_init (GST_config); | 893 | GST_barriers_init (GST_config); |
@@ -943,16 +895,84 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
943 | 895 | ||
944 | 896 | ||
945 | /** | 897 | /** |
946 | * The starting point of execution | 898 | * Define "main" method using service macro. |
947 | */ | 899 | */ |
948 | int | 900 | GNUNET_SERVICE_MAIN |
949 | main (int argc, char *const *argv) | 901 | ("testbed", |
950 | { | 902 | GNUNET_SERVICE_OPTION_NONE, |
951 | return (GNUNET_OK == | 903 | &testbed_run, |
952 | GNUNET_SERVICE_run (argc, argv, | 904 | &client_connect_cb, |
953 | "testbed", | 905 | &client_disconnect_cb, |
954 | GNUNET_SERVICE_OPTION_NONE, | 906 | NULL, |
955 | &testbed_run, NULL)) ? 0 : 1; | 907 | GNUNET_MQ_hd_var_size (init, |
956 | } | 908 | GNUNET_MESSAGE_TYPE_TESTBED_INIT, |
909 | struct GNUNET_TESTBED_InitMessage, | ||
910 | NULL), | ||
911 | GNUNET_MQ_hd_var_size (add_host, | ||
912 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, | ||
913 | struct GNUNET_TESTBED_AddHostMessage, | ||
914 | NULL), | ||
915 | GNUNET_MQ_hd_fixed_size (slave_get_config, | ||
916 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, | ||
917 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage, | ||
918 | NULL), | ||
919 | GNUNET_MQ_hd_fixed_size (link_controllers, | ||
920 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | ||
921 | struct GNUNET_TESTBED_ControllerLinkRequest, | ||
922 | NULL), | ||
923 | GNUNET_MQ_hd_var_size (remote_overlay_connect, | ||
924 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, | ||
925 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage, | ||
926 | NULL), | ||
927 | GNUNET_MQ_hd_fixed_size (overlay_connect, | ||
928 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, | ||
929 | struct GNUNET_TESTBED_OverlayConnectMessage, | ||
930 | NULL), | ||
931 | GNUNET_MQ_hd_var_size (peer_create, | ||
932 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, | ||
933 | struct GNUNET_TESTBED_PeerCreateMessage, | ||
934 | NULL), | ||
935 | GNUNET_MQ_hd_fixed_size (peer_destroy, | ||
936 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, | ||
937 | struct GNUNET_TESTBED_PeerDestroyMessage, | ||
938 | NULL), | ||
939 | GNUNET_MQ_hd_fixed_size (peer_start, | ||
940 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, | ||
941 | struct GNUNET_TESTBED_PeerStartMessage, | ||
942 | NULL), | ||
943 | GNUNET_MQ_hd_fixed_size (peer_stop, | ||
944 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, | ||
945 | struct GNUNET_TESTBED_PeerStopMessage, | ||
946 | NULL), | ||
947 | GNUNET_MQ_hd_fixed_size (peer_get_config, | ||
948 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, | ||
949 | struct GNUNET_TESTBED_PeerGetConfigurationMessage, | ||
950 | NULL), | ||
951 | GNUNET_MQ_hd_var_size (manage_peer_service, | ||
952 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, | ||
953 | struct GNUNET_TESTBED_ManagePeerServiceMessage, | ||
954 | NULL), | ||
955 | GNUNET_MQ_hd_fixed_size (shutdown_peers, | ||
956 | GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, | ||
957 | struct GNUNET_TESTBED_ShutdownPeersMessage, | ||
958 | NULL), | ||
959 | GNUNET_MQ_hd_var_size (peer_reconfigure, | ||
960 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, | ||
961 | struct GNUNET_TESTBED_PeerReconfigureMessage, | ||
962 | NULL), | ||
963 | GNUNET_MQ_hd_var_size (barrier_init, | ||
964 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, | ||
965 | struct GNUNET_TESTBED_BarrierInit, | ||
966 | NULL), | ||
967 | GNUNET_MQ_hd_var_size (barrier_cancel, | ||
968 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, | ||
969 | struct GNUNET_TESTBED_BarrierCancel, | ||
970 | NULL), | ||
971 | GNUNET_MQ_hd_var_size (barrier_status, | ||
972 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | ||
973 | struct GNUNET_TESTBED_BarrierStatusMsg, | ||
974 | NULL), | ||
975 | GNUNET_MQ_handler_end ()); | ||
976 | |||
957 | 977 | ||
958 | /* end of gnunet-service-testbed.c */ | 978 | /* end of gnunet-service-testbed.c */ |