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