diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 982 |
1 files changed, 494 insertions, 488 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 26f1a9c26..b34550339 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -96,18 +96,18 @@ static char *hostname; | |||
96 | * already in use | 96 | * already in use |
97 | */ | 97 | */ |
98 | static int | 98 | static int |
99 | host_list_add(struct GNUNET_TESTBED_Host *host) | 99 | host_list_add (struct GNUNET_TESTBED_Host *host) |
100 | { | 100 | { |
101 | uint32_t host_id; | 101 | uint32_t host_id; |
102 | 102 | ||
103 | host_id = GNUNET_TESTBED_host_get_id_(host); | 103 | host_id = GNUNET_TESTBED_host_get_id_ (host); |
104 | if (GST_host_list_size <= host_id) | 104 | if (GST_host_list_size <= host_id) |
105 | GST_array_grow_large_enough(GST_host_list, GST_host_list_size, host_id); | 105 | GST_array_grow_large_enough (GST_host_list, GST_host_list_size, host_id); |
106 | if (NULL != GST_host_list[host_id]) | 106 | if (NULL != GST_host_list[host_id]) |
107 | { | 107 | { |
108 | LOG_DEBUG("A host with id: %u already exists\n", host_id); | 108 | LOG_DEBUG ("A host with id: %u already exists\n", host_id); |
109 | return GNUNET_SYSERR; | 109 | return GNUNET_SYSERR; |
110 | } | 110 | } |
111 | GST_host_list[host_id] = host; | 111 | GST_host_list[host_id] = host; |
112 | return GNUNET_OK; | 112 | return GNUNET_OK; |
113 | } | 113 | } |
@@ -121,25 +121,25 @@ host_list_add(struct GNUNET_TESTBED_Host *host) | |||
121 | * @param emsg the error message; can be NULL | 121 | * @param emsg the error message; can be NULL |
122 | */ | 122 | */ |
123 | void | 123 | void |
124 | GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, | 124 | GST_send_operation_fail_msg (struct GNUNET_SERVICE_Client *client, |
125 | uint64_t operation_id, | 125 | uint64_t operation_id, |
126 | const char *emsg) | 126 | const char *emsg) |
127 | { | 127 | { |
128 | struct GNUNET_MQ_Envelope *env; | 128 | struct GNUNET_MQ_Envelope *env; |
129 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; | 129 | struct GNUNET_TESTBED_OperationFailureEventMessage *msg; |
130 | uint16_t emsg_len; | 130 | uint16_t emsg_len; |
131 | 131 | ||
132 | emsg_len = (NULL == emsg) ? 0 : strlen(emsg) + 1; | 132 | emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; |
133 | env = GNUNET_MQ_msg_extra(msg, | 133 | env = GNUNET_MQ_msg_extra (msg, |
134 | emsg_len, | 134 | emsg_len, |
135 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); | 135 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT); |
136 | msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); | 136 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); |
137 | msg->operation_id = GNUNET_htonll(operation_id); | 137 | msg->operation_id = GNUNET_htonll (operation_id); |
138 | GNUNET_memcpy(&msg[1], | 138 | GNUNET_memcpy (&msg[1], |
139 | emsg, | 139 | emsg, |
140 | emsg_len); | 140 | emsg_len); |
141 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 141 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
142 | env); | 142 | env); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
@@ -150,18 +150,18 @@ GST_send_operation_fail_msg(struct GNUNET_SERVICE_Client *client, | |||
150 | * @param operation_id the id of the operation which was successful | 150 | * @param operation_id the id of the operation which was successful |
151 | */ | 151 | */ |
152 | void | 152 | void |
153 | GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, | 153 | GST_send_operation_success_msg (struct GNUNET_SERVICE_Client *client, |
154 | uint64_t operation_id) | 154 | uint64_t operation_id) |
155 | { | 155 | { |
156 | struct GNUNET_MQ_Envelope *env; | 156 | struct GNUNET_MQ_Envelope *env; |
157 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; | 157 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg; |
158 | 158 | ||
159 | env = GNUNET_MQ_msg(msg, | 159 | env = GNUNET_MQ_msg (msg, |
160 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); | 160 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS); |
161 | msg->operation_id = GNUNET_htonll(operation_id); | 161 | msg->operation_id = GNUNET_htonll (operation_id); |
162 | msg->event_type = htonl(GNUNET_TESTBED_ET_OPERATION_FINISHED); | 162 | msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED); |
163 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 163 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
164 | env); | 164 | env); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -172,8 +172,8 @@ GST_send_operation_success_msg(struct GNUNET_SERVICE_Client *client, | |||
172 | * @param emsg the error message; NULL if host registration is successful | 172 | * @param emsg the error message; NULL if host registration is successful |
173 | */ | 173 | */ |
174 | static void | 174 | static void |
175 | hr_completion(void *cls, | 175 | hr_completion (void *cls, |
176 | const char *emsg); | 176 | const char *emsg); |
177 | 177 | ||
178 | 178 | ||
179 | /** | 179 | /** |
@@ -183,21 +183,21 @@ hr_completion(void *cls, | |||
183 | * for host registrations | 183 | * for host registrations |
184 | */ | 184 | */ |
185 | static void | 185 | static void |
186 | register_next_host(struct Slave *slave) | 186 | register_next_host (struct Slave *slave) |
187 | { | 187 | { |
188 | struct HostRegistration *hr; | 188 | struct HostRegistration *hr; |
189 | 189 | ||
190 | hr = slave->hr_dll_head; | 190 | hr = slave->hr_dll_head; |
191 | GNUNET_assert(NULL != hr); | 191 | GNUNET_assert (NULL != hr); |
192 | GNUNET_assert(NULL == slave->rhandle); | 192 | GNUNET_assert (NULL == slave->rhandle); |
193 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", | 193 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Registering host %u at %u\n", |
194 | GNUNET_TESTBED_host_get_id_(hr->host), | 194 | GNUNET_TESTBED_host_get_id_ (hr->host), |
195 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); | 195 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); |
196 | slave->rhandle | 196 | slave->rhandle |
197 | = GNUNET_TESTBED_register_host(slave->controller, | 197 | = GNUNET_TESTBED_register_host (slave->controller, |
198 | hr->host, | 198 | hr->host, |
199 | hr_completion, | 199 | hr_completion, |
200 | slave); | 200 | slave); |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
@@ -208,28 +208,28 @@ register_next_host(struct Slave *slave) | |||
208 | * @param emsg the error message; NULL if host registration is successful | 208 | * @param emsg the error message; NULL if host registration is successful |
209 | */ | 209 | */ |
210 | static void | 210 | static void |
211 | hr_completion(void *cls, | 211 | hr_completion (void *cls, |
212 | const char *emsg) | 212 | const char *emsg) |
213 | { | 213 | { |
214 | struct Slave *slave = cls; | 214 | struct Slave *slave = cls; |
215 | struct HostRegistration *hr; | 215 | struct HostRegistration *hr; |
216 | 216 | ||
217 | slave->rhandle = NULL; | 217 | slave->rhandle = NULL; |
218 | hr = slave->hr_dll_head; | 218 | hr = slave->hr_dll_head; |
219 | GNUNET_assert(NULL != hr); | 219 | GNUNET_assert (NULL != hr); |
220 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 220 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
221 | "Registering host %u at %u successful\n", | 221 | "Registering host %u at %u successful\n", |
222 | GNUNET_TESTBED_host_get_id_(hr->host), | 222 | GNUNET_TESTBED_host_get_id_ (hr->host), |
223 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); | 223 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); |
224 | GNUNET_CONTAINER_DLL_remove(slave->hr_dll_head, | 224 | GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head, |
225 | slave->hr_dll_tail, | 225 | slave->hr_dll_tail, |
226 | hr); | 226 | hr); |
227 | if (NULL != hr->cb) | 227 | if (NULL != hr->cb) |
228 | hr->cb(hr->cb_cls, | 228 | hr->cb (hr->cb_cls, |
229 | emsg); | 229 | emsg); |
230 | GNUNET_free(hr); | 230 | GNUNET_free (hr); |
231 | if (NULL != slave->hr_dll_head) | 231 | if (NULL != slave->hr_dll_head) |
232 | register_next_host(slave); | 232 | register_next_host (slave); |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
@@ -243,28 +243,28 @@ hr_completion(void *cls, | |||
243 | * @param host the host which has to be registered | 243 | * @param host the host which has to be registered |
244 | */ | 244 | */ |
245 | void | 245 | void |
246 | GST_queue_host_registration(struct Slave *slave, | 246 | GST_queue_host_registration (struct Slave *slave, |
247 | GNUNET_TESTBED_HostRegistrationCompletion cb, | 247 | GNUNET_TESTBED_HostRegistrationCompletion cb, |
248 | void *cb_cls, | 248 | void *cb_cls, |
249 | struct GNUNET_TESTBED_Host *host) | 249 | struct GNUNET_TESTBED_Host *host) |
250 | { | 250 | { |
251 | struct HostRegistration *hr; | 251 | struct HostRegistration *hr; |
252 | int call_register; | 252 | int call_register; |
253 | 253 | ||
254 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 254 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
255 | "Queueing host registration for host %u at %u\n", | 255 | "Queueing host registration for host %u at %u\n", |
256 | GNUNET_TESTBED_host_get_id_(host), | 256 | GNUNET_TESTBED_host_get_id_ (host), |
257 | GNUNET_TESTBED_host_get_id_(GST_host_list[slave->host_id])); | 257 | GNUNET_TESTBED_host_get_id_ (GST_host_list[slave->host_id])); |
258 | hr = GNUNET_new(struct HostRegistration); | 258 | hr = GNUNET_new (struct HostRegistration); |
259 | hr->cb = cb; | 259 | hr->cb = cb; |
260 | hr->cb_cls = cb_cls; | 260 | hr->cb_cls = cb_cls; |
261 | hr->host = host; | 261 | hr->host = host; |
262 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; | 262 | call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO; |
263 | GNUNET_CONTAINER_DLL_insert_tail(slave->hr_dll_head, | 263 | GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head, |
264 | slave->hr_dll_tail, | 264 | slave->hr_dll_tail, |
265 | hr); | 265 | hr); |
266 | if (GNUNET_YES == call_register) | 266 | if (GNUNET_YES == call_register) |
267 | register_next_host(slave); | 267 | register_next_host (slave); |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
@@ -275,23 +275,23 @@ GST_queue_host_registration(struct Slave *slave, | |||
275 | * @param msg the message to relay | 275 | * @param msg the message to relay |
276 | */ | 276 | */ |
277 | void | 277 | void |
278 | GST_forwarded_operation_reply_relay(void *cls, | 278 | GST_forwarded_operation_reply_relay (void *cls, |
279 | const struct GNUNET_MessageHeader *msg) | 279 | const struct GNUNET_MessageHeader *msg) |
280 | { | 280 | { |
281 | struct ForwardedOperationContext *fopc = cls; | 281 | struct ForwardedOperationContext *fopc = cls; |
282 | struct GNUNET_MQ_Envelope *env; | 282 | struct GNUNET_MQ_Envelope *env; |
283 | 283 | ||
284 | LOG_DEBUG("Relaying message with type: %u, size: %u\n", | 284 | LOG_DEBUG ("Relaying message with type: %u, size: %u\n", |
285 | ntohs(msg->type), | 285 | ntohs (msg->type), |
286 | ntohs(msg->size)); | 286 | ntohs (msg->size)); |
287 | env = GNUNET_MQ_msg_copy(msg); | 287 | env = GNUNET_MQ_msg_copy (msg); |
288 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(fopc->client), | 288 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (fopc->client), |
289 | env); | 289 | env); |
290 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | 290 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); |
291 | GNUNET_CONTAINER_DLL_remove(fopcq_head, | 291 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
292 | fopcq_tail, | 292 | fopcq_tail, |
293 | fopc); | 293 | fopc); |
294 | GNUNET_free(fopc); | 294 | GNUNET_free (fopc); |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
@@ -301,21 +301,21 @@ GST_forwarded_operation_reply_relay(void *cls, | |||
301 | * @param cls the ForwardedOperationContext | 301 | * @param cls the ForwardedOperationContext |
302 | */ | 302 | */ |
303 | void | 303 | void |
304 | GST_forwarded_operation_timeout(void *cls) | 304 | GST_forwarded_operation_timeout (void *cls) |
305 | { | 305 | { |
306 | struct ForwardedOperationContext *fopc = cls; | 306 | struct ForwardedOperationContext *fopc = cls; |
307 | 307 | ||
308 | fopc->timeout_task = NULL; | 308 | fopc->timeout_task = NULL; |
309 | GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); | 309 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); |
310 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 310 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
311 | "A forwarded operation has timed out\n"); | 311 | "A forwarded operation has timed out\n"); |
312 | GST_send_operation_fail_msg(fopc->client, | 312 | GST_send_operation_fail_msg (fopc->client, |
313 | fopc->operation_id, | 313 | fopc->operation_id, |
314 | "A forwarded operation has timed out"); | 314 | "A forwarded operation has timed out"); |
315 | GNUNET_CONTAINER_DLL_remove(fopcq_head, | 315 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
316 | fopcq_tail, | 316 | fopcq_tail, |
317 | fopc); | 317 | fopc); |
318 | GNUNET_free(fopc); | 318 | GNUNET_free (fopc); |
319 | } | 319 | } |
320 | 320 | ||
321 | 321 | ||
@@ -329,8 +329,8 @@ GST_forwarded_operation_timeout(void *cls) | |||
329 | * upon empty service sharing specification. | 329 | * upon empty service sharing specification. |
330 | */ | 330 | */ |
331 | static struct GNUNET_TESTING_SharedService * | 331 | static struct GNUNET_TESTING_SharedService * |
332 | parse_shared_services(char *ss_str, | 332 | parse_shared_services (char *ss_str, |
333 | struct GNUNET_CONFIGURATION_Handle *cfg) | 333 | struct GNUNET_CONFIGURATION_Handle *cfg) |
334 | { | 334 | { |
335 | struct GNUNET_TESTING_SharedService ss; | 335 | struct GNUNET_TESTING_SharedService ss; |
336 | struct GNUNET_TESTING_SharedService *slist; | 336 | struct GNUNET_TESTING_SharedService *slist; |
@@ -340,41 +340,41 @@ parse_shared_services(char *ss_str, | |||
340 | 340 | ||
341 | #define GROW_SS \ | 341 | #define GROW_SS \ |
342 | do { \ | 342 | do { \ |
343 | GNUNET_array_grow(slist, n, n + 1); \ | 343 | GNUNET_array_grow (slist, n, n + 1); \ |
344 | GNUNET_memcpy(&slist[n - 1], &ss, \ | 344 | GNUNET_memcpy (&slist[n - 1], &ss, \ |
345 | sizeof(struct GNUNET_TESTING_SharedService)); \ | 345 | sizeof(struct GNUNET_TESTING_SharedService)); \ |
346 | } while (0) | 346 | } while (0) |
347 | 347 | ||
348 | slist = NULL; | 348 | slist = NULL; |
349 | n = 0; | 349 | n = 0; |
350 | ss.cfg = cfg; | 350 | ss.cfg = cfg; |
351 | for (; NULL != (arg = strtok(ss_str, " ")); ss_str = NULL) | 351 | for (; NULL != (arg = strtok (ss_str, " ")); ss_str = NULL) |
352 | { | ||
353 | ss.service = NULL; | ||
354 | ss.share = 0; | ||
355 | if (2 != sscanf (arg, "%255[^:]:%u", | ||
356 | service, | ||
357 | &ss.share)) | ||
352 | { | 358 | { |
353 | ss.service = NULL; | 359 | LOG (GNUNET_ERROR_TYPE_WARNING, |
354 | ss.share = 0; | 360 | "Ignoring shared service spec: %s", |
355 | if (2 != sscanf(arg, "%255[^:]:%u", | 361 | arg); |
356 | service, | 362 | continue; |
357 | &ss.share)) | ||
358 | { | ||
359 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
360 | "Ignoring shared service spec: %s", | ||
361 | arg); | ||
362 | continue; | ||
363 | } | ||
364 | LOG_DEBUG("Will be sharing %s service among %u peers\n", | ||
365 | service, | ||
366 | ss.share); | ||
367 | ss.service = GNUNET_strdup(service); | ||
368 | GROW_SS; | ||
369 | } | 363 | } |
364 | LOG_DEBUG ("Will be sharing %s service among %u peers\n", | ||
365 | service, | ||
366 | ss.share); | ||
367 | ss.service = GNUNET_strdup (service); | ||
368 | GROW_SS; | ||
369 | } | ||
370 | if (NULL != slist) | 370 | if (NULL != slist) |
371 | { | 371 | { |
372 | /* Add trailing NULL block */ | 372 | /* Add trailing NULL block */ |
373 | (void)memset(&ss, | 373 | (void) memset (&ss, |
374 | 0, | 374 | 0, |
375 | sizeof(struct GNUNET_TESTING_SharedService)); | 375 | sizeof(struct GNUNET_TESTING_SharedService)); |
376 | GROW_SS; | 376 | GROW_SS; |
377 | } | 377 | } |
378 | return slist; | 378 | return slist; |
379 | #undef GROW_SS | 379 | #undef GROW_SS |
380 | } | 380 | } |
@@ -388,19 +388,19 @@ parse_shared_services(char *ss_str, | |||
388 | * @return #GNUNET_OK if @a message is well-formed | 388 | * @return #GNUNET_OK if @a message is well-formed |
389 | */ | 389 | */ |
390 | static int | 390 | static int |
391 | check_init(void *cls, | 391 | check_init (void *cls, |
392 | const struct GNUNET_TESTBED_InitMessage *msg) | 392 | const struct GNUNET_TESTBED_InitMessage *msg) |
393 | { | 393 | { |
394 | const char *controller_hostname; | 394 | const char *controller_hostname; |
395 | uint16_t msize; | 395 | uint16_t msize; |
396 | 396 | ||
397 | msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage); | 397 | msize = ntohs (msg->header.size) - sizeof(struct GNUNET_TESTBED_InitMessage); |
398 | controller_hostname = (const char *)&msg[1]; | 398 | controller_hostname = (const char *) &msg[1]; |
399 | if ('\0' != controller_hostname[msize - 1]) | 399 | if ('\0' != controller_hostname[msize - 1]) |
400 | { | 400 | { |
401 | GNUNET_break(0); | 401 | GNUNET_break (0); |
402 | return GNUNET_SYSERR; | 402 | return GNUNET_SYSERR; |
403 | } | 403 | } |
404 | return GNUNET_OK; | 404 | return GNUNET_OK; |
405 | } | 405 | } |
406 | 406 | ||
@@ -412,8 +412,8 @@ check_init(void *cls, | |||
412 | * @param message the actual message | 412 | * @param message the actual message |
413 | */ | 413 | */ |
414 | static void | 414 | static void |
415 | handle_init(void *cls, | 415 | handle_init (void *cls, |
416 | const struct GNUNET_TESTBED_InitMessage *msg) | 416 | const struct GNUNET_TESTBED_InitMessage *msg) |
417 | { | 417 | { |
418 | struct GNUNET_SERVICE_Client *client = cls; | 418 | struct GNUNET_SERVICE_Client *client = cls; |
419 | struct GNUNET_TESTBED_Host *host; | 419 | struct GNUNET_TESTBED_Host *host; |
@@ -423,56 +423,56 @@ handle_init(void *cls, | |||
423 | unsigned int cnt; | 423 | unsigned int cnt; |
424 | 424 | ||
425 | if (NULL != GST_context) | 425 | if (NULL != GST_context) |
426 | { | 426 | { |
427 | LOG_DEBUG("We are being connected to laterally\n"); | 427 | LOG_DEBUG ("We are being connected to laterally\n"); |
428 | GNUNET_SERVICE_client_continue(client); | 428 | GNUNET_SERVICE_client_continue (client); |
429 | return; | 429 | return; |
430 | } | 430 | } |
431 | controller_hostname = (const char *)&msg[1]; | 431 | controller_hostname = (const char *) &msg[1]; |
432 | ss_str = NULL; | 432 | ss_str = NULL; |
433 | ss = NULL; | 433 | ss = NULL; |
434 | if (GNUNET_OK == | 434 | if (GNUNET_OK == |
435 | GNUNET_CONFIGURATION_get_value_string(GST_config, | 435 | GNUNET_CONFIGURATION_get_value_string (GST_config, |
436 | "TESTBED", | 436 | "TESTBED", |
437 | "SHARED_SERVICES", | 437 | "SHARED_SERVICES", |
438 | &ss_str)) | 438 | &ss_str)) |
439 | { | 439 | { |
440 | ss = parse_shared_services(ss_str, | 440 | ss = parse_shared_services (ss_str, |
441 | GST_config); | 441 | GST_config); |
442 | GNUNET_free(ss_str); | 442 | GNUNET_free (ss_str); |
443 | ss_str = NULL; | 443 | ss_str = NULL; |
444 | } | 444 | } |
445 | GST_context = GNUNET_new(struct Context); | 445 | GST_context = GNUNET_new (struct Context); |
446 | GST_context->client = client; | 446 | GST_context->client = client; |
447 | GST_context->host_id = ntohl(msg->host_id); | 447 | GST_context->host_id = ntohl (msg->host_id); |
448 | GST_context->master_ip = GNUNET_strdup(controller_hostname); | 448 | GST_context->master_ip = GNUNET_strdup (controller_hostname); |
449 | LOG_DEBUG("Our IP: %s\n", | 449 | LOG_DEBUG ("Our IP: %s\n", |
450 | GST_context->master_ip); | 450 | GST_context->master_ip); |
451 | GST_context->system | 451 | GST_context->system |
452 | = GNUNET_TESTING_system_create("testbed", | 452 | = GNUNET_TESTING_system_create ("testbed", |
453 | GST_context->master_ip, | 453 | GST_context->master_ip, |
454 | hostname, | 454 | hostname, |
455 | ss); | 455 | ss); |
456 | if (NULL != ss) | 456 | if (NULL != ss) |
457 | { | ||
458 | for (cnt = 0; NULL != ss[cnt].service; cnt++) | ||
457 | { | 459 | { |
458 | for (cnt = 0; NULL != ss[cnt].service; cnt++) | 460 | ss_str = (char *) ss[cnt].service; |
459 | { | 461 | GNUNET_free (ss_str); |
460 | ss_str = (char *)ss[cnt].service; | ||
461 | GNUNET_free(ss_str); | ||
462 | } | ||
463 | GNUNET_free(ss); | ||
464 | ss = NULL; | ||
465 | } | 462 | } |
463 | GNUNET_free (ss); | ||
464 | ss = NULL; | ||
465 | } | ||
466 | host = | 466 | host = |
467 | GNUNET_TESTBED_host_create_with_id(GST_context->host_id, | 467 | GNUNET_TESTBED_host_create_with_id (GST_context->host_id, |
468 | GST_context->master_ip, | 468 | GST_context->master_ip, |
469 | NULL, | 469 | NULL, |
470 | GST_config, | 470 | GST_config, |
471 | 0); | 471 | 0); |
472 | host_list_add(host); | 472 | host_list_add (host); |
473 | LOG_DEBUG("Created master context with host ID: %u\n", | 473 | LOG_DEBUG ("Created master context with host ID: %u\n", |
474 | GST_context->host_id); | 474 | GST_context->host_id); |
475 | GNUNET_SERVICE_client_continue(client); | 475 | GNUNET_SERVICE_client_continue (client); |
476 | } | 476 | } |
477 | 477 | ||
478 | 478 | ||
@@ -484,29 +484,30 @@ handle_init(void *cls, | |||
484 | * @return #GNUNET_OK if @a message is well-formed | 484 | * @return #GNUNET_OK if @a message is well-formed |
485 | */ | 485 | */ |
486 | static int | 486 | static int |
487 | check_add_host(void *cls, | 487 | check_add_host (void *cls, |
488 | const struct GNUNET_TESTBED_AddHostMessage *msg) | 488 | const struct GNUNET_TESTBED_AddHostMessage *msg) |
489 | { | 489 | { |
490 | uint16_t username_length; | 490 | uint16_t username_length; |
491 | uint16_t hostname_length; | 491 | uint16_t hostname_length; |
492 | uint16_t msize; | 492 | uint16_t msize; |
493 | 493 | ||
494 | msize = ntohs(msg->header.size) - sizeof(struct GNUNET_TESTBED_AddHostMessage); | 494 | msize = ntohs (msg->header.size) - sizeof(struct |
495 | username_length = ntohs(msg->username_length); | 495 | GNUNET_TESTBED_AddHostMessage); |
496 | hostname_length = ntohs(msg->hostname_length); | 496 | username_length = ntohs (msg->username_length); |
497 | hostname_length = ntohs (msg->hostname_length); | ||
497 | /* msg must contain hostname */ | 498 | /* msg must contain hostname */ |
498 | if ((msize <= username_length) || | 499 | if ((msize <= username_length) || |
499 | (0 == hostname_length)) | 500 | (0 == hostname_length)) |
500 | { | 501 | { |
501 | GNUNET_break(0); | 502 | GNUNET_break (0); |
502 | return GNUNET_SYSERR; | 503 | return GNUNET_SYSERR; |
503 | } | 504 | } |
504 | /* msg must contain configuration */ | 505 | /* msg must contain configuration */ |
505 | if (msize <= username_length + hostname_length) | 506 | if (msize <= username_length + hostname_length) |
506 | { | 507 | { |
507 | GNUNET_break(0); | 508 | GNUNET_break (0); |
508 | return GNUNET_SYSERR; | 509 | return GNUNET_SYSERR; |
509 | } | 510 | } |
510 | return GNUNET_OK; | 511 | return GNUNET_OK; |
511 | } | 512 | } |
512 | 513 | ||
@@ -518,8 +519,8 @@ check_add_host(void *cls, | |||
518 | * @param msg the actual message | 519 | * @param msg the actual message |
519 | */ | 520 | */ |
520 | static void | 521 | static void |
521 | handle_add_host(void *cls, | 522 | handle_add_host (void *cls, |
522 | const struct GNUNET_TESTBED_AddHostMessage *msg) | 523 | const struct GNUNET_TESTBED_AddHostMessage *msg) |
523 | { | 524 | { |
524 | struct GNUNET_SERVICE_Client *client = cls; | 525 | struct GNUNET_SERVICE_Client *client = cls; |
525 | struct GNUNET_TESTBED_Host *host; | 526 | struct GNUNET_TESTBED_Host *host; |
@@ -534,77 +535,77 @@ handle_add_host(void *cls, | |||
534 | uint16_t hostname_length; | 535 | uint16_t hostname_length; |
535 | struct GNUNET_MQ_Envelope *env; | 536 | struct GNUNET_MQ_Envelope *env; |
536 | 537 | ||
537 | username_length = ntohs(msg->username_length); | 538 | username_length = ntohs (msg->username_length); |
538 | hostname_length = ntohs(msg->hostname_length); | 539 | hostname_length = ntohs (msg->hostname_length); |
539 | username = NULL; | 540 | username = NULL; |
540 | hostname = NULL; | 541 | hostname = NULL; |
541 | ptr = &msg[1]; | 542 | ptr = &msg[1]; |
542 | if (0 != username_length) | 543 | if (0 != username_length) |
543 | { | 544 | { |
544 | username = GNUNET_malloc(username_length + 1); | 545 | username = GNUNET_malloc (username_length + 1); |
545 | GNUNET_strlcpy(username, ptr, username_length + 1); | 546 | GNUNET_strlcpy (username, ptr, username_length + 1); |
546 | ptr += username_length; | 547 | ptr += username_length; |
547 | } | 548 | } |
548 | hostname = GNUNET_malloc(hostname_length + 1); | 549 | hostname = GNUNET_malloc (hostname_length + 1); |
549 | GNUNET_strlcpy(hostname, ptr, hostname_length + 1); | 550 | GNUNET_strlcpy (hostname, ptr, hostname_length + 1); |
550 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_(&msg->header))) | 551 | if (NULL == (host_cfg = GNUNET_TESTBED_extract_config_ (&msg->header))) |
551 | { | 552 | { |
552 | GNUNET_free_non_null(username); | 553 | GNUNET_free_non_null (username); |
553 | GNUNET_free_non_null(hostname); | 554 | GNUNET_free_non_null (hostname); |
554 | GNUNET_break_op(0); | 555 | GNUNET_break_op (0); |
555 | GNUNET_SERVICE_client_drop(client); | 556 | GNUNET_SERVICE_client_drop (client); |
556 | return; | 557 | return; |
557 | } | 558 | } |
558 | host_id = ntohl(msg->host_id); | 559 | host_id = ntohl (msg->host_id); |
559 | LOG_DEBUG("Received ADDHOST %u message\n", host_id); | 560 | LOG_DEBUG ("Received ADDHOST %u message\n", host_id); |
560 | LOG_DEBUG("-------host id: %u\n", host_id); | 561 | LOG_DEBUG ("-------host id: %u\n", host_id); |
561 | LOG_DEBUG("-------hostname: %s\n", hostname); | 562 | LOG_DEBUG ("-------hostname: %s\n", hostname); |
562 | if (NULL != username) | 563 | if (NULL != username) |
563 | LOG_DEBUG("-------username: %s\n", username); | 564 | LOG_DEBUG ("-------username: %s\n", username); |
564 | else | 565 | else |
565 | LOG_DEBUG("-------username: <not given>\n"); | 566 | LOG_DEBUG ("-------username: <not given>\n"); |
566 | LOG_DEBUG("-------ssh port: %u\n", ntohs(msg->ssh_port)); | 567 | LOG_DEBUG ("-------ssh port: %u\n", ntohs (msg->ssh_port)); |
567 | host = GNUNET_TESTBED_host_create_with_id(host_id, | 568 | host = GNUNET_TESTBED_host_create_with_id (host_id, |
568 | hostname, | 569 | hostname, |
569 | username, | 570 | username, |
570 | host_cfg, | 571 | host_cfg, |
571 | ntohs(msg->ssh_port)); | 572 | ntohs (msg->ssh_port)); |
572 | GNUNET_free_non_null(username); | 573 | GNUNET_free_non_null (username); |
573 | GNUNET_free(hostname); | 574 | GNUNET_free (hostname); |
574 | GNUNET_CONFIGURATION_destroy(host_cfg); | 575 | GNUNET_CONFIGURATION_destroy (host_cfg); |
575 | if (NULL == host) | 576 | if (NULL == host) |
576 | { | 577 | { |
577 | GNUNET_break_op(0); | 578 | GNUNET_break_op (0); |
578 | GNUNET_SERVICE_client_drop(client); | 579 | GNUNET_SERVICE_client_drop (client); |
579 | return; | 580 | return; |
580 | } | 581 | } |
581 | if (GNUNET_OK != host_list_add(host)) | 582 | if (GNUNET_OK != host_list_add (host)) |
582 | { | 583 | { |
583 | /* We are unable to add a host */ | 584 | /* We are unable to add a host */ |
584 | emsg = "A host exists with given host-id"; | 585 | emsg = "A host exists with given host-id"; |
585 | LOG_DEBUG("%s: %u", | 586 | LOG_DEBUG ("%s: %u", |
586 | emsg, | 587 | emsg, |
587 | host_id); | 588 | host_id); |
588 | GNUNET_TESTBED_host_destroy(host); | 589 | GNUNET_TESTBED_host_destroy (host); |
589 | env = GNUNET_MQ_msg_extra(reply, | 590 | env = GNUNET_MQ_msg_extra (reply, |
590 | strlen(emsg) + 1, | 591 | strlen (emsg) + 1, |
591 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | 592 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); |
592 | GNUNET_memcpy(&reply[1], | 593 | GNUNET_memcpy (&reply[1], |
593 | emsg, | 594 | emsg, |
594 | strlen(emsg) + 1); | 595 | strlen (emsg) + 1); |
595 | } | 596 | } |
596 | else | 597 | else |
597 | { | 598 | { |
598 | LOG_DEBUG("Added host %u at %u\n", | 599 | LOG_DEBUG ("Added host %u at %u\n", |
599 | host_id, | 600 | host_id, |
600 | GST_context->host_id); | 601 | GST_context->host_id); |
601 | env = GNUNET_MQ_msg(reply, | 602 | env = GNUNET_MQ_msg (reply, |
602 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); | 603 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS); |
603 | } | 604 | } |
604 | reply->host_id = htonl(host_id); | 605 | reply->host_id = htonl (host_id); |
605 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 606 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
606 | env); | 607 | env); |
607 | GNUNET_SERVICE_client_continue(client); | 608 | GNUNET_SERVICE_client_continue (client); |
608 | } | 609 | } |
609 | 610 | ||
610 | 611 | ||
@@ -615,8 +616,9 @@ handle_add_host(void *cls, | |||
615 | * @param msg the actual message | 616 | * @param msg the actual message |
616 | */ | 617 | */ |
617 | static void | 618 | static void |
618 | handle_slave_get_config(void *cls, | 619 | handle_slave_get_config (void *cls, |
619 | const struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) | 620 | const struct |
621 | GNUNET_TESTBED_SlaveGetConfigurationMessage *msg) | ||
620 | { | 622 | { |
621 | struct GNUNET_SERVICE_Client *client = cls; | 623 | struct GNUNET_SERVICE_Client *client = cls; |
622 | struct Slave *slave; | 624 | struct Slave *slave; |
@@ -630,42 +632,45 @@ handle_slave_get_config(void *cls, | |||
630 | uint64_t op_id; | 632 | uint64_t op_id; |
631 | uint32_t slave_id; | 633 | uint32_t slave_id; |
632 | 634 | ||
633 | slave_id = ntohl(msg->slave_id); | 635 | slave_id = ntohl (msg->slave_id); |
634 | op_id = GNUNET_ntohll(msg->operation_id); | 636 | op_id = GNUNET_ntohll (msg->operation_id); |
635 | if ((GST_slave_list_size <= slave_id) || | 637 | if ((GST_slave_list_size <= slave_id) || |
636 | (NULL == GST_slave_list[slave_id])) | 638 | (NULL == GST_slave_list[slave_id])) |
637 | { | 639 | { |
638 | /* FIXME: Add forwardings for this type of message here.. */ | 640 | /* FIXME: Add forwardings for this type of message here.. */ |
639 | GST_send_operation_fail_msg(client, | 641 | GST_send_operation_fail_msg (client, |
640 | op_id, | 642 | op_id, |
641 | "Slave not found"); | 643 | "Slave not found"); |
642 | GNUNET_SERVICE_client_continue(client); | 644 | GNUNET_SERVICE_client_continue (client); |
643 | return; | 645 | return; |
644 | } | 646 | } |
645 | slave = GST_slave_list[slave_id]; | 647 | slave = GST_slave_list[slave_id]; |
646 | GNUNET_assert(NULL != (cfg = GNUNET_TESTBED_host_get_cfg_(GST_host_list[slave->host_id]))); | 648 | GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ ( |
647 | config = GNUNET_CONFIGURATION_serialize(cfg, | 649 | GST_host_list[slave->host_id]))); |
648 | &config_size); | 650 | config = GNUNET_CONFIGURATION_serialize (cfg, |
651 | &config_size); | ||
649 | /* FIXME: maybe we want to transmit the delta to the default here? */ | 652 | /* FIXME: maybe we want to transmit the delta to the default here? */ |
650 | xconfig_size = GNUNET_TESTBED_compress_config_(config, | 653 | xconfig_size = GNUNET_TESTBED_compress_config_ (config, |
651 | config_size, | 654 | config_size, |
652 | &xconfig); | 655 | &xconfig); |
653 | GNUNET_free(config); | 656 | GNUNET_free (config); |
654 | GNUNET_assert(xconfig_size + sizeof(struct GNUNET_TESTBED_SlaveConfiguration) <= UINT16_MAX); | 657 | GNUNET_assert (xconfig_size + sizeof(struct |
655 | GNUNET_assert(xconfig_size <= UINT16_MAX); | 658 | GNUNET_TESTBED_SlaveConfiguration) <= |
656 | env = GNUNET_MQ_msg_extra(reply, | 659 | UINT16_MAX); |
657 | xconfig_size, | 660 | GNUNET_assert (xconfig_size <= UINT16_MAX); |
658 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); | 661 | env = GNUNET_MQ_msg_extra (reply, |
662 | xconfig_size, | ||
663 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION); | ||
659 | reply->slave_id = msg->slave_id; | 664 | reply->slave_id = msg->slave_id; |
660 | reply->operation_id = msg->operation_id; | 665 | reply->operation_id = msg->operation_id; |
661 | reply->config_size = htons((uint16_t)config_size); | 666 | reply->config_size = htons ((uint16_t) config_size); |
662 | GNUNET_memcpy(&reply[1], | 667 | GNUNET_memcpy (&reply[1], |
663 | xconfig, | 668 | xconfig, |
664 | xconfig_size); | 669 | xconfig_size); |
665 | GNUNET_free(xconfig); | 670 | GNUNET_free (xconfig); |
666 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | 671 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
667 | env); | 672 | env); |
668 | GNUNET_SERVICE_client_continue(client); | 673 | GNUNET_SERVICE_client_continue (client); |
669 | } | 674 | } |
670 | 675 | ||
671 | 676 | ||
@@ -673,52 +678,52 @@ handle_slave_get_config(void *cls, | |||
673 | * Clears the forwarded operations queue | 678 | * Clears the forwarded operations queue |
674 | */ | 679 | */ |
675 | void | 680 | void |
676 | GST_clear_fopcq() | 681 | GST_clear_fopcq () |
677 | { | 682 | { |
678 | struct ForwardedOperationContext *fopc; | 683 | struct ForwardedOperationContext *fopc; |
679 | 684 | ||
680 | while (NULL != (fopc = fopcq_head)) | 685 | while (NULL != (fopc = fopcq_head)) |
686 | { | ||
687 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | ||
688 | fopcq_tail, | ||
689 | fopc); | ||
690 | GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc); | ||
691 | if (NULL != fopc->timeout_task) | ||
692 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | ||
693 | switch (fopc->type) | ||
681 | { | 694 | { |
682 | GNUNET_CONTAINER_DLL_remove(fopcq_head, | 695 | case OP_PEER_CREATE: |
683 | fopcq_tail, | 696 | GNUNET_free (fopc->cls); |
684 | fopc); | 697 | break; |
685 | GNUNET_TESTBED_forward_operation_msg_cancel_(fopc->opc); | 698 | |
686 | if (NULL != fopc->timeout_task) | 699 | case OP_SHUTDOWN_PEERS: |
687 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | 700 | { |
688 | switch (fopc->type) | 701 | struct HandlerContext_ShutdownPeers *hc = fopc->cls; |
689 | { | 702 | |
690 | case OP_PEER_CREATE: | 703 | GNUNET_assert (0 < hc->nslaves); |
691 | GNUNET_free(fopc->cls); | 704 | hc->nslaves--; |
692 | break; | 705 | if (0 == hc->nslaves) |
693 | 706 | GNUNET_free (hc); | |
694 | case OP_SHUTDOWN_PEERS: | 707 | } |
695 | { | 708 | break; |
696 | struct HandlerContext_ShutdownPeers *hc = fopc->cls; | 709 | |
697 | 710 | case OP_PEER_START: | |
698 | GNUNET_assert(0 < hc->nslaves); | 711 | case OP_PEER_STOP: |
699 | hc->nslaves--; | 712 | case OP_PEER_DESTROY: |
700 | if (0 == hc->nslaves) | 713 | case OP_PEER_INFO: |
701 | GNUNET_free(hc); | 714 | case OP_OVERLAY_CONNECT: |
702 | } | 715 | case OP_LINK_CONTROLLERS: |
703 | break; | 716 | case OP_GET_SLAVE_CONFIG: |
704 | 717 | case OP_MANAGE_SERVICE: | |
705 | case OP_PEER_START: | 718 | case OP_PEER_RECONFIGURE: |
706 | case OP_PEER_STOP: | 719 | break; |
707 | case OP_PEER_DESTROY: | 720 | |
708 | case OP_PEER_INFO: | 721 | case OP_FORWARDED: |
709 | case OP_OVERLAY_CONNECT: | 722 | GNUNET_assert (0); |
710 | case OP_LINK_CONTROLLERS: | ||
711 | case OP_GET_SLAVE_CONFIG: | ||
712 | case OP_MANAGE_SERVICE: | ||
713 | case OP_PEER_RECONFIGURE: | ||
714 | break; | ||
715 | |||
716 | case OP_FORWARDED: | ||
717 | GNUNET_assert(0); | ||
718 | } | ||
719 | ; | ||
720 | GNUNET_free(fopc); | ||
721 | } | 723 | } |
724 | ; | ||
725 | GNUNET_free (fopc); | ||
726 | } | ||
722 | } | 727 | } |
723 | 728 | ||
724 | 729 | ||
@@ -728,49 +733,49 @@ GST_clear_fopcq() | |||
728 | * @param cls NULL | 733 | * @param cls NULL |
729 | */ | 734 | */ |
730 | static void | 735 | static void |
731 | shutdown_task(void *cls) | 736 | shutdown_task (void *cls) |
732 | { | 737 | { |
733 | uint32_t id; | 738 | uint32_t id; |
734 | 739 | ||
735 | LOG_DEBUG("Shutting down testbed service\n"); | 740 | LOG_DEBUG ("Shutting down testbed service\n"); |
736 | /* cleanup any remaining forwarded operations */ | 741 | /* cleanup any remaining forwarded operations */ |
737 | GST_clear_fopcq(); | 742 | GST_clear_fopcq (); |
738 | GST_free_lcf(); | 743 | GST_free_lcf (); |
739 | GST_free_mctxq(); | 744 | GST_free_mctxq (); |
740 | GST_free_occq(); | 745 | GST_free_occq (); |
741 | GST_free_roccq(); | 746 | GST_free_roccq (); |
742 | GST_free_nccq(); | 747 | GST_free_nccq (); |
743 | GST_neighbour_list_clean(); | 748 | GST_neighbour_list_clean (); |
744 | GST_free_prcq(); | 749 | GST_free_prcq (); |
745 | /* Clear peer list */ | 750 | /* Clear peer list */ |
746 | GST_destroy_peers(); | 751 | GST_destroy_peers (); |
747 | /* Clear route list */ | 752 | /* Clear route list */ |
748 | GST_route_list_clear(); | 753 | GST_route_list_clear (); |
749 | /* Clear GST_slave_list */ | 754 | /* Clear GST_slave_list */ |
750 | GST_slave_list_clear(); | 755 | GST_slave_list_clear (); |
751 | /* Clear host list */ | 756 | /* Clear host list */ |
752 | for (id = 0; id < GST_host_list_size; id++) | 757 | for (id = 0; id < GST_host_list_size; id++) |
753 | if (NULL != GST_host_list[id]) | 758 | if (NULL != GST_host_list[id]) |
754 | GNUNET_TESTBED_host_destroy(GST_host_list[id]); | 759 | GNUNET_TESTBED_host_destroy (GST_host_list[id]); |
755 | GNUNET_free_non_null(GST_host_list); | 760 | GNUNET_free_non_null (GST_host_list); |
756 | if (NULL != GST_context) | 761 | if (NULL != GST_context) |
757 | { | 762 | { |
758 | GNUNET_free_non_null(GST_context->master_ip); | 763 | GNUNET_free_non_null (GST_context->master_ip); |
759 | if (NULL != GST_context->system) | 764 | if (NULL != GST_context->system) |
760 | GNUNET_TESTING_system_destroy(GST_context->system, | 765 | GNUNET_TESTING_system_destroy (GST_context->system, |
761 | GNUNET_YES); | 766 | GNUNET_YES); |
762 | GNUNET_free(GST_context); | 767 | GNUNET_free (GST_context); |
763 | GST_context = NULL; | 768 | GST_context = NULL; |
764 | } | 769 | } |
765 | GNUNET_free_non_null(hostname); | 770 | GNUNET_free_non_null (hostname); |
766 | /* Free hello cache */ | 771 | /* Free hello cache */ |
767 | GST_cache_clear(); | 772 | GST_cache_clear (); |
768 | GST_connection_pool_destroy(); | 773 | GST_connection_pool_destroy (); |
769 | GNUNET_TESTBED_operation_queue_destroy_(GST_opq_openfds); | 774 | GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); |
770 | GST_opq_openfds = NULL; | 775 | GST_opq_openfds = NULL; |
771 | GST_stats_destroy(); | 776 | GST_stats_destroy (); |
772 | GST_barriers_destroy(); | 777 | GST_barriers_destroy (); |
773 | GNUNET_CONFIGURATION_destroy(GST_config); | 778 | GNUNET_CONFIGURATION_destroy (GST_config); |
774 | } | 779 | } |
775 | 780 | ||
776 | 781 | ||
@@ -783,9 +788,9 @@ shutdown_task(void *cls) | |||
783 | * @return @a client | 788 | * @return @a client |
784 | */ | 789 | */ |
785 | static void * | 790 | static void * |
786 | client_connect_cb(void *cls, | 791 | client_connect_cb (void *cls, |
787 | struct GNUNET_SERVICE_Client *client, | 792 | struct GNUNET_SERVICE_Client *client, |
788 | struct GNUNET_MQ_Handle *mq) | 793 | struct GNUNET_MQ_Handle *mq) |
789 | { | 794 | { |
790 | return client; | 795 | return client; |
791 | } | 796 | } |
@@ -799,41 +804,41 @@ client_connect_cb(void *cls, | |||
799 | * @param app_ctx should match @a client | 804 | * @param app_ctx should match @a client |
800 | */ | 805 | */ |
801 | static void | 806 | static void |
802 | client_disconnect_cb(void *cls, | 807 | client_disconnect_cb (void *cls, |
803 | struct GNUNET_SERVICE_Client *client, | 808 | struct GNUNET_SERVICE_Client *client, |
804 | void *app_ctx) | 809 | void *app_ctx) |
805 | { | 810 | { |
806 | struct ForwardedOperationContext *fopc; | 811 | struct ForwardedOperationContext *fopc; |
807 | struct ForwardedOperationContext *fopcn; | 812 | struct ForwardedOperationContext *fopcn; |
808 | 813 | ||
809 | GNUNET_assert(client == app_ctx); | 814 | GNUNET_assert (client == app_ctx); |
810 | GST_notify_client_disconnect_oc(client); | 815 | GST_notify_client_disconnect_oc (client); |
811 | GST_link_notify_disconnect(client); | 816 | GST_link_notify_disconnect (client); |
812 | GST_notify_client_disconnect_peers(client); | 817 | GST_notify_client_disconnect_peers (client); |
813 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | 818 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) |
819 | { | ||
820 | fopcn = fopc->next; | ||
821 | if (fopc->client == client) | ||
814 | { | 822 | { |
815 | fopcn = fopc->next; | 823 | /* handle as if it were a timeout */ |
816 | if (fopc->client == client) | 824 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); |
817 | { | 825 | GST_forwarded_operation_timeout (fopc); |
818 | /* handle as if it were a timeout */ | ||
819 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | ||
820 | GST_forwarded_operation_timeout(fopc); | ||
821 | } | ||
822 | } | 826 | } |
827 | } | ||
823 | if (NULL == GST_context) | 828 | if (NULL == GST_context) |
824 | return; | 829 | return; |
825 | if (client == GST_context->client) | 830 | if (client == GST_context->client) |
826 | { | 831 | { |
827 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 832 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
828 | "Master client disconnected\n"); | 833 | "Master client disconnected\n"); |
829 | GST_context->client = NULL; | 834 | GST_context->client = NULL; |
830 | /* should not be needed as we're terminated by failure to read | 835 | /* should not be needed as we're terminated by failure to read |
831 | * from stdin, but if stdin fails for some reason, this shouldn't | 836 | * from stdin, but if stdin fails for some reason, this shouldn't |
832 | * hurt for now --- might need to revise this later if we ever | 837 | * hurt for now --- might need to revise this later if we ever |
833 | * decide that master connections might be temporarily down | 838 | * decide that master connections might be temporarily down |
834 | * for some reason */ | 839 | * for some reason */ |
835 | //GNUNET_SCHEDULER_shutdown (); | 840 | // GNUNET_SCHEDULER_shutdown (); |
836 | } | 841 | } |
837 | } | 842 | } |
838 | 843 | ||
839 | 844 | ||
@@ -845,54 +850,55 @@ client_disconnect_cb(void *cls, | |||
845 | * @param service the initialized server | 850 | * @param service the initialized server |
846 | */ | 851 | */ |
847 | static void | 852 | static void |
848 | testbed_run(void *cls, | 853 | testbed_run (void *cls, |
849 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 854 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
850 | struct GNUNET_SERVICE_Handle *service) | 855 | struct GNUNET_SERVICE_Handle *service) |
851 | { | 856 | { |
852 | char *logfile; | 857 | char *logfile; |
853 | unsigned long long num; | 858 | unsigned long long num; |
854 | 859 | ||
855 | LOG_DEBUG("Starting testbed\n"); | 860 | LOG_DEBUG ("Starting testbed\n"); |
856 | if (GNUNET_OK == | 861 | if (GNUNET_OK == |
857 | GNUNET_CONFIGURATION_get_value_filename(cfg, "TESTBED", "LOG_FILE", | 862 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED", "LOG_FILE", |
858 | &logfile)) | 863 | &logfile)) |
859 | { | 864 | { |
860 | GNUNET_break(GNUNET_OK == | 865 | GNUNET_break (GNUNET_OK == |
861 | GNUNET_log_setup("testbed", | 866 | GNUNET_log_setup ("testbed", |
862 | "DEBUG", | 867 | "DEBUG", |
863 | logfile)); | 868 | logfile)); |
864 | GNUNET_free(logfile); | 869 | GNUNET_free (logfile); |
865 | } | 870 | } |
866 | GNUNET_assert(GNUNET_OK == | 871 | GNUNET_assert (GNUNET_OK == |
867 | GNUNET_CONFIGURATION_get_value_number(cfg, | 872 | GNUNET_CONFIGURATION_get_value_number (cfg, |
868 | "testbed", | 873 | "testbed", |
869 | "CACHE_SIZE", | 874 | "CACHE_SIZE", |
870 | &num)); | 875 | &num)); |
871 | GST_cache_init((unsigned int)num); | 876 | GST_cache_init ((unsigned int) num); |
872 | GST_connection_pool_init((unsigned int)num); | 877 | GST_connection_pool_init ((unsigned int) num); |
873 | GNUNET_assert(GNUNET_OK == | 878 | GNUNET_assert (GNUNET_OK == |
874 | GNUNET_CONFIGURATION_get_value_number(cfg, | 879 | GNUNET_CONFIGURATION_get_value_number (cfg, |
875 | "testbed", | 880 | "testbed", |
876 | "MAX_OPEN_FDS", | 881 | "MAX_OPEN_FDS", |
877 | &num)); | 882 | &num)); |
878 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_(OPERATION_QUEUE_TYPE_FIXED, | 883 | GST_opq_openfds = GNUNET_TESTBED_operation_queue_create_ ( |
879 | (unsigned int)num); | 884 | OPERATION_QUEUE_TYPE_FIXED, |
880 | GNUNET_assert(GNUNET_OK == | 885 | (unsigned int) num); |
881 | GNUNET_CONFIGURATION_get_value_time(cfg, | 886 | GNUNET_assert (GNUNET_OK == |
882 | "testbed", | 887 | GNUNET_CONFIGURATION_get_value_time (cfg, |
883 | "OPERATION_TIMEOUT", | ||
884 | &GST_timeout)); | ||
885 | GNUNET_assert(GNUNET_OK == | ||
886 | GNUNET_CONFIGURATION_get_value_string(cfg, | ||
887 | "testbed", | 888 | "testbed", |
888 | "HOSTNAME", | 889 | "OPERATION_TIMEOUT", |
889 | &hostname)); | 890 | &GST_timeout)); |
890 | GST_config = GNUNET_CONFIGURATION_dup(cfg); | 891 | GNUNET_assert (GNUNET_OK == |
891 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 892 | GNUNET_CONFIGURATION_get_value_string (cfg, |
892 | NULL); | 893 | "testbed", |
893 | LOG_DEBUG("Testbed startup complete\n"); | 894 | "HOSTNAME", |
894 | GST_stats_init(GST_config); | 895 | &hostname)); |
895 | GST_barriers_init(GST_config); | 896 | GST_config = GNUNET_CONFIGURATION_dup (cfg); |
897 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
898 | NULL); | ||
899 | LOG_DEBUG ("Testbed startup complete\n"); | ||
900 | GST_stats_init (GST_config); | ||
901 | GST_barriers_init (GST_config); | ||
896 | } | 902 | } |
897 | 903 | ||
898 | 904 | ||
@@ -906,75 +912,75 @@ GNUNET_SERVICE_MAIN | |||
906 | &client_connect_cb, | 912 | &client_connect_cb, |
907 | &client_disconnect_cb, | 913 | &client_disconnect_cb, |
908 | NULL, | 914 | NULL, |
909 | GNUNET_MQ_hd_var_size(init, | 915 | GNUNET_MQ_hd_var_size (init, |
910 | GNUNET_MESSAGE_TYPE_TESTBED_INIT, | 916 | GNUNET_MESSAGE_TYPE_TESTBED_INIT, |
911 | struct GNUNET_TESTBED_InitMessage, | 917 | struct GNUNET_TESTBED_InitMessage, |
912 | NULL), | 918 | NULL), |
913 | GNUNET_MQ_hd_var_size(add_host, | 919 | GNUNET_MQ_hd_var_size (add_host, |
914 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, | 920 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST, |
915 | struct GNUNET_TESTBED_AddHostMessage, | 921 | struct GNUNET_TESTBED_AddHostMessage, |
916 | NULL), | 922 | NULL), |
917 | GNUNET_MQ_hd_fixed_size(slave_get_config, | 923 | GNUNET_MQ_hd_fixed_size (slave_get_config, |
918 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, | 924 | GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION, |
919 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage, | 925 | struct GNUNET_TESTBED_SlaveGetConfigurationMessage, |
920 | NULL), | 926 | NULL), |
921 | GNUNET_MQ_hd_fixed_size(link_controllers, | 927 | GNUNET_MQ_hd_fixed_size (link_controllers, |
922 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 928 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, |
923 | struct GNUNET_TESTBED_ControllerLinkRequest, | 929 | struct GNUNET_TESTBED_ControllerLinkRequest, |
924 | NULL), | 930 | NULL), |
925 | GNUNET_MQ_hd_var_size(remote_overlay_connect, | 931 | GNUNET_MQ_hd_var_size (remote_overlay_connect, |
926 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, | 932 | GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT, |
927 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage, | 933 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage, |
928 | NULL), | 934 | NULL), |
929 | GNUNET_MQ_hd_fixed_size(overlay_connect, | 935 | GNUNET_MQ_hd_fixed_size (overlay_connect, |
930 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, | 936 | GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT, |
931 | struct GNUNET_TESTBED_OverlayConnectMessage, | 937 | struct GNUNET_TESTBED_OverlayConnectMessage, |
932 | NULL), | 938 | NULL), |
933 | GNUNET_MQ_hd_var_size(peer_create, | 939 | GNUNET_MQ_hd_var_size (peer_create, |
934 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, | 940 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER, |
935 | struct GNUNET_TESTBED_PeerCreateMessage, | 941 | struct GNUNET_TESTBED_PeerCreateMessage, |
936 | NULL), | 942 | NULL), |
937 | GNUNET_MQ_hd_fixed_size(peer_destroy, | 943 | GNUNET_MQ_hd_fixed_size (peer_destroy, |
938 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, | 944 | GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER, |
939 | struct GNUNET_TESTBED_PeerDestroyMessage, | 945 | struct GNUNET_TESTBED_PeerDestroyMessage, |
940 | NULL), | 946 | NULL), |
941 | GNUNET_MQ_hd_fixed_size(peer_start, | 947 | GNUNET_MQ_hd_fixed_size (peer_start, |
942 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, | 948 | GNUNET_MESSAGE_TYPE_TESTBED_START_PEER, |
943 | struct GNUNET_TESTBED_PeerStartMessage, | 949 | struct GNUNET_TESTBED_PeerStartMessage, |
944 | NULL), | 950 | NULL), |
945 | GNUNET_MQ_hd_fixed_size(peer_stop, | 951 | GNUNET_MQ_hd_fixed_size (peer_stop, |
946 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, | 952 | GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER, |
947 | struct GNUNET_TESTBED_PeerStopMessage, | 953 | struct GNUNET_TESTBED_PeerStopMessage, |
948 | NULL), | 954 | NULL), |
949 | GNUNET_MQ_hd_fixed_size(peer_get_config, | 955 | GNUNET_MQ_hd_fixed_size (peer_get_config, |
950 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, | 956 | GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION, |
951 | struct GNUNET_TESTBED_PeerGetConfigurationMessage, | 957 | struct GNUNET_TESTBED_PeerGetConfigurationMessage, |
952 | NULL), | 958 | NULL), |
953 | GNUNET_MQ_hd_var_size(manage_peer_service, | 959 | GNUNET_MQ_hd_var_size (manage_peer_service, |
954 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, | 960 | GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE, |
955 | struct GNUNET_TESTBED_ManagePeerServiceMessage, | 961 | struct GNUNET_TESTBED_ManagePeerServiceMessage, |
956 | NULL), | 962 | NULL), |
957 | GNUNET_MQ_hd_fixed_size(shutdown_peers, | 963 | GNUNET_MQ_hd_fixed_size (shutdown_peers, |
958 | GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, | 964 | GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS, |
959 | struct GNUNET_TESTBED_ShutdownPeersMessage, | 965 | struct GNUNET_TESTBED_ShutdownPeersMessage, |
960 | NULL), | 966 | NULL), |
961 | GNUNET_MQ_hd_var_size(peer_reconfigure, | 967 | GNUNET_MQ_hd_var_size (peer_reconfigure, |
962 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, | 968 | GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER, |
963 | struct GNUNET_TESTBED_PeerReconfigureMessage, | 969 | struct GNUNET_TESTBED_PeerReconfigureMessage, |
964 | NULL), | 970 | NULL), |
965 | GNUNET_MQ_hd_var_size(barrier_init, | 971 | GNUNET_MQ_hd_var_size (barrier_init, |
966 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, | 972 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_INIT, |
967 | struct GNUNET_TESTBED_BarrierInit, | 973 | struct GNUNET_TESTBED_BarrierInit, |
968 | NULL), | 974 | NULL), |
969 | GNUNET_MQ_hd_var_size(barrier_cancel, | 975 | GNUNET_MQ_hd_var_size (barrier_cancel, |
970 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, | 976 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL, |
971 | struct GNUNET_TESTBED_BarrierCancel, | 977 | struct GNUNET_TESTBED_BarrierCancel, |
972 | NULL), | 978 | NULL), |
973 | GNUNET_MQ_hd_var_size(barrier_status, | 979 | GNUNET_MQ_hd_var_size (barrier_status, |
974 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 980 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, |
975 | struct GNUNET_TESTBED_BarrierStatusMsg, | 981 | struct GNUNET_TESTBED_BarrierStatusMsg, |
976 | NULL), | 982 | NULL), |
977 | GNUNET_MQ_handler_end()); | 983 | GNUNET_MQ_handler_end ()); |
978 | 984 | ||
979 | 985 | ||
980 | /* end of gnunet-service-testbed.c */ | 986 | /* end of gnunet-service-testbed.c */ |