diff options
Diffstat (limited to 'src/transport/transport-testing2.c')
-rw-r--r-- | src/transport/transport-testing2.c | 445 |
1 files changed, 224 insertions, 221 deletions
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 6a86f9b84..7204d26da 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -35,13 +35,14 @@ | |||
35 | #include "transport.h" | 35 | #include "transport.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-testing2", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__) |
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * @brief Handle to a transport communicator | 42 | * @brief Handle to a transport communicator |
43 | */ | 43 | */ |
44 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle { | 44 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
45 | { | ||
45 | /** | 46 | /** |
46 | * @brief Handle to the configuration | 47 | * @brief Handle to the configuration |
47 | */ | 48 | */ |
@@ -145,7 +146,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle { | |||
145 | /** | 146 | /** |
146 | * @brief Queue of a communicator and some context | 147 | * @brief Queue of a communicator and some context |
147 | */ | 148 | */ |
148 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue { | 149 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue |
150 | { | ||
149 | /** | 151 | /** |
150 | * @brief Handle to the TransportCommunicator | 152 | * @brief Handle to the TransportCommunicator |
151 | */ | 153 | */ |
@@ -205,7 +207,8 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue { | |||
205 | /** | 207 | /** |
206 | * @brief Handle/Context to a single transmission | 208 | * @brief Handle/Context to a single transmission |
207 | */ | 209 | */ |
208 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission { | 210 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission |
211 | { | ||
209 | }; | 212 | }; |
210 | 213 | ||
211 | 214 | ||
@@ -219,16 +222,16 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission { | |||
219 | * @return GNUNET_YES in case message is correct | 222 | * @return GNUNET_YES in case message is correct |
220 | */ | 223 | */ |
221 | static int | 224 | static int |
222 | check_communicator_available( | 225 | check_communicator_available ( |
223 | void *cls, | 226 | void *cls, |
224 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | 227 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) |
225 | { | 228 | { |
226 | uint16_t size; | 229 | uint16_t size; |
227 | 230 | ||
228 | size = ntohs(msg->header.size) - sizeof(*msg); | 231 | size = ntohs (msg->header.size) - sizeof(*msg); |
229 | if (0 == size) | 232 | if (0 == size) |
230 | return GNUNET_OK; /* receive-only communicator */ | 233 | return GNUNET_OK; /* receive-only communicator */ |
231 | GNUNET_MQ_check_zero_termination(msg); | 234 | GNUNET_MQ_check_zero_termination (msg); |
232 | return GNUNET_OK; | 235 | return GNUNET_OK; |
233 | } | 236 | } |
234 | 237 | ||
@@ -242,27 +245,27 @@ check_communicator_available( | |||
242 | * @param msg Message struct | 245 | * @param msg Message struct |
243 | */ | 246 | */ |
244 | static void | 247 | static void |
245 | handle_communicator_available( | 248 | handle_communicator_available ( |
246 | void *cls, | 249 | void *cls, |
247 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | 250 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) |
248 | { | 251 | { |
249 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 252 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
250 | uint16_t size; | 253 | uint16_t size; |
251 | 254 | ||
252 | size = ntohs(msg->header.size) - sizeof(*msg); | 255 | size = ntohs (msg->header.size) - sizeof(*msg); |
253 | if (0 == size) | 256 | if (0 == size) |
254 | return; /* receive-only communicator */ | 257 | return; /* receive-only communicator */ |
255 | tc_h->c_characteristics = ntohl(msg->cc); | 258 | tc_h->c_characteristics = ntohl (msg->cc); |
256 | tc_h->c_addr_prefix = GNUNET_strdup((const char *)&msg[1]); | 259 | tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]); |
257 | if (NULL != tc_h->communicator_available_cb) | 260 | if (NULL != tc_h->communicator_available_cb) |
258 | { | 261 | { |
259 | LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); | 262 | LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); |
260 | tc_h->communicator_available_cb(tc_h->cb_cls, | 263 | tc_h->communicator_available_cb (tc_h->cb_cls, |
261 | tc_h, | 264 | tc_h, |
262 | tc_h->c_characteristics, | 265 | tc_h->c_characteristics, |
263 | tc_h->c_addr_prefix); | 266 | tc_h->c_addr_prefix); |
264 | } | 267 | } |
265 | GNUNET_SERVICE_client_continue(tc_h->client); | 268 | GNUNET_SERVICE_client_continue (tc_h->client); |
266 | } | 269 | } |
267 | 270 | ||
268 | 271 | ||
@@ -274,17 +277,17 @@ handle_communicator_available( | |||
274 | * @return #GNUNET_OK if message is well-formed | 277 | * @return #GNUNET_OK if message is well-formed |
275 | */ | 278 | */ |
276 | static int | 279 | static int |
277 | check_add_address(void *cls, | 280 | check_add_address (void *cls, |
278 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) | 281 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) |
279 | { | 282 | { |
280 | struct TransportClient *tc = cls; | 283 | struct TransportClient *tc = cls; |
281 | 284 | ||
282 | //if (CT_COMMUNICATOR != tc->type) | 285 | // if (CT_COMMUNICATOR != tc->type) |
283 | //{ | 286 | // { |
284 | // GNUNET_break (0); | 287 | // GNUNET_break (0); |
285 | // return GNUNET_SYSERR; | 288 | // return GNUNET_SYSERR; |
286 | //} | 289 | // } |
287 | GNUNET_MQ_check_zero_termination(msg); | 290 | GNUNET_MQ_check_zero_termination (msg); |
288 | return GNUNET_OK; | 291 | return GNUNET_OK; |
289 | } | 292 | } |
290 | 293 | ||
@@ -298,27 +301,27 @@ check_add_address(void *cls, | |||
298 | * @param msg Message | 301 | * @param msg Message |
299 | */ | 302 | */ |
300 | static void | 303 | static void |
301 | handle_add_address(void *cls, | 304 | handle_add_address (void *cls, |
302 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) | 305 | const struct GNUNET_TRANSPORT_AddAddressMessage *msg) |
303 | { | 306 | { |
304 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 307 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
305 | uint16_t size; | 308 | uint16_t size; |
306 | 309 | ||
307 | size = ntohs(msg->header.size) - sizeof(*msg); | 310 | size = ntohs (msg->header.size) - sizeof(*msg); |
308 | if (0 == size) | 311 | if (0 == size) |
309 | return; /* receive-only communicator */ | 312 | return; /* receive-only communicator */ |
310 | tc_h->c_address = GNUNET_strdup((const char *)&msg[1]); | 313 | tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]); |
311 | if (NULL != tc_h->add_address_cb) | 314 | if (NULL != tc_h->add_address_cb) |
312 | { | 315 | { |
313 | LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); | 316 | LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); |
314 | tc_h->add_address_cb(tc_h->cb_cls, | 317 | tc_h->add_address_cb (tc_h->cb_cls, |
315 | tc_h, | 318 | tc_h, |
316 | tc_h->c_address, | 319 | tc_h->c_address, |
317 | GNUNET_TIME_relative_ntoh(msg->expiration), | 320 | GNUNET_TIME_relative_ntoh (msg->expiration), |
318 | msg->aid, | 321 | msg->aid, |
319 | ntohl(msg->nt)); | 322 | ntohl (msg->nt)); |
320 | } | 323 | } |
321 | GNUNET_SERVICE_client_continue(tc_h->client); | 324 | GNUNET_SERVICE_client_continue (tc_h->client); |
322 | } | 325 | } |
323 | 326 | ||
324 | 327 | ||
@@ -330,17 +333,17 @@ handle_add_address(void *cls, | |||
330 | * @return #GNUNET_OK if message is well-formed | 333 | * @return #GNUNET_OK if message is well-formed |
331 | */ | 334 | */ |
332 | static int | 335 | static int |
333 | check_incoming_msg(void *cls, | 336 | check_incoming_msg (void *cls, |
334 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | 337 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) |
335 | { | 338 | { |
336 | //struct TransportClient *tc = cls; | 339 | // struct TransportClient *tc = cls; |
337 | 340 | ||
338 | //if (CT_COMMUNICATOR != tc->type) | 341 | // if (CT_COMMUNICATOR != tc->type) |
339 | //{ | 342 | // { |
340 | // GNUNET_break (0); | 343 | // GNUNET_break (0); |
341 | // return GNUNET_SYSERR; | 344 | // return GNUNET_SYSERR; |
342 | //} | 345 | // } |
343 | GNUNET_MQ_check_boxed_message(msg); | 346 | GNUNET_MQ_check_boxed_message (msg); |
344 | return GNUNET_OK; | 347 | return GNUNET_OK; |
345 | } | 348 | } |
346 | 349 | ||
@@ -354,23 +357,23 @@ check_incoming_msg(void *cls, | |||
354 | * @param msg Message | 357 | * @param msg Message |
355 | */ | 358 | */ |
356 | static void | 359 | static void |
357 | handle_incoming_msg(void *cls, | 360 | handle_incoming_msg (void *cls, |
358 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) | 361 | const struct GNUNET_TRANSPORT_IncomingMessage *msg) |
359 | { | 362 | { |
360 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 363 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
361 | 364 | ||
362 | if (NULL != tc_h->incoming_msg_cb) | 365 | if (NULL != tc_h->incoming_msg_cb) |
363 | { | 366 | { |
364 | tc_h->incoming_msg_cb(tc_h->cb_cls, | 367 | tc_h->incoming_msg_cb (tc_h->cb_cls, |
365 | tc_h, | 368 | tc_h, |
366 | (const struct GNUNET_MessageHeader *)msg); | 369 | (const struct GNUNET_MessageHeader *) msg); |
367 | } | 370 | } |
368 | else | 371 | else |
369 | { | 372 | { |
370 | LOG(GNUNET_ERROR_TYPE_WARNING, | 373 | LOG (GNUNET_ERROR_TYPE_WARNING, |
371 | "Incoming message from communicator but no handler!\n"); | 374 | "Incoming message from communicator but no handler!\n"); |
372 | } | 375 | } |
373 | GNUNET_SERVICE_client_continue(tc_h->client); | 376 | GNUNET_SERVICE_client_continue (tc_h->client); |
374 | } | 377 | } |
375 | 378 | ||
376 | 379 | ||
@@ -381,16 +384,16 @@ handle_incoming_msg(void *cls, | |||
381 | * @param msg Message | 384 | * @param msg Message |
382 | */ | 385 | */ |
383 | static void | 386 | static void |
384 | handle_queue_create_ok(void *cls, | 387 | handle_queue_create_ok (void *cls, |
385 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) | 388 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) |
386 | { | 389 | { |
387 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 390 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
388 | 391 | ||
389 | if (NULL != tc_h->queue_create_reply_cb) | 392 | if (NULL != tc_h->queue_create_reply_cb) |
390 | { | 393 | { |
391 | tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_YES); | 394 | tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES); |
392 | } | 395 | } |
393 | GNUNET_SERVICE_client_continue(tc_h->client); | 396 | GNUNET_SERVICE_client_continue (tc_h->client); |
394 | } | 397 | } |
395 | 398 | ||
396 | 399 | ||
@@ -404,17 +407,17 @@ handle_queue_create_ok(void *cls, | |||
404 | * @param msg Message | 407 | * @param msg Message |
405 | */ | 408 | */ |
406 | static void | 409 | static void |
407 | handle_queue_create_fail( | 410 | handle_queue_create_fail ( |
408 | void *cls, | 411 | void *cls, |
409 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) | 412 | const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) |
410 | { | 413 | { |
411 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 414 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
412 | 415 | ||
413 | if (NULL != tc_h->queue_create_reply_cb) | 416 | if (NULL != tc_h->queue_create_reply_cb) |
414 | { | 417 | { |
415 | tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_NO); | 418 | tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO); |
416 | } | 419 | } |
417 | GNUNET_SERVICE_client_continue(tc_h->client); | 420 | GNUNET_SERVICE_client_continue (tc_h->client); |
418 | } | 421 | } |
419 | 422 | ||
420 | 423 | ||
@@ -425,10 +428,10 @@ handle_queue_create_fail( | |||
425 | * @param aqm the send message that was sent | 428 | * @param aqm the send message that was sent |
426 | */ | 429 | */ |
427 | static int | 430 | static int |
428 | check_add_queue_message(void *cls, | 431 | check_add_queue_message (void *cls, |
429 | const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) | 432 | const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) |
430 | { | 433 | { |
431 | GNUNET_MQ_check_zero_termination(aqm); | 434 | GNUNET_MQ_check_zero_termination (aqm); |
432 | return GNUNET_OK; | 435 | return GNUNET_OK; |
433 | } | 436 | } |
434 | 437 | ||
@@ -442,27 +445,27 @@ check_add_queue_message(void *cls, | |||
442 | * @param msg Message struct | 445 | * @param msg Message struct |
443 | */ | 446 | */ |
444 | static void | 447 | static void |
445 | handle_add_queue_message(void *cls, | 448 | handle_add_queue_message (void *cls, |
446 | const struct GNUNET_TRANSPORT_AddQueueMessage *msg) | 449 | const struct GNUNET_TRANSPORT_AddQueueMessage *msg) |
447 | { | 450 | { |
448 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 451 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
449 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; | 452 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; |
450 | 453 | ||
451 | tc_queue = tc_h->queue_head; | 454 | tc_queue = tc_h->queue_head; |
452 | while (tc_queue->qid != msg->qid) | 455 | while (tc_queue->qid != msg->qid) |
453 | { | 456 | { |
454 | tc_queue = tc_queue->next; | 457 | tc_queue = tc_queue->next; |
455 | } | 458 | } |
456 | GNUNET_assert(tc_queue->qid == msg->qid); | 459 | GNUNET_assert (tc_queue->qid == msg->qid); |
457 | GNUNET_assert(0 == GNUNET_memcmp(&tc_queue->peer_id, &msg->receiver)); | 460 | GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); |
458 | tc_queue->nt = msg->nt; | 461 | tc_queue->nt = msg->nt; |
459 | tc_queue->mtu = msg->mtu; | 462 | tc_queue->mtu = msg->mtu; |
460 | tc_queue->cs = msg->cs; | 463 | tc_queue->cs = msg->cs; |
461 | if (NULL != tc_h->add_queue_cb) | 464 | if (NULL != tc_h->add_queue_cb) |
462 | { | 465 | { |
463 | tc_h->add_queue_cb(tc_h->cb_cls, tc_h, tc_queue); | 466 | tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue); |
464 | } | 467 | } |
465 | GNUNET_SERVICE_client_continue(tc_h->client); | 468 | GNUNET_SERVICE_client_continue (tc_h->client); |
466 | } | 469 | } |
467 | 470 | ||
468 | 471 | ||
@@ -472,11 +475,11 @@ handle_add_queue_message(void *cls, | |||
472 | * @param cls Closure - Handle to the service | 475 | * @param cls Closure - Handle to the service |
473 | */ | 476 | */ |
474 | static void | 477 | static void |
475 | shutdown_service(void *cls) | 478 | shutdown_service (void *cls) |
476 | { | 479 | { |
477 | struct GNUNET_SERVICE_Handle *h = cls; | 480 | struct GNUNET_SERVICE_Handle *h = cls; |
478 | 481 | ||
479 | GNUNET_SERVICE_stop(h); | 482 | GNUNET_SERVICE_stop (h); |
480 | } | 483 | } |
481 | 484 | ||
482 | 485 | ||
@@ -490,14 +493,14 @@ shutdown_service(void *cls) | |||
490 | * @return TransportCommunicator Handle | 493 | * @return TransportCommunicator Handle |
491 | */ | 494 | */ |
492 | static void * | 495 | static void * |
493 | connect_cb(void *cls, | 496 | connect_cb (void *cls, |
494 | struct GNUNET_SERVICE_Client *client, | 497 | struct GNUNET_SERVICE_Client *client, |
495 | struct GNUNET_MQ_Handle *mq) | 498 | struct GNUNET_MQ_Handle *mq) |
496 | { | 499 | { |
497 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 500 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
498 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; | 501 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; |
499 | 502 | ||
500 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); | 503 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); |
501 | tc_h->client = client; | 504 | tc_h->client = client; |
502 | tc_h->c_mq = mq; | 505 | tc_h->c_mq = mq; |
503 | 506 | ||
@@ -505,14 +508,14 @@ connect_cb(void *cls, | |||
505 | return tc_h; | 508 | return tc_h; |
506 | /* Iterate over queues. They are yet to be opened. Request opening. */ | 509 | /* Iterate over queues. They are yet to be opened. Request opening. */ |
507 | while (NULL != (tc_queue_iter = tc_h->queue_head)) | 510 | while (NULL != (tc_queue_iter = tc_h->queue_head)) |
508 | { | 511 | { |
509 | if (NULL == tc_queue_iter->open_queue_env) | 512 | if (NULL == tc_queue_iter->open_queue_env) |
510 | continue; | 513 | continue; |
511 | /* Send the previously created mq envelope to request the creation of the | 514 | /* Send the previously created mq envelope to request the creation of the |
512 | * queue. */ | 515 | * queue. */ |
513 | GNUNET_MQ_send(tc_h->c_mq, tc_queue_iter->open_queue_env); | 516 | GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); |
514 | tc_queue_iter->open_queue_env = NULL; | 517 | tc_queue_iter->open_queue_env = NULL; |
515 | } | 518 | } |
516 | return tc_h; | 519 | return tc_h; |
517 | } | 520 | } |
518 | 521 | ||
@@ -525,13 +528,13 @@ connect_cb(void *cls, | |||
525 | * @param internal_cls TransporCommmunicator Handle | 528 | * @param internal_cls TransporCommmunicator Handle |
526 | */ | 529 | */ |
527 | static void | 530 | static void |
528 | disconnect_cb(void *cls, | 531 | disconnect_cb (void *cls, |
529 | struct GNUNET_SERVICE_Client *client, | 532 | struct GNUNET_SERVICE_Client *client, |
530 | void *internal_cls) | 533 | void *internal_cls) |
531 | { | 534 | { |
532 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 535 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
533 | 536 | ||
534 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); | 537 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); |
535 | tc_h->client = NULL; | 538 | tc_h->client = NULL; |
536 | } | 539 | } |
537 | 540 | ||
@@ -544,66 +547,66 @@ disconnect_cb(void *cls, | |||
544 | * @param cfg Configuration | 547 | * @param cfg Configuration |
545 | */ | 548 | */ |
546 | static void | 549 | static void |
547 | transport_communicator_start( | 550 | transport_communicator_start ( |
548 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | 551 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) |
549 | { | 552 | { |
550 | struct GNUNET_MQ_MessageHandler mh[] = { | 553 | struct GNUNET_MQ_MessageHandler mh[] = { |
551 | GNUNET_MQ_hd_var_size(communicator_available, | 554 | GNUNET_MQ_hd_var_size (communicator_available, |
552 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, | 555 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, |
553 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, | 556 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, |
554 | &tc_h), | 557 | &tc_h), |
555 | //GNUNET_MQ_hd_var_size (communicator_backchannel, | 558 | // GNUNET_MQ_hd_var_size (communicator_backchannel, |
556 | // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, | 559 | // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, |
557 | // struct GNUNET_TRANSPORT_CommunicatorBackchannel, | 560 | // struct GNUNET_TRANSPORT_CommunicatorBackchannel, |
558 | // NULL), | 561 | // NULL), |
559 | GNUNET_MQ_hd_var_size(add_address, | 562 | GNUNET_MQ_hd_var_size (add_address, |
560 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, | 563 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, |
561 | struct GNUNET_TRANSPORT_AddAddressMessage, | 564 | struct GNUNET_TRANSPORT_AddAddressMessage, |
562 | &tc_h), | 565 | &tc_h), |
563 | //GNUNET_MQ_hd_fixed_size (del_address, | 566 | // GNUNET_MQ_hd_fixed_size (del_address, |
564 | // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, | 567 | // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, |
565 | // struct GNUNET_TRANSPORT_DelAddressMessage, | 568 | // struct GNUNET_TRANSPORT_DelAddressMessage, |
566 | // NULL), | 569 | // NULL), |
567 | GNUNET_MQ_hd_var_size(incoming_msg, | 570 | GNUNET_MQ_hd_var_size (incoming_msg, |
568 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, | 571 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, |
569 | struct GNUNET_TRANSPORT_IncomingMessage, | 572 | struct GNUNET_TRANSPORT_IncomingMessage, |
570 | NULL), | 573 | NULL), |
571 | GNUNET_MQ_hd_fixed_size(queue_create_ok, | 574 | GNUNET_MQ_hd_fixed_size (queue_create_ok, |
572 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, | 575 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, |
573 | struct GNUNET_TRANSPORT_CreateQueueResponse, | 576 | struct GNUNET_TRANSPORT_CreateQueueResponse, |
574 | tc_h), | 577 | tc_h), |
575 | GNUNET_MQ_hd_fixed_size(queue_create_fail, | 578 | GNUNET_MQ_hd_fixed_size (queue_create_fail, |
576 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, | 579 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, |
577 | struct GNUNET_TRANSPORT_CreateQueueResponse, | 580 | struct GNUNET_TRANSPORT_CreateQueueResponse, |
578 | tc_h), | 581 | tc_h), |
579 | GNUNET_MQ_hd_var_size(add_queue_message, | 582 | GNUNET_MQ_hd_var_size (add_queue_message, |
580 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, | 583 | GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, |
581 | struct GNUNET_TRANSPORT_AddQueueMessage, | 584 | struct GNUNET_TRANSPORT_AddQueueMessage, |
582 | NULL), | 585 | NULL), |
583 | //GNUNET_MQ_hd_fixed_size (del_queue_message, | 586 | // GNUNET_MQ_hd_fixed_size (del_queue_message, |
584 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, | 587 | // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, |
585 | // struct GNUNET_TRANSPORT_DelQueueMessage, | 588 | // struct GNUNET_TRANSPORT_DelQueueMessage, |
586 | // NULL), | 589 | // NULL), |
587 | //GNUNET_MQ_hd_fixed_size (send_message_ack, | 590 | // GNUNET_MQ_hd_fixed_size (send_message_ack, |
588 | // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, | 591 | // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, |
589 | // struct GNUNET_TRANSPORT_SendMessageToAck, | 592 | // struct GNUNET_TRANSPORT_SendMessageToAck, |
590 | // NULL), | 593 | // NULL), |
591 | }; | 594 | }; |
592 | struct GNUNET_SERVICE_Handle *h; | 595 | struct GNUNET_SERVICE_Handle *h; |
593 | 596 | ||
594 | h = GNUNET_SERVICE_start("transport", | 597 | h = GNUNET_SERVICE_start ("transport", |
595 | tc_h->cfg, | 598 | tc_h->cfg, |
596 | &connect_cb, | 599 | &connect_cb, |
597 | &disconnect_cb, | 600 | &disconnect_cb, |
598 | tc_h, | 601 | tc_h, |
599 | mh); | 602 | mh); |
600 | if (NULL == h) | 603 | if (NULL == h) |
601 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); | 604 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); |
602 | else | 605 | else |
603 | { | 606 | { |
604 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); | 607 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); |
605 | /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_service, h); | 608 | /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h); |
606 | } | 609 | } |
607 | } | 610 | } |
608 | 611 | ||
609 | 612 | ||
@@ -613,21 +616,21 @@ transport_communicator_start( | |||
613 | * @param cls Closure - Process of communicator | 616 | * @param cls Closure - Process of communicator |
614 | */ | 617 | */ |
615 | static void | 618 | static void |
616 | shutdown_communicator(void *cls) | 619 | shutdown_communicator (void *cls) |
617 | { | 620 | { |
618 | struct GNUNET_OS_Process *proc = cls; | 621 | struct GNUNET_OS_Process *proc = cls; |
619 | 622 | ||
620 | if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGTERM)) | 623 | if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM)) |
624 | { | ||
625 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
626 | "Error shutting down communicator with SIGERM, trying SIGKILL\n"); | ||
627 | if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL)) | ||
621 | { | 628 | { |
622 | LOG(GNUNET_ERROR_TYPE_WARNING, | 629 | LOG (GNUNET_ERROR_TYPE_ERROR, |
623 | "Error shutting down communicator with SIGERM, trying SIGKILL\n"); | 630 | "Error shutting down communicator with SIGERM and SIGKILL\n"); |
624 | if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGKILL)) | ||
625 | { | ||
626 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
627 | "Error shutting down communicator with SIGERM and SIGKILL\n"); | ||
628 | } | ||
629 | } | 631 | } |
630 | GNUNET_OS_process_destroy(proc); | 632 | } |
633 | GNUNET_OS_process_destroy (proc); | ||
631 | } | 634 | } |
632 | 635 | ||
633 | 636 | ||
@@ -637,33 +640,33 @@ shutdown_communicator(void *cls) | |||
637 | * @param cfgname Name of the communicator | 640 | * @param cfgname Name of the communicator |
638 | */ | 641 | */ |
639 | static void | 642 | static void |
640 | communicator_start( | 643 | communicator_start ( |
641 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 644 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
642 | const char *binary_name) | 645 | const char *binary_name) |
643 | { | 646 | { |
644 | char *binary; | 647 | char *binary; |
645 | 648 | ||
646 | LOG(GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); | 649 | LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); |
647 | binary = GNUNET_OS_get_libexec_binary_path(binary_name); | 650 | binary = GNUNET_OS_get_libexec_binary_path (binary_name); |
648 | tc_h->c_proc = GNUNET_OS_start_process(GNUNET_YES, | 651 | tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES, |
649 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 652 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
650 | NULL, | 653 | NULL, |
651 | NULL, | 654 | NULL, |
652 | NULL, | 655 | NULL, |
653 | binary, | 656 | binary, |
654 | binary_name, | 657 | binary_name, |
655 | "-c", | 658 | "-c", |
656 | tc_h->cfg_filename, | 659 | tc_h->cfg_filename, |
657 | NULL); | 660 | NULL); |
658 | if (NULL == tc_h->c_proc) | 661 | if (NULL == tc_h->c_proc) |
659 | { | 662 | { |
660 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); | 663 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); |
661 | return; | 664 | return; |
662 | } | 665 | } |
663 | LOG(GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); | 666 | LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); |
664 | GNUNET_free(binary); | 667 | GNUNET_free (binary); |
665 | /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_communicator, | 668 | /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator, |
666 | tc_h->c_proc); | 669 | tc_h->c_proc); |
667 | } | 670 | } |
668 | 671 | ||
669 | 672 | ||
@@ -680,7 +683,7 @@ communicator_start( | |||
680 | * @return Handle to the communicator duo | 683 | * @return Handle to the communicator duo |
681 | */ | 684 | */ |
682 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | 685 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * |
683 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | 686 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
684 | const char *service_name, | 687 | const char *service_name, |
685 | const char *binary_name, | 688 | const char *binary_name, |
686 | const char *cfg_filename, | 689 | const char *cfg_filename, |
@@ -695,19 +698,19 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | |||
695 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; | 698 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; |
696 | 699 | ||
697 | tc_h = | 700 | tc_h = |
698 | GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); | 701 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); |
699 | tc_h->cfg_filename = GNUNET_strdup(cfg_filename); | 702 | tc_h->cfg_filename = GNUNET_strdup (cfg_filename); |
700 | tc_h->cfg = GNUNET_CONFIGURATION_create(); | 703 | tc_h->cfg = GNUNET_CONFIGURATION_create (); |
701 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load(tc_h->cfg, cfg_filename))) | 704 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename))) |
702 | { | 705 | { |
703 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 706 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
704 | _("Malformed configuration file `%s', exit ...\n"), | 707 | _ ("Malformed configuration file `%s', exit ...\n"), |
705 | cfg_filename); | 708 | cfg_filename); |
706 | GNUNET_free(tc_h->cfg_filename); | 709 | GNUNET_free (tc_h->cfg_filename); |
707 | GNUNET_CONFIGURATION_destroy(tc_h->cfg); | 710 | GNUNET_CONFIGURATION_destroy (tc_h->cfg); |
708 | GNUNET_free(tc_h); | 711 | GNUNET_free (tc_h); |
709 | return NULL; | 712 | return NULL; |
710 | } | 713 | } |
711 | tc_h->communicator_available_cb = communicator_available_cb; | 714 | tc_h->communicator_available_cb = communicator_available_cb; |
712 | tc_h->add_address_cb = add_address_cb; | 715 | tc_h->add_address_cb = add_address_cb; |
713 | tc_h->queue_create_reply_cb = queue_create_reply_cb; | 716 | tc_h->queue_create_reply_cb = queue_create_reply_cb; |
@@ -716,11 +719,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | |||
716 | tc_h->cb_cls = cb_cls; | 719 | tc_h->cb_cls = cb_cls; |
717 | 720 | ||
718 | /* Start communicator part of service */ | 721 | /* Start communicator part of service */ |
719 | transport_communicator_start(tc_h); | 722 | transport_communicator_start (tc_h); |
720 | 723 | ||
721 | /* Schedule start communicator */ | 724 | /* Schedule start communicator */ |
722 | communicator_start(tc_h, | 725 | communicator_start (tc_h, |
723 | binary_name); | 726 | binary_name); |
724 | return tc_h; | 727 | return tc_h; |
725 | } | 728 | } |
726 | 729 | ||
@@ -733,7 +736,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | |||
733 | * @param address For which address | 736 | * @param address For which address |
734 | */ | 737 | */ |
735 | void | 738 | void |
736 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue( | 739 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( |
737 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 740 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
738 | const struct GNUNET_PeerIdentity *peer_id, | 741 | const struct GNUNET_PeerIdentity *peer_id, |
739 | const char *address) | 742 | const char *address) |
@@ -746,33 +749,33 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue( | |||
746 | size_t alen; | 749 | size_t alen; |
747 | 750 | ||
748 | tc_queue = | 751 | tc_queue = |
749 | GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); | 752 | GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); |
750 | tc_queue->tc_h = tc_h; | 753 | tc_queue->tc_h = tc_h; |
751 | prefix = GNUNET_HELLO_address_to_prefix(address); | 754 | prefix = GNUNET_HELLO_address_to_prefix (address); |
752 | if (NULL == prefix) | 755 | if (NULL == prefix) |
753 | { | 756 | { |
754 | GNUNET_break(0); /* We got an invalid address!? */ | 757 | GNUNET_break (0); /* We got an invalid address!? */ |
755 | GNUNET_free(tc_queue); | 758 | GNUNET_free (tc_queue); |
756 | return; | 759 | return; |
757 | } | 760 | } |
758 | GNUNET_free(prefix); | 761 | GNUNET_free (prefix); |
759 | alen = strlen(address) + 1; | 762 | alen = strlen (address) + 1; |
760 | env = | 763 | env = |
761 | GNUNET_MQ_msg_extra(msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); | 764 | GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); |
762 | msg->request_id = htonl(idgen++); | 765 | msg->request_id = htonl (idgen++); |
763 | tc_queue->qid = msg->request_id; | 766 | tc_queue->qid = msg->request_id; |
764 | msg->receiver = *peer_id; | 767 | msg->receiver = *peer_id; |
765 | tc_queue->peer_id = *peer_id; | 768 | tc_queue->peer_id = *peer_id; |
766 | memcpy(&msg[1], address, alen); | 769 | memcpy (&msg[1], address, alen); |
767 | if (NULL != tc_h->c_mq) | 770 | if (NULL != tc_h->c_mq) |
768 | { | 771 | { |
769 | GNUNET_MQ_send(tc_h->c_mq, env); | 772 | GNUNET_MQ_send (tc_h->c_mq, env); |
770 | } | 773 | } |
771 | else | 774 | else |
772 | { | 775 | { |
773 | tc_queue->open_queue_env = env; | 776 | tc_queue->open_queue_env = env; |
774 | } | 777 | } |
775 | GNUNET_CONTAINER_DLL_insert(tc_h->queue_head, tc_h->queue_tail, tc_queue); | 778 | GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue); |
776 | } | 779 | } |
777 | 780 | ||
778 | 781 | ||
@@ -800,20 +803,20 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send | |||
800 | size_t inbox_size; | 803 | size_t inbox_size; |
801 | 804 | ||
802 | inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size; | 805 | inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size; |
803 | mh = GNUNET_malloc(inbox_size); | 806 | mh = GNUNET_malloc (inbox_size); |
804 | mh->size = htons(inbox_size); | 807 | mh->size = htons (inbox_size); |
805 | mh->type = GNUNET_MESSAGE_TYPE_DUMMY; | 808 | mh->type = GNUNET_MESSAGE_TYPE_DUMMY; |
806 | memcpy(&mh[1], | 809 | memcpy (&mh[1], |
807 | payload, | 810 | payload, |
808 | payload_size); | 811 | payload_size); |
809 | env = GNUNET_MQ_msg_extra(msg, | 812 | env = GNUNET_MQ_msg_extra (msg, |
810 | inbox_size, | 813 | inbox_size, |
811 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); | 814 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); |
812 | msg->qid = htonl(tc_queue->qid); | 815 | msg->qid = htonl (tc_queue->qid); |
813 | msg->mid = tc_queue->mid++; | 816 | msg->mid = tc_queue->mid++; |
814 | msg->receiver = tc_queue->peer_id; | 817 | msg->receiver = tc_queue->peer_id; |
815 | memcpy(&msg[1], mh, inbox_size); | 818 | memcpy (&msg[1], mh, inbox_size); |
816 | GNUNET_free(mh); | 819 | GNUNET_free (mh); |
817 | GNUNET_MQ_send(tc_queue->tc_h->c_mq, env); | 820 | GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); |
818 | return tc_t; | 821 | return tc_t; |
819 | } | 822 | } |