summaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r--src/transport/gnunet-service-transport.c2336
1 files changed, 1173 insertions, 1163 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 5080e650e..853a61127 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -61,7 +61,8 @@
61/** 61/**
62 * Information we need for an asynchronous session kill. 62 * Information we need for an asynchronous session kill.
63 */ 63 */
64struct GNUNET_ATS_SessionKiller { 64struct GNUNET_ATS_SessionKiller
65{
65 /** 66 /**
66 * Kept in a DLL. 67 * Kept in a DLL.
67 */ 68 */
@@ -92,7 +93,8 @@ struct GNUNET_ATS_SessionKiller {
92/** 93/**
93 * What type of client is the `struct TransportClient` about? 94 * What type of client is the `struct TransportClient` about?
94 */ 95 */
95enum ClientType { 96enum ClientType
97{
96 /** 98 /**
97 * We do not know yet (client is fresh). 99 * We do not know yet (client is fresh).
98 */ 100 */
@@ -128,7 +130,8 @@ struct GST_BlacklistCheck;
128/** 130/**
129 * Client connected to the transport service. 131 * Client connected to the transport service.
130 */ 132 */
131struct TransportClient { 133struct TransportClient
134{
132 /** 135 /**
133 * This is a doubly-linked list. 136 * This is a doubly-linked list.
134 */ 137 */
@@ -154,7 +157,8 @@ struct TransportClient {
154 */ 157 */
155 enum ClientType type; 158 enum ClientType type;
156 159
157 union { 160 union
161 {
158 /** 162 /**
159 * Peer identity to monitor the addresses of. 163 * Peer identity to monitor the addresses of.
160 * Zero to monitor all neighbours. Valid if 164 * Zero to monitor all neighbours. Valid if
@@ -165,7 +169,8 @@ struct TransportClient {
165 /** 169 /**
166 * Additional details if @e type is CT_BLACKLIST. 170 * Additional details if @e type is CT_BLACKLIST.
167 */ 171 */
168 struct { 172 struct
173 {
169 /** 174 /**
170 * Blacklist check that we're currently performing (or NULL 175 * Blacklist check that we're currently performing (or NULL
171 * if we're performing one that has been cancelled). 176 * if we're performing one that has been cancelled).
@@ -189,7 +194,8 @@ struct TransportClient {
189/** 194/**
190 * Context we use when performing a blacklist check. 195 * Context we use when performing a blacklist check.
191 */ 196 */
192struct GST_BlacklistCheck { 197struct GST_BlacklistCheck
198{
193 /** 199 /**
194 * This is a linked list. 200 * This is a linked list.
195 */ 201 */
@@ -240,7 +246,8 @@ struct GST_BlacklistCheck {
240/** 246/**
241 * Context for address to string operations 247 * Context for address to string operations
242 */ 248 */
243struct AddressToStringContext { 249struct AddressToStringContext
250{
244 /** 251 /**
245 * This is a doubly-linked list. 252 * This is a doubly-linked list.
246 */ 253 */
@@ -261,7 +268,8 @@ struct AddressToStringContext {
261/** 268/**
262 * Closure for #handle_send_transmit_continuation() 269 * Closure for #handle_send_transmit_continuation()
263 */ 270 */
264struct SendTransmitContinuationContext { 271struct SendTransmitContinuationContext
272{
265 /** 273 /**
266 * Client that made the request. 274 * Client that made the request.
267 */ 275 */
@@ -416,31 +424,31 @@ struct GNUNET_NT_InterfaceScanner *GST_is;
416 * @param may_drop #GNUNET_YES if the message can be dropped 424 * @param may_drop #GNUNET_YES if the message can be dropped
417 */ 425 */
418static void 426static void
419unicast(struct TransportClient *tc, 427unicast (struct TransportClient *tc,
420 const struct GNUNET_MessageHeader *msg, 428 const struct GNUNET_MessageHeader *msg,
421 int may_drop) 429 int may_drop)
422{ 430{
423 struct GNUNET_MQ_Envelope *env; 431 struct GNUNET_MQ_Envelope *env;
424 432
425 if ((GNUNET_MQ_get_length(tc->mq) >= MAX_PENDING) && 433 if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) &&
426 (GNUNET_YES == may_drop)) 434 (GNUNET_YES == may_drop))
427 { 435 {
428 GNUNET_log( 436 GNUNET_log (
429 GNUNET_ERROR_TYPE_DEBUG, 437 GNUNET_ERROR_TYPE_DEBUG,
430 "Dropping message of type %u and size %u, have %u/%u messages pending\n", 438 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
431 ntohs(msg->type), 439 ntohs (msg->type),
432 ntohs(msg->size), 440 ntohs (msg->size),
433 GNUNET_MQ_get_length(tc->mq), 441 GNUNET_MQ_get_length (tc->mq),
434 MAX_PENDING); 442 MAX_PENDING);
435 GNUNET_STATISTICS_update(GST_stats, 443 GNUNET_STATISTICS_update (GST_stats,
436 gettext_noop( 444 gettext_noop (
437 "# messages dropped due to slow client"), 445 "# messages dropped due to slow client"),
438 1, 446 1,
439 GNUNET_NO); 447 GNUNET_NO);
440 return; 448 return;
441 } 449 }
442 env = GNUNET_MQ_msg_copy(msg); 450 env = GNUNET_MQ_msg_copy (msg);
443 GNUNET_MQ_send(tc->mq, env); 451 GNUNET_MQ_send (tc->mq, env);
444} 452}
445 453
446 454
@@ -454,17 +462,17 @@ unicast(struct TransportClient *tc,
454 * @return our `struct TransportClient` 462 * @return our `struct TransportClient`
455 */ 463 */
456static void * 464static void *
457client_connect_cb(void *cls, 465client_connect_cb (void *cls,
458 struct GNUNET_SERVICE_Client *client, 466 struct GNUNET_SERVICE_Client *client,
459 struct GNUNET_MQ_Handle *mq) 467 struct GNUNET_MQ_Handle *mq)
460{ 468{
461 struct TransportClient *tc; 469 struct TransportClient *tc;
462 470
463 tc = GNUNET_new(struct TransportClient); 471 tc = GNUNET_new (struct TransportClient);
464 tc->client = client; 472 tc->client = client;
465 tc->mq = mq; 473 tc->mq = mq;
466 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc); 474 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
467 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
468 return tc; 476 return tc;
469} 477}
470 478
@@ -475,7 +483,7 @@ client_connect_cb(void *cls,
475 * @param cls the `struct BlacklistCheck*` 483 * @param cls the `struct BlacklistCheck*`
476 */ 484 */
477static void 485static void
478do_blacklist_check(void *cls); 486do_blacklist_check (void *cls);
479 487
480 488
481/** 489/**
@@ -488,16 +496,16 @@ do_blacklist_check(void *cls);
488 * @return #GNUNET_OK (continue to iterate) 496 * @return #GNUNET_OK (continue to iterate)
489 */ 497 */
490static int 498static int
491mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 499mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
492{ 500{
493 struct TransportClient *tc = cls; 501 struct TransportClient *tc = cls;
494 struct SendTransmitContinuationContext *stcc = value; 502 struct SendTransmitContinuationContext *stcc = value;
495 503
496 if (tc == stcc->tc) 504 if (tc == stcc->tc)
497 { 505 {
498 stcc->down = GNUNET_YES; 506 stcc->down = GNUNET_YES;
499 stcc->tc = NULL; 507 stcc->tc = NULL;
500 } 508 }
501 return GNUNET_OK; 509 return GNUNET_OK;
502} 510}
503 511
@@ -511,50 +519,50 @@ mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
511 * @param app_ctx our `struct TransportClient` 519 * @param app_ctx our `struct TransportClient`
512 */ 520 */
513static void 521static void
514client_disconnect_cb(void *cls, 522client_disconnect_cb (void *cls,
515 struct GNUNET_SERVICE_Client *client, 523 struct GNUNET_SERVICE_Client *client,
516 void *app_ctx) 524 void *app_ctx)
517{ 525{
518 struct TransportClient *tc = app_ctx; 526 struct TransportClient *tc = app_ctx;
519 struct GST_BlacklistCheck *bc; 527 struct GST_BlacklistCheck *bc;
520 528
521 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Client %p disconnected, cleaning up.\n", 530 "Client %p disconnected, cleaning up.\n",
523 tc); 531 tc);
524 GNUNET_CONTAINER_multipeermap_iterate(active_stccs, &mark_match_down, tc); 532 GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc);
525 for (struct AddressToStringContext *cur = a2s_head; NULL != cur; 533 for (struct AddressToStringContext *cur = a2s_head; NULL != cur;
526 cur = cur->next) 534 cur = cur->next)
527 { 535 {
528 if (cur->tc == tc) 536 if (cur->tc == tc)
529 cur->tc = NULL; 537 cur->tc = NULL;
530 } 538 }
531 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc); 539 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
532 switch (tc->type) 540 switch (tc->type)
533 { 541 {
534 case CT_NONE: 542 case CT_NONE:
535 break; 543 break;
536
537 case CT_CORE:
538 break;
539 544
540 case CT_MONITOR: 545 case CT_CORE:
541 break; 546 break;
542 547
543 case CT_BLACKLIST: 548 case CT_MONITOR:
544 for (bc = bc_head; NULL != bc; bc = bc->next) 549 break;
545 {
546 if (bc->bl_pos != tc)
547 continue;
548 bc->bl_pos = tc->next;
549 if (NULL == bc->task)
550 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
551 }
552 break;
553 550
554 case CT_CORE_NO_HANDLERS: 551 case CT_BLACKLIST:
555 break; 552 for (bc = bc_head; NULL != bc; bc = bc->next)
553 {
554 if (bc->bl_pos != tc)
555 continue;
556 bc->bl_pos = tc->next;
557 if (NULL == bc->task)
558 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
556 } 559 }
557 GNUNET_free(tc); 560 break;
561
562 case CT_CORE_NO_HANDLERS:
563 break;
564 }
565 GNUNET_free (tc);
558} 566}
559 567
560 568
@@ -571,24 +579,24 @@ client_disconnect_cb(void *cls,
571 * @param bandwidth_out outbound bandwidth in NBO 579 * @param bandwidth_out outbound bandwidth in NBO
572 */ 580 */
573static void 581static void
574notify_client_about_neighbour(void *cls, 582notify_client_about_neighbour (void *cls,
575 const struct GNUNET_PeerIdentity *peer, 583 const struct GNUNET_PeerIdentity *peer,
576 const struct GNUNET_HELLO_Address *address, 584 const struct GNUNET_HELLO_Address *address,
577 enum GNUNET_TRANSPORT_PeerState state, 585 enum GNUNET_TRANSPORT_PeerState state,
578 struct GNUNET_TIME_Absolute state_timeout, 586 struct GNUNET_TIME_Absolute state_timeout,
579 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 587 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
580 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 588 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
581{ 589{
582 struct TransportClient *tc = cls; 590 struct TransportClient *tc = cls;
583 struct ConnectInfoMessage cim; 591 struct ConnectInfoMessage cim;
584 592
585 if (GNUNET_NO == GST_neighbours_test_connected(peer)) 593 if (GNUNET_NO == GST_neighbours_test_connected (peer))
586 return; 594 return;
587 cim.header.size = htons(sizeof(struct ConnectInfoMessage)); 595 cim.header.size = htons (sizeof(struct ConnectInfoMessage));
588 cim.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 596 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
589 cim.id = *peer; 597 cim.id = *peer;
590 cim.quota_out = bandwidth_out; 598 cim.quota_out = bandwidth_out;
591 unicast(tc, &cim.header, GNUNET_NO); 599 unicast (tc, &cim.header, GNUNET_NO);
592} 600}
593 601
594 602
@@ -601,39 +609,39 @@ notify_client_about_neighbour(void *cls,
601 * @param start the start message that was sent 609 * @param start the start message that was sent
602 */ 610 */
603static void 611static void
604handle_client_start(void *cls, const struct StartMessage *start) 612handle_client_start (void *cls, const struct StartMessage *start)
605{ 613{
606 struct TransportClient *tc = cls; 614 struct TransportClient *tc = cls;
607 const struct GNUNET_MessageHeader *hello; 615 const struct GNUNET_MessageHeader *hello;
608 uint32_t options; 616 uint32_t options;
609 617
610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); 618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc);
611 options = ntohl(start->options); 619 options = ntohl (start->options);
612 if ((0 != (1 & options)) && 620 if ((0 != (1 & options)) &&
613 (0 != memcmp(&start->self, 621 (0 != memcmp (&start->self,
614 &GST_my_identity, 622 &GST_my_identity,
615 sizeof(struct GNUNET_PeerIdentity)))) 623 sizeof(struct GNUNET_PeerIdentity))))
616 { 624 {
617 /* client thinks this is a different peer, reject */ 625 /* client thinks this is a different peer, reject */
618 GNUNET_break(0); 626 GNUNET_break (0);
619 GNUNET_SERVICE_client_drop(tc->client); 627 GNUNET_SERVICE_client_drop (tc->client);
620 return; 628 return;
621 } 629 }
622 if (CT_NONE != tc->type) 630 if (CT_NONE != tc->type)
623 { 631 {
624 GNUNET_break(0); 632 GNUNET_break (0);
625 GNUNET_SERVICE_client_drop(tc->client); 633 GNUNET_SERVICE_client_drop (tc->client);
626 return; 634 return;
627 } 635 }
628 if (0 != (2 & options)) 636 if (0 != (2 & options))
629 tc->type = CT_CORE; 637 tc->type = CT_CORE;
630 else 638 else
631 tc->type = CT_CORE_NO_HANDLERS; 639 tc->type = CT_CORE_NO_HANDLERS;
632 hello = GST_hello_get(); 640 hello = GST_hello_get ();
633 if (NULL != hello) 641 if (NULL != hello)
634 unicast(tc, hello, GNUNET_NO); 642 unicast (tc, hello, GNUNET_NO);
635 GST_neighbours_iterate(&notify_client_about_neighbour, tc); 643 GST_neighbours_iterate (&notify_client_about_neighbour, tc);
636 GNUNET_SERVICE_client_continue(tc->client); 644 GNUNET_SERVICE_client_continue (tc->client);
637} 645}
638 646
639 647
@@ -644,7 +652,7 @@ handle_client_start(void *cls, const struct StartMessage *start)
644 * @param message the HELLO message 652 * @param message the HELLO message
645 */ 653 */
646static int 654static int
647check_client_hello(void *cls, const struct GNUNET_MessageHeader *message) 655check_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
648{ 656{
649 return GNUNET_OK; /* FIXME: check here? */ 657 return GNUNET_OK; /* FIXME: check here? */
650} 658}
@@ -657,13 +665,13 @@ check_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
657 * @param message the HELLO message 665 * @param message the HELLO message
658 */ 666 */
659static void 667static void
660handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message) 668handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
661{ 669{
662 struct TransportClient *tc = cls; 670 struct TransportClient *tc = cls;
663 671
664 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); 672 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n");
665 GST_validation_handle_hello(message); 673 GST_validation_handle_hello (message);
666 GNUNET_SERVICE_client_continue(tc->client); 674 GNUNET_SERVICE_client_continue (tc->client);
667} 675}
668 676
669 677
@@ -677,55 +685,55 @@ handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
677 * @param bytes_on_wire bytes sent on wire 685 * @param bytes_on_wire bytes sent on wire
678 */ 686 */
679static void 687static void
680handle_send_transmit_continuation(void *cls, 688handle_send_transmit_continuation (void *cls,
681 int success, 689 int success,
682 size_t bytes_payload, 690 size_t bytes_payload,
683 size_t bytes_on_wire) 691 size_t bytes_on_wire)
684{ 692{
685 struct SendTransmitContinuationContext *stcc = cls; 693 struct SendTransmitContinuationContext *stcc = cls;
686 struct SendOkMessage send_ok_msg; 694 struct SendOkMessage send_ok_msg;
687 struct GNUNET_TIME_Relative delay; 695 struct GNUNET_TIME_Relative delay;
688 const struct GNUNET_HELLO_Address *addr; 696 const struct GNUNET_HELLO_Address *addr;
689 697
690 delay = GNUNET_TIME_absolute_get_duration(stcc->send_time); 698 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time);
691 addr = GST_neighbour_get_current_address(&stcc->target); 699 addr = GST_neighbour_get_current_address (&stcc->target);
692 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 700 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
693 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 701 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
694 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 702 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
695 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 703 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
696 (unsigned int)bytes_payload, 704 (unsigned int) bytes_payload,
697 (unsigned int)bytes_on_wire, 705 (unsigned int) bytes_on_wire,
698 GNUNET_i2s(&stcc->target), 706 GNUNET_i2s (&stcc->target),
699 success, 707 success,
700 (NULL != addr) ? addr->transport_name : "%"); 708 (NULL != addr) ? addr->transport_name : "%");
701 else 709 else
702 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
703 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 711 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
704 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES), 712 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES),
705 (unsigned int)bytes_payload, 713 (unsigned int) bytes_payload,
706 (unsigned int)bytes_on_wire, 714 (unsigned int) bytes_on_wire,
707 GNUNET_i2s(&stcc->target), 715 GNUNET_i2s (&stcc->target),
708 success, 716 success,
709 (NULL != addr) ? addr->transport_name : "%"); 717 (NULL != addr) ? addr->transport_name : "%");
710 718
711 if (GNUNET_NO == stcc->down) 719 if (GNUNET_NO == stcc->down)
712 { 720 {
713 /* Only send confirmation if we are still connected */ 721 /* Only send confirmation if we are still connected */
714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Sending SEND_OK for transmission request %llu\n", 723 "Sending SEND_OK for transmission request %llu\n",
716 stcc->uuid); 724 stcc->uuid);
717 send_ok_msg.header.size = htons(sizeof(send_ok_msg)); 725 send_ok_msg.header.size = htons (sizeof(send_ok_msg));
718 send_ok_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 726 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
719 send_ok_msg.bytes_msg = htonl(bytes_payload); 727 send_ok_msg.bytes_msg = htonl (bytes_payload);
720 send_ok_msg.bytes_physical = htonl(bytes_on_wire); 728 send_ok_msg.bytes_physical = htonl (bytes_on_wire);
721 send_ok_msg.success = htonl(success); 729 send_ok_msg.success = htonl (success);
722 send_ok_msg.peer = stcc->target; 730 send_ok_msg.peer = stcc->target;
723 unicast(stcc->tc, &send_ok_msg.header, GNUNET_NO); 731 unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO);
724 } 732 }
725 GNUNET_assert( 733 GNUNET_assert (
726 GNUNET_OK == 734 GNUNET_OK ==
727 GNUNET_CONTAINER_multipeermap_remove(active_stccs, &stcc->target, stcc)); 735 GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc));
728 GNUNET_free(stcc); 736 GNUNET_free (stcc);
729} 737}
730 738
731 739
@@ -736,23 +744,23 @@ handle_send_transmit_continuation(void *cls,
736 * @param obm the send message that was sent 744 * @param obm the send message that was sent
737 */ 745 */
738static int 746static int
739check_client_send(void *cls, const struct OutboundMessage *obm) 747check_client_send (void *cls, const struct OutboundMessage *obm)
740{ 748{
741 uint16_t size; 749 uint16_t size;
742 const struct GNUNET_MessageHeader *obmm; 750 const struct GNUNET_MessageHeader *obmm;
743 751
744 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage); 752 size = ntohs (obm->header.size) - sizeof(struct OutboundMessage);
745 if (size < sizeof(struct GNUNET_MessageHeader)) 753 if (size < sizeof(struct GNUNET_MessageHeader))
746 { 754 {
747 GNUNET_break(0); 755 GNUNET_break (0);
748 return GNUNET_SYSERR; 756 return GNUNET_SYSERR;
749 } 757 }
750 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 758 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
751 if (size != ntohs(obmm->size)) 759 if (size != ntohs (obmm->size))
752 { 760 {
753 GNUNET_break(0); 761 GNUNET_break (0);
754 return GNUNET_SYSERR; 762 return GNUNET_SYSERR;
755 } 763 }
756 return GNUNET_OK; 764 return GNUNET_OK;
757} 765}
758 766
@@ -764,53 +772,53 @@ check_client_send(void *cls, const struct OutboundMessage *obm)
764 * @param obm the send message that was sent 772 * @param obm the send message that was sent
765 */ 773 */
766static void 774static void
767handle_client_send(void *cls, const struct OutboundMessage *obm) 775handle_client_send (void *cls, const struct OutboundMessage *obm)
768{ 776{
769 static unsigned long long uuid_gen; 777 static unsigned long long uuid_gen;
770 struct TransportClient *tc = cls; 778 struct TransportClient *tc = cls;
771 const struct GNUNET_MessageHeader *obmm; 779 const struct GNUNET_MessageHeader *obmm;
772 struct SendTransmitContinuationContext *stcc; 780 struct SendTransmitContinuationContext *stcc;
773 781
774 obmm = (const struct GNUNET_MessageHeader *)&obm[1]; 782 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
775 if (GNUNET_NO == GST_neighbours_test_connected(&obm->peer)) 783 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
776 { 784 {
777 /* not connected, not allowed to send; can happen due to asynchronous operations */ 785 /* not connected, not allowed to send; can happen due to asynchronous operations */
778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
779 "Could not send message to peer `%s': not connected\n", 787 "Could not send message to peer `%s': not connected\n",
780 GNUNET_i2s(&obm->peer)); 788 GNUNET_i2s (&obm->peer));
781 GNUNET_STATISTICS_update( 789 GNUNET_STATISTICS_update (
782 GST_stats, 790 GST_stats,
783 gettext_noop("# bytes payload dropped (other peer was not connected)"), 791 gettext_noop ("# bytes payload dropped (other peer was not connected)"),
784 ntohs(obmm->size), 792 ntohs (obmm->size),
785 GNUNET_NO); 793 GNUNET_NO);
786 GNUNET_SERVICE_client_continue(tc->client); 794 GNUNET_SERVICE_client_continue (tc->client);
787 return; 795 return;
788 } 796 }
789 GNUNET_log( 797 GNUNET_log (
790 GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_ERROR_TYPE_DEBUG,
791 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", 799 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
792 uuid_gen, 800 uuid_gen,
793 GNUNET_i2s(&obm->peer), 801 GNUNET_i2s (&obm->peer),
794 ntohs(obmm->type), 802 ntohs (obmm->type),
795 ntohs(obmm->size)); 803 ntohs (obmm->size));
796 GNUNET_SERVICE_client_continue(tc->client); 804 GNUNET_SERVICE_client_continue (tc->client);
797 805
798 stcc = GNUNET_new(struct SendTransmitContinuationContext); 806 stcc = GNUNET_new (struct SendTransmitContinuationContext);
799 stcc->target = obm->peer; 807 stcc->target = obm->peer;
800 stcc->tc = tc; 808 stcc->tc = tc;
801 stcc->send_time = GNUNET_TIME_absolute_get(); 809 stcc->send_time = GNUNET_TIME_absolute_get ();
802 stcc->uuid = uuid_gen++; 810 stcc->uuid = uuid_gen++;
803 (void)GNUNET_CONTAINER_multipeermap_put( 811 (void) GNUNET_CONTAINER_multipeermap_put (
804 active_stccs, 812 active_stccs,
805 &stcc->target, 813 &stcc->target,
806 stcc, 814 stcc,
807 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 815 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
808 GST_manipulation_send(&obm->peer, 816 GST_manipulation_send (&obm->peer,
809 obmm, 817 obmm,
810 ntohs(obmm->size), 818 ntohs (obmm->size),
811 GNUNET_TIME_relative_ntoh(obm->timeout), 819 GNUNET_TIME_relative_ntoh (obm->timeout),
812 &handle_send_transmit_continuation, 820 &handle_send_transmit_continuation,
813 stcc); 821 stcc);
814} 822}
815 823
816 824
@@ -829,50 +837,50 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
829 * never #GNUNET_NO 837 * never #GNUNET_NO
830 */ 838 */
831static void 839static void
832transmit_address_to_client(void *cls, const char *buf, int res) 840transmit_address_to_client (void *cls, const char *buf, int res)
833{ 841{
834 struct AddressToStringContext *actx = cls; 842 struct AddressToStringContext *actx = cls;
835 struct GNUNET_MQ_Envelope *env; 843 struct GNUNET_MQ_Envelope *env;
836 struct AddressToStringResultMessage *atsm; 844 struct AddressToStringResultMessage *atsm;
837 size_t slen; 845 size_t slen;
838 846
839 GNUNET_assert((GNUNET_OK == res) || (GNUNET_SYSERR == res)); 847 GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res));
840 if (NULL == actx->tc) 848 if (NULL == actx->tc)
841 return; 849 return;
842 if (NULL == buf) 850 if (NULL == buf)
851 {
852 env = GNUNET_MQ_msg (atsm,
853 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
854 if (GNUNET_OK == res)
855 {
856 /* this was the last call, transmit */
857 atsm->res = htonl (GNUNET_OK);
858 atsm->addr_len = htonl (0);
859 GNUNET_MQ_send (actx->tc->mq, env);
860 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
861 GNUNET_free (actx);
862 return;
863 }
864 if (GNUNET_SYSERR == res)
843 { 865 {
844 env = GNUNET_MQ_msg(atsm, 866 /* address conversion failed, but there will be more callbacks */
845 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 867 atsm->res = htonl (GNUNET_SYSERR);
846 if (GNUNET_OK == res) 868 atsm->addr_len = htonl (0);
847 { 869 GNUNET_MQ_send (actx->tc->mq, env);
848 /* this was the last call, transmit */ 870 return;
849 atsm->res = htonl(GNUNET_OK);
850 atsm->addr_len = htonl(0);
851 GNUNET_MQ_send(actx->tc->mq, env);
852 GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, actx);
853 GNUNET_free(actx);
854 return;
855 }
856 if (GNUNET_SYSERR == res)
857 {
858 /* address conversion failed, but there will be more callbacks */
859 atsm->res = htonl(GNUNET_SYSERR);
860 atsm->addr_len = htonl(0);
861 GNUNET_MQ_send(actx->tc->mq, env);
862 return;
863 }
864 } 871 }
865 GNUNET_assert(GNUNET_OK == res); 872 }
873 GNUNET_assert (GNUNET_OK == res);
866 /* succesful conversion, append*/ 874 /* succesful conversion, append*/
867 slen = strlen(buf) + 1; 875 slen = strlen (buf) + 1;
868 env = 876 env =
869 GNUNET_MQ_msg_extra(atsm, 877 GNUNET_MQ_msg_extra (atsm,
870 slen, 878 slen,
871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 879 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
872 atsm->res = htonl(GNUNET_YES); 880 atsm->res = htonl (GNUNET_YES);
873 atsm->addr_len = htonl(slen); 881 atsm->addr_len = htonl (slen);
874 GNUNET_memcpy(&atsm[1], buf, slen); 882 GNUNET_memcpy (&atsm[1], buf, slen);
875 GNUNET_MQ_send(actx->tc->mq, env); 883 GNUNET_MQ_send (actx->tc->mq, env);
876} 884}
877 885
878 886
@@ -884,29 +892,29 @@ transmit_address_to_client(void *cls, const char *buf, int res)
884 * @return #GNUNET_OK if @a alum is well-formed 892 * @return #GNUNET_OK if @a alum is well-formed
885 */ 893 */
886static int 894static int
887check_client_address_to_string(void *cls, 895check_client_address_to_string (void *cls,
888 const struct AddressLookupMessage *alum) 896 const struct AddressLookupMessage *alum)
889{ 897{
890 const char *plugin_name; 898 const char *plugin_name;
891 const char *address; 899 const char *address;
892 uint32_t address_len; 900 uint32_t address_len;
893 uint16_t size; 901 uint16_t size;
894 902
895 size = ntohs(alum->header.size); 903 size = ntohs (alum->header.size);
896 address_len = ntohs(alum->addrlen); 904 address_len = ntohs (alum->addrlen);
897 if (size <= sizeof(struct AddressLookupMessage) + address_len) 905 if (size <= sizeof(struct AddressLookupMessage) + address_len)
898 { 906 {
899 GNUNET_break(0); 907 GNUNET_break (0);
900 return GNUNET_SYSERR; 908 return GNUNET_SYSERR;
901 } 909 }
902 address = (const char *)&alum[1]; 910 address = (const char *) &alum[1];
903 plugin_name = (const char *)&address[address_len]; 911 plugin_name = (const char *) &address[address_len];
904 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) - 912 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage)
905 address_len - 1]) 913 - address_len - 1])
906 { 914 {
907 GNUNET_break(0); 915 GNUNET_break (0);
908 return GNUNET_SYSERR; 916 return GNUNET_SYSERR;
909 } 917 }
910 return GNUNET_OK; 918 return GNUNET_OK;
911} 919}
912 920
@@ -918,8 +926,8 @@ check_client_address_to_string(void *cls,
918 * @param alum the resolution request 926 * @param alum the resolution request
919 */ 927 */
920static void 928static void
921handle_client_address_to_string(void *cls, 929handle_client_address_to_string (void *cls,
922 const struct AddressLookupMessage *alum) 930 const struct AddressLookupMessage *alum)
923{ 931{
924 struct TransportClient *tc = cls; 932 struct TransportClient *tc = cls;
925 struct GNUNET_TRANSPORT_PluginFunctions *papi; 933 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -932,45 +940,45 @@ handle_client_address_to_string(void *cls,
932 struct GNUNET_TIME_Relative rtimeout; 940 struct GNUNET_TIME_Relative rtimeout;
933 int32_t numeric; 941 int32_t numeric;
934 942
935 address_len = ntohs(alum->addrlen); 943 address_len = ntohs (alum->addrlen);
936 address = (const char *)&alum[1]; 944 address = (const char *) &alum[1];
937 plugin_name = (const char *)&address[address_len]; 945 plugin_name = (const char *) &address[address_len];
938 rtimeout = GNUNET_TIME_relative_ntoh(alum->timeout); 946 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
939 numeric = ntohs(alum->numeric_only); 947 numeric = ntohs (alum->numeric_only);
940 papi = GST_plugins_printer_find(plugin_name); 948 papi = GST_plugins_printer_find (plugin_name);
941 if (NULL == papi) 949 if (NULL == papi)
942 { 950 {
943 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 951 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
944 "Failed to find plugin `%s'\n", 952 "Failed to find plugin `%s'\n",
945 plugin_name); 953 plugin_name);
946 env = GNUNET_MQ_msg(atsm, 954 env = GNUNET_MQ_msg (atsm,
947 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 955 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
948 atsm->res = htonl(GNUNET_SYSERR); 956 atsm->res = htonl (GNUNET_SYSERR);
949 atsm->addr_len = htonl(0); 957 atsm->addr_len = htonl (0);
950 GNUNET_MQ_send(tc->mq, env); 958 GNUNET_MQ_send (tc->mq, env);
951 env = GNUNET_MQ_msg(atsm, 959 env = GNUNET_MQ_msg (atsm,
952 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 960 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
953 atsm->res = htonl(GNUNET_OK); 961 atsm->res = htonl (GNUNET_OK);
954 atsm->addr_len = htonl(0); 962 atsm->addr_len = htonl (0);
955 GNUNET_MQ_send(tc->mq, env); 963 GNUNET_MQ_send (tc->mq, env);
956 return; 964 return;
957 } 965 }
958 actx = GNUNET_new(struct AddressToStringContext); 966 actx = GNUNET_new (struct AddressToStringContext);
959 actx->tc = tc; 967 actx->tc = tc;
960 GNUNET_CONTAINER_DLL_insert(a2s_head, a2s_tail, actx); 968 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx);
961 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 969 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Pretty-printing address of %u bytes using plugin `%s'\n", 971 "Pretty-printing address of %u bytes using plugin `%s'\n",
964 address_len, 972 address_len,
965 plugin_name); 973 plugin_name);
966 papi->address_pretty_printer(papi->cls, 974 papi->address_pretty_printer (papi->cls,
967 plugin_name, 975 plugin_name,
968 address, 976 address,
969 address_len, 977 address_len,
970 numeric, 978 numeric,
971 rtimeout, 979 rtimeout,
972 &transmit_address_to_client, 980 &transmit_address_to_client,
973 actx); 981 actx);
974} 982}
975 983
976 984
@@ -982,7 +990,7 @@ handle_client_address_to_string(void *cls,
982 * @return composed message 990 * @return composed message
983 */ 991 */
984static struct PeerIterateResponseMessage * 992static struct PeerIterateResponseMessage *
985compose_address_iterate_response_message( 993compose_address_iterate_response_message (
986 const struct GNUNET_PeerIdentity *peer, 994 const struct GNUNET_PeerIdentity *peer,
987 const struct GNUNET_HELLO_Address *address) 995 const struct GNUNET_HELLO_Address *address)
988{ 996{
@@ -992,34 +1000,34 @@ compose_address_iterate_response_message(
992 size_t alen; 1000 size_t alen;
993 char *addr; 1001 char *addr;
994 1002
995 GNUNET_assert(NULL != peer); 1003 GNUNET_assert (NULL != peer);
996 if (NULL != address) 1004 if (NULL != address)
997 { 1005 {
998 tlen = strlen(address->transport_name) + 1; 1006 tlen = strlen (address->transport_name) + 1;
999 alen = address->address_length; 1007 alen = address->address_length;
1000 } 1008 }
1001 else 1009 else
1002 { 1010 {
1003 tlen = 0; 1011 tlen = 0;
1004 alen = 0; 1012 alen = 0;
1005 } 1013 }
1006 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen); 1014 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen);
1007 msg = GNUNET_malloc(size); 1015 msg = GNUNET_malloc (size);
1008 msg->header.size = htons(size); 1016 msg->header.size = htons (size);
1009 msg->header.type = 1017 msg->header.type =
1010 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); 1018 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1011 msg->reserved = htonl(0); 1019 msg->reserved = htonl (0);
1012 msg->peer = *peer; 1020 msg->peer = *peer;
1013 msg->addrlen = htonl(alen); 1021 msg->addrlen = htonl (alen);
1014 msg->pluginlen = htonl(tlen); 1022 msg->pluginlen = htonl (tlen);
1015 1023
1016 if (NULL != address) 1024 if (NULL != address)
1017 { 1025 {
1018 msg->local_address_info = htonl((uint32_t)address->local_info); 1026 msg->local_address_info = htonl ((uint32_t) address->local_info);
1019 addr = (char *)&msg[1]; 1027 addr = (char *) &msg[1];
1020 GNUNET_memcpy(addr, address->address, alen); 1028 GNUNET_memcpy (addr, address->address, alen);
1021 GNUNET_memcpy(&addr[alen], address->transport_name, tlen); 1029 GNUNET_memcpy (&addr[alen], address->transport_name, tlen);
1022 } 1030 }
1023 return msg; 1031 return msg;
1024} 1032}
1025 1033
@@ -1028,7 +1036,8 @@ compose_address_iterate_response_message(
1028 * Context for #send_validation_information() and 1036 * Context for #send_validation_information() and
1029 * #send_peer_information(). 1037 * #send_peer_information().
1030 */ 1038 */
1031struct IterationContext { 1039struct IterationContext
1040{
1032 /** 1041 /**
1033 * Context to use for the transmission. 1042 * Context to use for the transmission.
1034 */ 1043 */
@@ -1058,31 +1067,31 @@ struct IterationContext {
1058 * @param bandwidth_out outbound quota in NBO 1067 * @param bandwidth_out outbound quota in NBO
1059 */ 1068 */
1060static void 1069static void
1061send_peer_information(void *cls, 1070send_peer_information (void *cls,
1062 const struct GNUNET_PeerIdentity *peer, 1071 const struct GNUNET_PeerIdentity *peer,
1063 const struct GNUNET_HELLO_Address *address, 1072 const struct GNUNET_HELLO_Address *address,
1064 enum GNUNET_TRANSPORT_PeerState state, 1073 enum GNUNET_TRANSPORT_PeerState state,
1065 struct GNUNET_TIME_Absolute state_timeout, 1074 struct GNUNET_TIME_Absolute state_timeout,
1066 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1075 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1067 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1076 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1068{ 1077{
1069 struct IterationContext *pc = cls; 1078 struct IterationContext *pc = cls;
1070 struct GNUNET_MQ_Envelope *env; 1079 struct GNUNET_MQ_Envelope *env;
1071 struct PeerIterateResponseMessage *msg; 1080 struct PeerIterateResponseMessage *msg;
1072 1081
1073 if ((GNUNET_YES != pc->all) && (0 != memcmp(peer, &pc->id, sizeof(pc->id)))) 1082 if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof(pc->id))))
1074 return; 1083 return;
1075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1076 "Sending information about `%s' using address `%s' in state `%s'\n", 1085 "Sending information about `%s' using address `%s' in state `%s'\n",
1077 GNUNET_i2s(peer), 1086 GNUNET_i2s (peer),
1078 (NULL != address) ? GST_plugins_a2s(address) : "<none>", 1087 (NULL != address) ? GST_plugins_a2s (address) : "<none>",
1079 GNUNET_TRANSPORT_ps2s(state)); 1088 GNUNET_TRANSPORT_ps2s (state));
1080 msg = compose_address_iterate_response_message(peer, address); 1089 msg = compose_address_iterate_response_message (peer, address);
1081 msg->state = htonl(state); 1090 msg->state = htonl (state);
1082 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); 1091 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1083 env = GNUNET_MQ_msg_copy(&msg->header); 1092 env = GNUNET_MQ_msg_copy (&msg->header);
1084 GNUNET_free(msg); 1093 GNUNET_free (msg);
1085 GNUNET_MQ_send(pc->tc->mq, env); 1094 GNUNET_MQ_send (pc->tc->mq, env);
1086} 1095}
1087 1096
1088 1097
@@ -1094,61 +1103,61 @@ send_peer_information(void *cls,
1094 * @param msg the peer address information request 1103 * @param msg the peer address information request
1095 */ 1104 */
1096static void 1105static void
1097handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg) 1106handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg)
1098{ 1107{
1099 struct TransportClient *tc = cls; 1108 struct TransportClient *tc = cls;
1100 struct IterationContext pc; 1109 struct IterationContext pc;
1101 1110
1102 if (CT_NONE != tc->type) 1111 if (CT_NONE != tc->type)
1103 { 1112 {
1104 GNUNET_break(0); 1113 GNUNET_break (0);
1105 GNUNET_SERVICE_client_drop(tc->client); 1114 GNUNET_SERVICE_client_drop (tc->client);
1106 return; 1115 return;
1107 } 1116 }
1108 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 1117 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1109 GNUNET_SERVICE_client_mark_monitor(tc->client); 1118 GNUNET_SERVICE_client_mark_monitor (tc->client);
1110 1119
1111 /* Send initial list */ 1120 /* Send initial list */
1112 pc.tc = tc; 1121 pc.tc = tc;
1113 if (0 == memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) 1122 if (0 == memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1114 { 1123 {
1115 /* iterate over all neighbours */ 1124 /* iterate over all neighbours */
1116 pc.all = GNUNET_YES; 1125 pc.all = GNUNET_YES;
1117 pc.id = msg->peer; 1126 pc.id = msg->peer;
1118 } 1127 }
1119 else 1128 else
1120 { 1129 {
1121 /* just return one neighbour */ 1130 /* just return one neighbour */
1122 pc.all = GNUNET_NO; 1131 pc.all = GNUNET_NO;
1123 pc.id = msg->peer; 1132 pc.id = msg->peer;
1124 } 1133 }
1125 GST_neighbours_iterate(&send_peer_information, &pc); 1134 GST_neighbours_iterate (&send_peer_information, &pc);
1126 1135
1127 if (GNUNET_YES != ntohl(msg->one_shot)) 1136 if (GNUNET_YES != ntohl (msg->one_shot))
1128 { 1137 {
1129 tc->details.monitor_peer = msg->peer; 1138 tc->details.monitor_peer = msg->peer;
1130 tc->type = CT_MONITOR; 1139 tc->type = CT_MONITOR;
1131 if (0 != 1140 if (0 !=
1132 memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity))) 1141 memcmp (&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1134 "Client %p started monitoring of the peer `%s'\n", 1143 "Client %p started monitoring of the peer `%s'\n",
1135 tc, 1144 tc,
1136 GNUNET_i2s(&msg->peer)); 1145 GNUNET_i2s (&msg->peer));
1137 else 1146 else
1138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 "Client %p started monitoring all peers\n", 1148 "Client %p started monitoring all peers\n",
1140 tc); 1149 tc);
1141 } 1150 }
1142 else 1151 else
1143 { 1152 {
1144 struct GNUNET_MessageHeader *msg; 1153 struct GNUNET_MessageHeader *msg;
1145 struct GNUNET_MQ_Envelope *env; 1154 struct GNUNET_MQ_Envelope *env;
1146 1155
1147 env = 1156 env =
1148 GNUNET_MQ_msg(msg, 1157 GNUNET_MQ_msg (msg,
1149 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); 1158 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1150 GNUNET_MQ_send(tc->mq, env); 1159 GNUNET_MQ_send (tc->mq, env);
1151 } 1160 }
1152} 1161}
1153 1162
1154 1163
@@ -1165,9 +1174,9 @@ handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg)
1165 * merely signalling that the initial iteration is over 1174 * merely signalling that the initial iteration is over
1166 */ 1175 */
1167static void 1176static void
1168plugin_session_info_cb(void *cls, 1177plugin_session_info_cb (void *cls,
1169 struct GNUNET_ATS_Session *session, 1178 struct GNUNET_ATS_Session *session,
1170 const struct GNUNET_TRANSPORT_SessionInfo *info) 1179 const struct GNUNET_TRANSPORT_SessionInfo *info)
1171{ 1180{
1172 struct GNUNET_MQ_Envelope *env; 1181 struct GNUNET_MQ_Envelope *env;
1173 struct TransportPluginMonitorMessage *msg; 1182 struct TransportPluginMonitorMessage *msg;
@@ -1178,65 +1187,65 @@ plugin_session_info_cb(void *cls,
1178 char *name; 1187 char *name;
1179 char *addr; 1188 char *addr;
1180 1189
1181 if (0 == GNUNET_notification_context_get_size(plugin_nc)) 1190 if (0 == GNUNET_notification_context_get_size (plugin_nc))
1182 { 1191 {
1183 GST_plugins_monitor_subscribe(NULL, NULL); 1192 GST_plugins_monitor_subscribe (NULL, NULL);
1184 return; 1193 return;
1185 } 1194 }
1186 if ((NULL == info) && (NULL == session)) 1195 if ((NULL == info) && (NULL == session))
1196 {
1197 /* end of initial iteration */
1198 if (NULL != sync_client)
1187 { 1199 {
1188 /* end of initial iteration */ 1200 env =
1189 if (NULL != sync_client) 1201 GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1190 { 1202 GNUNET_MQ_send (sync_client->mq, env);
1191 env = 1203 sync_client = NULL;
1192 GNUNET_MQ_msg(sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC);
1193 GNUNET_MQ_send(sync_client->mq, env);
1194 sync_client = NULL;
1195 }
1196 return;
1197 } 1204 }
1198 GNUNET_assert(NULL != info); 1205 return;
1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1206 }
1200 "Plugin event for peer %s on transport %s\n", 1207 GNUNET_assert (NULL != info);
1201 GNUNET_i2s(&info->address->peer), 1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1202 info->address->transport_name); 1209 "Plugin event for peer %s on transport %s\n",
1203 slen = strlen(info->address->transport_name) + 1; 1210 GNUNET_i2s (&info->address->peer),
1211 info->address->transport_name);
1212 slen = strlen (info->address->transport_name) + 1;
1204 alen = info->address->address_length; 1213 alen = info->address->address_length;
1205 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen; 1214 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen;
1206 if (size > UINT16_MAX) 1215 if (size > UINT16_MAX)
1207 { 1216 {
1208 GNUNET_break(0); 1217 GNUNET_break (0);
1209 return; 1218 return;
1210 } 1219 }
1211 msg = GNUNET_malloc(size); 1220 msg = GNUNET_malloc (size);
1212 msg->header.size = htons(size); 1221 msg->header.size = htons (size);
1213 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); 1222 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1214 msg->session_state = htons((uint16_t)info->state); 1223 msg->session_state = htons ((uint16_t) info->state);
1215 msg->is_inbound = htons((int16_t)info->is_inbound); 1224 msg->is_inbound = htons ((int16_t) info->is_inbound);
1216 msg->msgs_pending = htonl(info->num_msg_pending); 1225 msg->msgs_pending = htonl (info->num_msg_pending);
1217 msg->bytes_pending = htonl(info->num_bytes_pending); 1226 msg->bytes_pending = htonl (info->num_bytes_pending);
1218 msg->timeout = GNUNET_TIME_absolute_hton(info->session_timeout); 1227 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout);
1219 msg->delay = GNUNET_TIME_absolute_hton(info->receive_delay); 1228 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay);
1220 msg->peer = info->address->peer; 1229 msg->peer = info->address->peer;
1221 msg->session_id = (uint64_t)(intptr_t)session; 1230 msg->session_id = (uint64_t) (intptr_t) session;
1222 msg->plugin_name_len = htons(slen); 1231 msg->plugin_name_len = htons (slen);
1223 msg->plugin_address_len = htons(alen); 1232 msg->plugin_address_len = htons (alen);
1224 name = (char *)&msg[1]; 1233 name = (char *) &msg[1];
1225 GNUNET_memcpy(name, info->address->transport_name, slen); 1234 GNUNET_memcpy (name, info->address->transport_name, slen);
1226 addr = &name[slen]; 1235 addr = &name[slen];
1227 GNUNET_memcpy(addr, info->address->address, alen); 1236 GNUNET_memcpy (addr, info->address->address, alen);
1228 if (NULL != sync_client) 1237 if (NULL != sync_client)
1229 { 1238 {
1230 struct GNUNET_MQ_Envelope *env; 1239 struct GNUNET_MQ_Envelope *env;
1231 1240
1232 env = GNUNET_MQ_msg_copy(&msg->header); 1241 env = GNUNET_MQ_msg_copy (&msg->header);
1233 GNUNET_MQ_send(sync_client->mq, env); 1242 GNUNET_MQ_send (sync_client->mq, env);
1234 } 1243 }
1235 else 1244 else
1236 { 1245 {
1237 GNUNET_notification_context_broadcast(plugin_nc, &msg->header, GNUNET_NO); 1246 GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO);
1238 } 1247 }
1239 GNUNET_free(msg); 1248 GNUNET_free (msg);
1240} 1249}
1241 1250
1242 1251
@@ -1247,17 +1256,17 @@ plugin_session_info_cb(void *cls,
1247 * @param message the peer address information request 1256 * @param message the peer address information request
1248 */ 1257 */
1249static void 1258static void
1250handle_client_monitor_plugins(void *cls, 1259handle_client_monitor_plugins (void *cls,
1251 const struct GNUNET_MessageHeader *message) 1260 const struct GNUNET_MessageHeader *message)
1252{ 1261{
1253 struct TransportClient *tc = cls; 1262 struct TransportClient *tc = cls;
1254 1263
1255 GNUNET_SERVICE_client_mark_monitor(tc->client); 1264 GNUNET_SERVICE_client_mark_monitor (tc->client);
1256 GNUNET_SERVICE_client_disable_continue_warning(tc->client); 1265 GNUNET_SERVICE_client_disable_continue_warning (tc->client);
1257 GNUNET_notification_context_add(plugin_nc, tc->mq); 1266 GNUNET_notification_context_add (plugin_nc, tc->mq);
1258 GNUNET_assert(NULL == sync_client); 1267 GNUNET_assert (NULL == sync_client);
1259 sync_client = tc; 1268 sync_client = tc;
1260 GST_plugins_monitor_subscribe(&plugin_session_info_cb, NULL); 1269 GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL);
1261} 1270}
1262 1271
1263 1272
@@ -1268,28 +1277,28 @@ handle_client_monitor_plugins(void *cls,
1268 * @param may_drop #GNUNET_YES if the message can be dropped / is payload 1277 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1269 */ 1278 */
1270void 1279void
1271GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop) 1280GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
1272{ 1281{
1273 int done; 1282 int done;
1274 1283
1275 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1276 "Asked to broadcast message of type %u with %u bytes\n", 1285 "Asked to broadcast message of type %u with %u bytes\n",
1277 (unsigned int)ntohs(msg->type), 1286 (unsigned int) ntohs (msg->type),
1278 (unsigned int)ntohs(msg->size)); 1287 (unsigned int) ntohs (msg->size));
1279 done = GNUNET_NO; 1288 done = GNUNET_NO;
1280 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1289 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1281 { 1290 {
1282 if (CT_NONE == tc->type) 1291 if (CT_NONE == tc->type)
1283 continue; /* client not yet ready */ 1292 continue; /* client not yet ready */
1284 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) 1293 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type))
1285 continue; /* skip, this client does not care about payload */ 1294 continue; /* skip, this client does not care about payload */
1286 unicast(tc, msg, may_drop); 1295 unicast (tc, msg, may_drop);
1287 done = GNUNET_YES; 1296 done = GNUNET_YES;
1288 } 1297 }
1289 if (GNUNET_NO == done) 1298 if (GNUNET_NO == done)
1290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1291 "Message of type %u not delivered, is CORE service up?\n", 1300 "Message of type %u not delivered, is CORE service up?\n",
1292 ntohs(msg->type)); 1301 ntohs (msg->type));
1293} 1302}
1294 1303
1295 1304
@@ -1302,7 +1311,7 @@ GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop)
1302 * @param state_timeout the time out for the state 1311 * @param state_timeout the time out for the state
1303 */ 1312 */
1304void 1313void
1305GST_clients_broadcast_peer_notification( 1314GST_clients_broadcast_peer_notification (
1306 const struct GNUNET_PeerIdentity *peer, 1315 const struct GNUNET_PeerIdentity *peer,
1307 const struct GNUNET_HELLO_Address *address, 1316 const struct GNUNET_HELLO_Address *address,
1308 enum GNUNET_TRANSPORT_PeerState state, 1317 enum GNUNET_TRANSPORT_PeerState state,
@@ -1311,25 +1320,25 @@ GST_clients_broadcast_peer_notification(
1311 struct GNUNET_MQ_Envelope *env; 1320 struct GNUNET_MQ_Envelope *env;
1312 struct PeerIterateResponseMessage *msg; 1321 struct PeerIterateResponseMessage *msg;
1313 1322
1314 msg = compose_address_iterate_response_message(peer, address); 1323 msg = compose_address_iterate_response_message (peer, address);
1315 msg->state = htonl(state); 1324 msg->state = htonl (state);
1316 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); 1325 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout);
1317 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1326 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1318 { 1327 {
1319 if (CT_MONITOR != tc->type) 1328 if (CT_MONITOR != tc->type)
1320 continue; 1329 continue;
1321 if ((0 == memcmp(&tc->details.monitor_peer, 1330 if ((0 == memcmp (&tc->details.monitor_peer,
1322 &all_zeros, 1331 &all_zeros,
1323 sizeof(struct GNUNET_PeerIdentity))) || 1332 sizeof(struct GNUNET_PeerIdentity))) ||
1324 (0 == memcmp(&tc->details.monitor_peer, 1333 (0 == memcmp (&tc->details.monitor_peer,
1325 peer, 1334 peer,
1326 sizeof(struct GNUNET_PeerIdentity)))) 1335 sizeof(struct GNUNET_PeerIdentity))))
1327 { 1336 {
1328 env = GNUNET_MQ_msg_copy(&msg->header); 1337 env = GNUNET_MQ_msg_copy (&msg->header);
1329 GNUNET_MQ_send(tc->mq, env); 1338 GNUNET_MQ_send (tc->mq, env);
1330 }
1331 } 1339 }
1332 GNUNET_free(msg); 1340 }
1341 GNUNET_free (msg);
1333} 1342}
1334 1343
1335 1344
@@ -1343,7 +1352,7 @@ GST_clients_broadcast_peer_notification(
1343 * @return #GNUNET_OK (continue to iterate) 1352 * @return #GNUNET_OK (continue to iterate)
1344 */ 1353 */
1345static int 1354static int
1346mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 1355mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1347{ 1356{
1348 struct SendTransmitContinuationContext *stcc = value; 1357 struct SendTransmitContinuationContext *stcc = value;
1349 1358
@@ -1359,19 +1368,19 @@ mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1359 * @param peer peer that disconnected 1368 * @param peer peer that disconnected
1360 */ 1369 */
1361void 1370void
1362GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer) 1371GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1363{ 1372{
1364 struct DisconnectInfoMessage disconnect_msg; 1373 struct DisconnectInfoMessage disconnect_msg;
1365 1374
1366 GNUNET_CONTAINER_multipeermap_get_multiple(active_stccs, 1375 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs,
1367 peer, 1376 peer,
1368 &mark_peer_down, 1377 &mark_peer_down,
1369 NULL); 1378 NULL);
1370 disconnect_msg.header.size = htons(sizeof(struct DisconnectInfoMessage)); 1379 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
1371 disconnect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 1380 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1372 disconnect_msg.reserved = htonl(0); 1381 disconnect_msg.reserved = htonl (0);
1373 disconnect_msg.peer = *peer; 1382 disconnect_msg.peer = *peer;
1374 GST_clients_broadcast(&disconnect_msg.header, GNUNET_NO); 1383 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
1375} 1384}
1376 1385
1377 1386
@@ -1387,27 +1396,27 @@ GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer)
1387 * @param bandwidth_out outbound quota in NBO 1396 * @param bandwidth_out outbound quota in NBO
1388 */ 1397 */
1389static void 1398static void
1390transmit_our_hello(void *cls, 1399transmit_our_hello (void *cls,
1391 const struct GNUNET_PeerIdentity *peer, 1400 const struct GNUNET_PeerIdentity *peer,
1392 const struct GNUNET_HELLO_Address *address, 1401 const struct GNUNET_HELLO_Address *address,
1393 enum GNUNET_TRANSPORT_PeerState state, 1402 enum GNUNET_TRANSPORT_PeerState state,
1394 struct GNUNET_TIME_Absolute state_timeout, 1403 struct GNUNET_TIME_Absolute state_timeout,
1395 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1404 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1396 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1405 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1397{ 1406{
1398 const struct GNUNET_MessageHeader *hello = cls; 1407 const struct GNUNET_MessageHeader *hello = cls;
1399 1408
1400 if (0 == memcmp(peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity))) 1409 if (0 == memcmp (peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1401 return; /* not to ourselves */ 1410 return; /* not to ourselves */
1402 if (GNUNET_NO == GST_neighbours_test_connected(peer)) 1411 if (GNUNET_NO == GST_neighbours_test_connected (peer))
1403 return; 1412 return;
1404 1413
1405 GST_neighbours_send(peer, 1414 GST_neighbours_send (peer,
1406 hello, 1415 hello,
1407 ntohs(hello->size), 1416 ntohs (hello->size),
1408 hello_expiration, 1417 hello_expiration,
1409 NULL, 1418 NULL,
1410 NULL); 1419 NULL);
1411} 1420}
1412 1421
1413 1422
@@ -1418,12 +1427,12 @@ transmit_our_hello(void *cls,
1418 * @param hello new HELLO 1427 * @param hello new HELLO
1419 */ 1428 */
1420static void 1429static void
1421process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello) 1430process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
1422{ 1431{
1423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); 1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n");
1424 GST_clients_broadcast(hello, GNUNET_NO); 1433 GST_clients_broadcast (hello, GNUNET_NO);
1425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); 1434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n");
1426 GST_neighbours_iterate(&transmit_our_hello, (void *)hello); 1435 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
1427} 1436}
1428 1437
1429 1438
@@ -1438,44 +1447,44 @@ process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello)
1438 * @return how long the plugin should wait until receiving more data 1447 * @return how long the plugin should wait until receiving more data
1439 */ 1448 */
1440static struct GNUNET_TIME_Relative 1449static struct GNUNET_TIME_Relative
1441process_payload(const struct GNUNET_HELLO_Address *address, 1450process_payload (const struct GNUNET_HELLO_Address *address,
1442 struct GNUNET_ATS_Session *session, 1451 struct GNUNET_ATS_Session *session,
1443 const struct GNUNET_MessageHeader *message) 1452 const struct GNUNET_MessageHeader *message)
1444{ 1453{
1445 struct GNUNET_TIME_Relative ret; 1454 struct GNUNET_TIME_Relative ret;
1446 int do_forward; 1455 int do_forward;
1447 struct InboundMessage *im; 1456 struct InboundMessage *im;
1448 size_t msg_size = ntohs(message->size); 1457 size_t msg_size = ntohs (message->size);
1449 size_t size = sizeof(struct InboundMessage) + msg_size; 1458 size_t size = sizeof(struct InboundMessage) + msg_size;
1450 char buf[size] GNUNET_ALIGN; 1459 char buf[size] GNUNET_ALIGN;
1451 1460
1452 do_forward = GNUNET_SYSERR; 1461 do_forward = GNUNET_SYSERR;
1453 ret = GST_neighbours_calculate_receive_delay(&address->peer, 1462 ret = GST_neighbours_calculate_receive_delay (&address->peer,
1454 msg_size, 1463 msg_size,
1455 &do_forward); 1464 &do_forward);
1456 if (!GST_neighbours_test_connected(&address->peer)) 1465 if (! GST_neighbours_test_connected (&address->peer))
1457 { 1466 {
1458 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1459 "Discarded %u bytes type %u payload from peer `%s'\n", 1468 "Discarded %u bytes type %u payload from peer `%s'\n",
1460 (unsigned int)msg_size, 1469 (unsigned int) msg_size,
1461 ntohs(message->type), 1470 ntohs (message->type),
1462 GNUNET_i2s(&address->peer)); 1471 GNUNET_i2s (&address->peer));
1463 GNUNET_STATISTICS_update( 1472 GNUNET_STATISTICS_update (
1464 GST_stats, 1473 GST_stats,
1465 gettext_noop("# bytes payload discarded due to not connected peer"), 1474 gettext_noop ("# bytes payload discarded due to not connected peer"),
1466 msg_size, 1475 msg_size,
1467 GNUNET_NO); 1476 GNUNET_NO);
1468 return ret; 1477 return ret;
1469 } 1478 }
1470 1479
1471 if (GNUNET_YES != do_forward) 1480 if (GNUNET_YES != do_forward)
1472 return ret; 1481 return ret;
1473 im = (struct InboundMessage *)buf; 1482 im = (struct InboundMessage *) buf;
1474 im->header.size = htons(size); 1483 im->header.size = htons (size);
1475 im->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 1484 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1476 im->peer = address->peer; 1485 im->peer = address->peer;
1477 GNUNET_memcpy(&im[1], message, ntohs(message->size)); 1486 GNUNET_memcpy (&im[1], message, ntohs (message->size));
1478 GST_clients_broadcast(&im->header, GNUNET_YES); 1487 GST_clients_broadcast (&im->header, GNUNET_YES);
1479 return ret; 1488 return ret;
1480} 1489}
1481 1490
@@ -1486,14 +1495,14 @@ process_payload(const struct GNUNET_HELLO_Address *address,
1486 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill 1495 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1487 */ 1496 */
1488static void 1497static void
1489kill_session_task(void *cls) 1498kill_session_task (void *cls)
1490{ 1499{
1491 struct GNUNET_ATS_SessionKiller *sk = cls; 1500 struct GNUNET_ATS_SessionKiller *sk = cls;
1492 1501
1493 sk->task = NULL; 1502 sk->task = NULL;
1494 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); 1503 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1495 sk->plugin->disconnect_session(sk->plugin->cls, sk->session); 1504 sk->plugin->disconnect_session (sk->plugin->cls, sk->session);
1496 GNUNET_free(sk); 1505 GNUNET_free (sk);
1497} 1506}
1498 1507
1499 1508
@@ -1505,7 +1514,7 @@ kill_session_task(void *cls)
1505 * @param session session to termiante 1514 * @param session session to termiante
1506 */ 1515 */
1507static void 1516static void
1508kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session) 1517kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session)
1509{ 1518{
1510 struct GNUNET_TRANSPORT_PluginFunctions *plugin; 1519 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1511 struct GNUNET_ATS_SessionKiller *sk; 1520 struct GNUNET_ATS_SessionKiller *sk;
@@ -1513,18 +1522,18 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session)
1513 for (sk = sk_head; NULL != sk; sk = sk->next) 1522 for (sk = sk_head; NULL != sk; sk = sk->next)
1514 if (sk->session == session) 1523 if (sk->session == session)
1515 return; 1524 return;
1516 plugin = GST_plugins_find(plugin_name); 1525 plugin = GST_plugins_find (plugin_name);
1517 if (NULL == plugin) 1526 if (NULL == plugin)
1518 { 1527 {
1519 GNUNET_break(0); 1528 GNUNET_break (0);
1520 return; 1529 return;
1521 } 1530 }
1522 /* need to issue disconnect asynchronously */ 1531 /* need to issue disconnect asynchronously */
1523 sk = GNUNET_new(struct GNUNET_ATS_SessionKiller); 1532 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller);
1524 sk->session = session; 1533 sk->session = session;
1525 sk->plugin = plugin; 1534 sk->plugin = plugin;
1526 sk->task = GNUNET_SCHEDULER_add_now(&kill_session_task, sk); 1535 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk);
1527 GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); 1536 GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk);
1528} 1537}
1529 1538
1530 1539
@@ -1539,37 +1548,37 @@ kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session)
1539 * @param result the result 1548 * @param result the result
1540 */ 1549 */
1541static void 1550static void
1542connect_bl_check_cont(void *cls, 1551connect_bl_check_cont (void *cls,
1543 const struct GNUNET_PeerIdentity *peer, 1552 const struct GNUNET_PeerIdentity *peer,
1544 const struct GNUNET_HELLO_Address *address, 1553 const struct GNUNET_HELLO_Address *address,
1545 struct GNUNET_ATS_Session *session, 1554 struct GNUNET_ATS_Session *session,
1546 int result) 1555 int result)
1547{ 1556{
1548 struct GNUNET_MessageHeader *msg = cls; 1557 struct GNUNET_MessageHeader *msg = cls;
1549 1558
1550 if (GNUNET_OK == result) 1559 if (GNUNET_OK == result)
1560 {
1561 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1562 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1563 "Received SYN message from peer `%s' at `%s'\n",
1564 GNUNET_i2s (peer),
1565 GST_plugins_a2s (address));
1566 if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer))
1551 { 1567 {
1552 /* Blacklist allows to speak to this peer, forward SYN to neighbours */ 1568 GST_blacklist_abort_matching (address, session);
1553 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1569 kill_session (address->transport_name, session);
1554 "Received SYN message from peer `%s' at `%s'\n",
1555 GNUNET_i2s(peer),
1556 GST_plugins_a2s(address));
1557 if (GNUNET_OK != GST_neighbours_handle_session_syn(msg, peer))
1558 {
1559 GST_blacklist_abort_matching(address, session);
1560 kill_session(address->transport_name, session);
1561 }
1562 GNUNET_free(msg);
1563 return;
1564 } 1570 }
1565 GNUNET_free(msg); 1571 GNUNET_free (msg);
1572 return;
1573 }
1574 GNUNET_free (msg);
1566 if (GNUNET_SYSERR == result) 1575 if (GNUNET_SYSERR == result)
1567 return; /* check was aborted, session destroyed */ 1576 return; /* check was aborted, session destroyed */
1568 /* Blacklist denies to speak to this peer */ 1577 /* Blacklist denies to speak to this peer */
1569 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1570 "Discarding SYN message from `%s' due to denied blacklist check\n", 1579 "Discarding SYN message from `%s' due to denied blacklist check\n",
1571 GNUNET_i2s(peer)); 1580 GNUNET_i2s (peer));
1572 kill_session(address->transport_name, session); 1581 kill_session (address->transport_name, session);
1573} 1582}
1574 1583
1575 1584
@@ -1587,10 +1596,10 @@ connect_bl_check_cont(void *cls,
1587 * (plugins that do not support this, can ignore the return value) 1596 * (plugins that do not support this, can ignore the return value)
1588 */ 1597 */
1589struct GNUNET_TIME_Relative 1598struct GNUNET_TIME_Relative
1590GST_receive_callback(void *cls, 1599GST_receive_callback (void *cls,
1591 const struct GNUNET_HELLO_Address *address, 1600 const struct GNUNET_HELLO_Address *address,
1592 struct GNUNET_ATS_Session *session, 1601 struct GNUNET_ATS_Session *session,
1593 const struct GNUNET_MessageHeader *message) 1602 const struct GNUNET_MessageHeader *message)
1594{ 1603{
1595 const char *plugin_name = cls; 1604 const char *plugin_name = cls;
1596 struct GNUNET_TIME_Relative ret; 1605 struct GNUNET_TIME_Relative ret;
@@ -1599,115 +1608,115 @@ GST_receive_callback(void *cls,
1599 ret = GNUNET_TIME_UNIT_ZERO; 1608 ret = GNUNET_TIME_UNIT_ZERO;
1600 if (NULL == message) 1609 if (NULL == message)
1601 goto end; 1610 goto end;
1602 type = ntohs(message->type); 1611 type = ntohs (message->type);
1603 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1604 "Received message with type %u from peer `%s' at %s\n", 1613 "Received message with type %u from peer `%s' at %s\n",
1605 type, 1614 type,
1606 GNUNET_i2s(&address->peer), 1615 GNUNET_i2s (&address->peer),
1607 GST_plugins_a2s(address)); 1616 GST_plugins_a2s (address));
1608 1617
1609 GNUNET_STATISTICS_update(GST_stats, 1618 GNUNET_STATISTICS_update (GST_stats,
1610 gettext_noop("# bytes total received"), 1619 gettext_noop ("# bytes total received"),
1611 ntohs(message->size), 1620 ntohs (message->size),
1612 GNUNET_NO); 1621 GNUNET_NO);
1613 GST_neighbours_notify_data_recv(address, message); 1622 GST_neighbours_notify_data_recv (address, message);
1614 switch (type) 1623 switch (type)
1624 {
1625 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1626 /* Legacy HELLO message, discard */
1627 return ret;
1628
1629 case GNUNET_MESSAGE_TYPE_HELLO:
1630 if (GNUNET_OK != GST_validation_handle_hello (message))
1615 { 1631 {
1616 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY: 1632 GNUNET_break_op (0);
1617 /* Legacy HELLO message, discard */ 1633 GST_blacklist_abort_matching (address, session);
1618 return ret; 1634 }
1619 1635 return ret;
1620 case GNUNET_MESSAGE_TYPE_HELLO:
1621 if (GNUNET_OK != GST_validation_handle_hello(message))
1622 {
1623 GNUNET_break_op(0);
1624 GST_blacklist_abort_matching(address, session);
1625 }
1626 return ret;
1627
1628 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1629 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1630 "Processing PING from `%s'\n",
1631 GST_plugins_a2s(address));
1632 if (GNUNET_OK !=
1633 GST_validation_handle_ping(&address->peer, message, address, session))
1634 {
1635 GST_blacklist_abort_matching(address, session);
1636 kill_session(plugin_name, session);
1637 }
1638 break;
1639 1636
1640 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 1637 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1642 "Processing PONG from `%s'\n", 1639 "Processing PING from `%s'\n",
1643 GST_plugins_a2s(address)); 1640 GST_plugins_a2s (address));
1644 if (GNUNET_OK != GST_validation_handle_pong(&address->peer, message)) 1641 if (GNUNET_OK !=
1645 { 1642 GST_validation_handle_ping (&address->peer, message, address, session))
1646 GNUNET_break_op(0); 1643 {
1647 GST_blacklist_abort_matching(address, session); 1644 GST_blacklist_abort_matching (address, session);
1648 kill_session(plugin_name, session); 1645 kill_session (plugin_name, session);
1649 } 1646 }
1650 break; 1647 break;
1648
1649 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1651 "Processing PONG from `%s'\n",
1652 GST_plugins_a2s (address));
1653 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message))
1654 {
1655 GNUNET_break_op (0);
1656 GST_blacklist_abort_matching (address, session);
1657 kill_session (plugin_name, session);
1658 }
1659 break;
1651 1660
1652 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: 1661 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1653 /* Do blacklist check if communication with this peer is allowed */ 1662 /* Do blacklist check if communication with this peer is allowed */
1654 (void)GST_blacklist_test_allowed(&address->peer, 1663 (void) GST_blacklist_test_allowed (&address->peer,
1655 NULL, 1664 NULL,
1656 &connect_bl_check_cont, 1665 &connect_bl_check_cont,
1657 GNUNET_copy_message(message), 1666 GNUNET_copy_message (message),
1658 address, 1667 address,
1659 session); 1668 session);
1660 break; 1669 break;
1661 1670
1662 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: 1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1663 if (GNUNET_OK != 1672 if (GNUNET_OK !=
1664 GST_neighbours_handle_session_syn_ack(message, address, session)) 1673 GST_neighbours_handle_session_syn_ack (message, address, session))
1665 { 1674 {
1666 GST_blacklist_abort_matching(address, session); 1675 GST_blacklist_abort_matching (address, session);
1667 kill_session(plugin_name, session); 1676 kill_session (plugin_name, session);
1668 } 1677 }
1669 break; 1678 break;
1670 1679
1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 1680 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1672 if (GNUNET_OK != 1681 if (GNUNET_OK !=
1673 GST_neighbours_handle_session_ack(message, address, session)) 1682 GST_neighbours_handle_session_ack (message, address, session))
1674 { 1683 {
1675 GNUNET_break_op(0); 1684 GNUNET_break_op (0);
1676 GST_blacklist_abort_matching(address, session); 1685 GST_blacklist_abort_matching (address, session);
1677 kill_session(plugin_name, session); 1686 kill_session (plugin_name, session);
1678 } 1687 }
1679 break; 1688 break;
1680 1689
1681 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 1690 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1682 GST_neighbours_handle_disconnect_message(&address->peer, message); 1691 GST_neighbours_handle_disconnect_message (&address->peer, message);
1683 break; 1692 break;
1684 1693
1685 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: 1694 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1686 GST_neighbours_handle_quota_message(&address->peer, message); 1695 GST_neighbours_handle_quota_message (&address->peer, message);
1687 break; 1696 break;
1688 1697
1689 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 1698 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1690 GST_neighbours_keepalive(&address->peer, message); 1699 GST_neighbours_keepalive (&address->peer, message);
1691 break; 1700 break;
1692 1701
1693 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: 1702 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1694 GST_neighbours_keepalive_response(&address->peer, message); 1703 GST_neighbours_keepalive_response (&address->peer, message);
1695 break; 1704 break;
1696 1705
1697 default: 1706 default:
1698 /* should be payload */ 1707 /* should be payload */
1699 GNUNET_STATISTICS_update(GST_stats, 1708 GNUNET_STATISTICS_update (GST_stats,
1700 gettext_noop("# bytes payload received"), 1709 gettext_noop ("# bytes payload received"),
1701 ntohs(message->size), 1710 ntohs (message->size),
1702 GNUNET_NO); 1711 GNUNET_NO);
1703 ret = process_payload(address, session, message); 1712 ret = process_payload (address, session, message);
1704 break; 1713 break;
1705 } 1714 }
1706end: 1715end:
1707 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1708 "Allowing receive from peer %s to continue in %s\n", 1717 "Allowing receive from peer %s to continue in %s\n",
1709 GNUNET_i2s(&address->peer), 1718 GNUNET_i2s (&address->peer),
1710 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); 1719 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1711 return ret; 1720 return ret;
1712} 1721}
1713 1722
@@ -1722,7 +1731,7 @@ end:
1722 * @param address the address to add or remove 1731 * @param address the address to add or remove
1723 */ 1732 */
1724static void 1733static void
1725plugin_env_address_change_notification( 1734plugin_env_address_change_notification (
1726 void *cls, 1735 void *cls,
1727 int add_remove, 1736 int add_remove,
1728 const struct GNUNET_HELLO_Address *address) 1737 const struct GNUNET_HELLO_Address *address)
@@ -1730,29 +1739,29 @@ plugin_env_address_change_notification(
1730 static int addresses = 0; 1739 static int addresses = 0;
1731 1740
1732 if (GNUNET_YES == add_remove) 1741 if (GNUNET_YES == add_remove)
1742 {
1743 addresses++;
1744 GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO);
1745 }
1746 else if (GNUNET_NO == add_remove)
1747 {
1748 if (0 == addresses)
1733 { 1749 {
1734 addresses++; 1750 GNUNET_break (0);
1735 GNUNET_STATISTICS_update(GST_stats, "# transport addresses", 1, GNUNET_NO);
1736 } 1751 }
1737 else if (GNUNET_NO == add_remove) 1752 else
1738 { 1753 {
1739 if (0 == addresses) 1754 addresses--;
1740 { 1755 GNUNET_STATISTICS_update (GST_stats,
1741 GNUNET_break(0); 1756 "# transport addresses",
1742 } 1757 -1,
1743 else 1758 GNUNET_NO);
1744 {
1745 addresses--;
1746 GNUNET_STATISTICS_update(GST_stats,
1747 "# transport addresses",
1748 -1,
1749 GNUNET_NO);
1750 }
1751 } 1759 }
1752 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1760 }
1753 "Transport now has %u addresses to communicate\n", 1761 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1754 addresses); 1762 "Transport now has %u addresses to communicate\n",
1755 GST_hello_modify_addresses(add_remove, address); 1763 addresses);
1764 GST_hello_modify_addresses (add_remove, address);
1756} 1765}
1757 1766
1758 1767
@@ -1770,45 +1779,45 @@ plugin_env_address_change_notification(
1770 * @param session which session is being destoyed 1779 * @param session which session is being destoyed
1771 */ 1780 */
1772static void 1781static void
1773plugin_env_session_end(void *cls, 1782plugin_env_session_end (void *cls,
1774 const struct GNUNET_HELLO_Address *address, 1783 const struct GNUNET_HELLO_Address *address,
1775 struct GNUNET_ATS_Session *session) 1784 struct GNUNET_ATS_Session *session)
1776{ 1785{
1777 struct GNUNET_ATS_SessionKiller *sk; 1786 struct GNUNET_ATS_SessionKiller *sk;
1778 1787
1779 if (NULL == address) 1788 if (NULL == address)
1780 { 1789 {
1781 GNUNET_break(0); 1790 GNUNET_break (0);
1782 return; 1791 return;
1783 } 1792 }
1784 if (NULL == session) 1793 if (NULL == session)
1785 { 1794 {
1786 GNUNET_break(0); 1795 GNUNET_break (0);
1787 return; 1796 return;
1788 } 1797 }
1789 GNUNET_assert(strlen(address->transport_name) > 0); 1798 GNUNET_assert (strlen (address->transport_name) > 0);
1790 1799
1791 GNUNET_log( 1800 GNUNET_log (
1792 GNUNET_ERROR_TYPE_DEBUG, 1801 GNUNET_ERROR_TYPE_DEBUG,
1793 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", 1802 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1794 session, 1803 session,
1795 GNUNET_i2s(&address->peer), 1804 GNUNET_i2s (&address->peer),
1796 GST_plugins_a2s(address)); 1805 GST_plugins_a2s (address));
1797 1806
1798 GST_neighbours_session_terminated(&address->peer, session); 1807 GST_neighbours_session_terminated (&address->peer, session);
1799 GST_ats_del_session(address, session); 1808 GST_ats_del_session (address, session);
1800 GST_blacklist_abort_matching(address, session); 1809 GST_blacklist_abort_matching (address, session);
1801 1810
1802 for (sk = sk_head; NULL != sk; sk = sk->next) 1811 for (sk = sk_head; NULL != sk; sk = sk->next)
1812 {
1813 if (sk->session == session)
1803 { 1814 {
1804 if (sk->session == session) 1815 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk);
1805 { 1816 GNUNET_SCHEDULER_cancel (sk->task);
1806 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); 1817 GNUNET_free (sk);
1807 GNUNET_SCHEDULER_cancel(sk->task); 1818 break;
1808 GNUNET_free(sk);
1809 break;
1810 }
1811 } 1819 }
1820 }
1812} 1821}
1813 1822
1814 1823
@@ -1824,7 +1833,7 @@ plugin_env_session_end(void *cls,
1824 * @param result the result 1833 * @param result the result
1825 */ 1834 */
1826static void 1835static void
1827plugin_env_session_start_bl_check_cont( 1836plugin_env_session_start_bl_check_cont (
1828 void *cls, 1837 void *cls,
1829 const struct GNUNET_PeerIdentity *peer, 1838 const struct GNUNET_PeerIdentity *peer,
1830 const struct GNUNET_HELLO_Address *address, 1839 const struct GNUNET_HELLO_Address *address,
@@ -1832,19 +1841,19 @@ plugin_env_session_start_bl_check_cont(
1832 int result) 1841 int result)
1833{ 1842{
1834 if (GNUNET_OK != result) 1843 if (GNUNET_OK != result)
1835 { 1844 {
1836 kill_session(address->transport_name, session); 1845 kill_session (address->transport_name, session);
1837 return; 1846 return;
1838 } 1847 }
1839 if (GNUNET_YES != 1848 if (GNUNET_YES !=
1840 GNUNET_HELLO_address_check_option(address, 1849 GNUNET_HELLO_address_check_option (address,
1841 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1850 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1842 { 1851 {
1843 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1844 "Informing verifier about inbound session's address `%s'\n", 1853 "Informing verifier about inbound session's address `%s'\n",
1845 GST_plugins_a2s(address)); 1854 GST_plugins_a2s (address));
1846 GST_validation_handle_address(address); 1855 GST_validation_handle_address (address);
1847 } 1856 }
1848} 1857}
1849 1858
1850 1859
@@ -1857,49 +1866,49 @@ plugin_env_session_start_bl_check_cont(
1857 * @param scope network scope information 1866 * @param scope network scope information
1858 */ 1867 */
1859static void 1868static void
1860plugin_env_session_start(void *cls, 1869plugin_env_session_start (void *cls,
1861 const struct GNUNET_HELLO_Address *address, 1870 const struct GNUNET_HELLO_Address *address,
1862 struct GNUNET_ATS_Session *session, 1871 struct GNUNET_ATS_Session *session,
1863 enum GNUNET_NetworkType scope) 1872 enum GNUNET_NetworkType scope)
1864{ 1873{
1865 struct GNUNET_ATS_Properties prop; 1874 struct GNUNET_ATS_Properties prop;
1866 1875
1867 if (NULL == address) 1876 if (NULL == address)
1868 { 1877 {
1869 GNUNET_break(0); 1878 GNUNET_break (0);
1870 return; 1879 return;
1871 } 1880 }
1872 if (NULL == session) 1881 if (NULL == session)
1873 { 1882 {
1874 GNUNET_break(0); 1883 GNUNET_break (0);
1875 return; 1884 return;
1876 } 1885 }
1877 GNUNET_log( 1886 GNUNET_log (
1878 GNUNET_ERROR_TYPE_INFO, 1887 GNUNET_ERROR_TYPE_INFO,
1879 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", 1888 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1880 address->transport_name, 1889 address->transport_name,
1881 GNUNET_i2s(&address->peer), 1890 GNUNET_i2s (&address->peer),
1882 GST_plugins_a2s(address)); 1891 GST_plugins_a2s (address));
1883 if (GNUNET_YES == 1892 if (GNUNET_YES ==
1884 GNUNET_HELLO_address_check_option(address, 1893 GNUNET_HELLO_address_check_option (address,
1885 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1894 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1886 { 1895 {
1887 /* inbound is always new, but outbound MAY already be known, but 1896 /* inbound is always new, but outbound MAY already be known, but
1888 for example for UNIX, we have symmetric connections and thus we 1897 for example for UNIX, we have symmetric connections and thus we
1889 may not know the address yet; add if necessary! */ 1898 may not know the address yet; add if necessary! */
1890 /* FIXME: maybe change API here so we just pass scope? */ 1899 /* FIXME: maybe change API here so we just pass scope? */
1891 memset(&prop, 0, sizeof(prop)); 1900 memset (&prop, 0, sizeof(prop));
1892 GNUNET_break(GNUNET_NT_UNSPECIFIED != scope); 1901 GNUNET_break (GNUNET_NT_UNSPECIFIED != scope);
1893 prop.scope = scope; 1902 prop.scope = scope;
1894 GST_ats_add_inbound_address(address, session, &prop); 1903 GST_ats_add_inbound_address (address, session, &prop);
1895 } 1904 }
1896 /* Do blacklist check if communication with this peer is allowed */ 1905 /* Do blacklist check if communication with this peer is allowed */
1897 (void)GST_blacklist_test_allowed(&address->peer, 1906 (void) GST_blacklist_test_allowed (&address->peer,
1898 address->transport_name, 1907 address->transport_name,
1899 &plugin_env_session_start_bl_check_cont, 1908 &plugin_env_session_start_bl_check_cont,
1900 NULL, 1909 NULL,
1901 address, 1910 address,
1902 session); 1911 session);
1903} 1912}
1904 1913
1905 1914
@@ -1922,51 +1931,52 @@ plugin_env_session_start(void *cls,
1922 * @param ats_count number of @a ats elements 1931 * @param ats_count number of @a ats elements
1923 */ 1932 */
1924static void 1933static void
1925ats_request_address_change(void *cls, 1934ats_request_address_change (void *cls,
1926 const struct GNUNET_PeerIdentity *peer, 1935 const struct GNUNET_PeerIdentity *peer,
1927 const struct GNUNET_HELLO_Address *address, 1936 const struct GNUNET_HELLO_Address *address,
1928 struct GNUNET_ATS_Session *session, 1937 struct GNUNET_ATS_Session *session,
1929 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1938 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1930 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 1939 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
1931{ 1940{
1932 uint32_t bw_in = ntohl(bandwidth_in.value__); 1941 uint32_t bw_in = ntohl (bandwidth_in.value__);
1933 uint32_t bw_out = ntohl(bandwidth_out.value__); 1942 uint32_t bw_out = ntohl (bandwidth_out.value__);
1934 1943
1935 if (NULL == peer) 1944 if (NULL == peer)
1936 { 1945 {
1937 /* ATS service died, all suggestions become invalid! 1946 /* ATS service died, all suggestions become invalid!
1938 (but we'll keep using the allocations for a little 1947 (but we'll keep using the allocations for a little
1939 while, to keep going while ATS restarts) */ 1948 while, to keep going while ATS restarts) */
1940 /* FIXME: We should drop all 1949 /* FIXME: We should drop all
1941 connections now, as ATS won't explicitly tell 1950 connections now, as ATS won't explicitly tell
1942 us and be unaware of ongoing resource allocations! */ 1951 us and be unaware of ongoing resource allocations! */
1943 return; 1952 return;
1944 } 1953 }
1945 /* ATS tells me to disconnect from peer */ 1954 /* ATS tells me to disconnect from peer */
1946 if ((0 == bw_in) && (0 == bw_out)) 1955 if ((0 == bw_in) && (0 == bw_out))
1947 { 1956 {
1948 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1957 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1949 "ATS tells me to disconnect from peer `%s'\n", 1958 "ATS tells me to disconnect from peer `%s'\n",
1950 GNUNET_i2s(peer)); 1959 GNUNET_i2s (peer));
1951 GST_neighbours_force_disconnect(peer); 1960 GST_neighbours_force_disconnect (peer);
1952 return; 1961 return;
1953 } 1962 }
1954 GNUNET_assert(NULL != address); 1963 GNUNET_assert (NULL != address);
1955 GNUNET_STATISTICS_update(GST_stats, 1964 GNUNET_STATISTICS_update (GST_stats,
1956 "# ATS suggestions received", 1965 "# ATS suggestions received",
1957 1, 1966 1,
1958 GNUNET_NO); 1967 GNUNET_NO);
1959 GST_neighbours_switch_to_address(address, 1968 GST_neighbours_switch_to_address (address,
1960 session, 1969 session,
1961 bandwidth_in, 1970 bandwidth_in,
1962 bandwidth_out); 1971 bandwidth_out);
1963} 1972}
1964 1973
1965 1974
1966/** 1975/**
1967 * Closure for #test_connection_ok(). 1976 * Closure for #test_connection_ok().
1968 */ 1977 */
1969struct TestConnectionContext { 1978struct TestConnectionContext
1979{
1970 /** 1980 /**
1971 * Is this the first neighbour we're checking? 1981 * Is this the first neighbour we're checking?
1972 */ 1982 */
@@ -1991,19 +2001,19 @@ struct TestConnectionContext {
1991 * #GNUNET_NO if we must shutdown the connection 2001 * #GNUNET_NO if we must shutdown the connection
1992 */ 2002 */
1993static void 2003static void
1994confirm_or_drop_neighbour(void *cls, 2004confirm_or_drop_neighbour (void *cls,
1995 const struct GNUNET_PeerIdentity *peer, 2005 const struct GNUNET_PeerIdentity *peer,
1996 const struct GNUNET_HELLO_Address *address, 2006 const struct GNUNET_HELLO_Address *address,
1997 struct GNUNET_ATS_Session *session, 2007 struct GNUNET_ATS_Session *session,
1998 int allowed) 2008 int allowed)
1999{ 2009{
2000 if (GNUNET_OK == allowed) 2010 if (GNUNET_OK == allowed)
2001 return; /* we're done */ 2011 return; /* we're done */
2002 GNUNET_STATISTICS_update(GST_stats, 2012 GNUNET_STATISTICS_update (GST_stats,
2003 gettext_noop("# disconnects due to blacklist"), 2013 gettext_noop ("# disconnects due to blacklist"),
2004 1, 2014 1,
2005 GNUNET_NO); 2015 GNUNET_NO);
2006 GST_neighbours_force_disconnect(peer); 2016 GST_neighbours_force_disconnect (peer);
2007} 2017}
2008 2018
2009 2019
@@ -2020,31 +2030,31 @@ confirm_or_drop_neighbour(void *cls,
2020 * @param bandwidth_out bandwidth assigned outbound 2030 * @param bandwidth_out bandwidth assigned outbound
2021 */ 2031 */
2022static void 2032static void
2023test_connection_ok(void *cls, 2033test_connection_ok (void *cls,
2024 const struct GNUNET_PeerIdentity *peer, 2034 const struct GNUNET_PeerIdentity *peer,
2025 const struct GNUNET_HELLO_Address *address, 2035 const struct GNUNET_HELLO_Address *address,
2026 enum GNUNET_TRANSPORT_PeerState state, 2036 enum GNUNET_TRANSPORT_PeerState state,
2027 struct GNUNET_TIME_Absolute state_timeout, 2037 struct GNUNET_TIME_Absolute state_timeout,
2028 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2038 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2029 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2039 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2030{ 2040{
2031 struct TestConnectionContext *tcc = cls; 2041 struct TestConnectionContext *tcc = cls;
2032 struct GST_BlacklistCheck *bc; 2042 struct GST_BlacklistCheck *bc;
2033 2043
2034 bc = GNUNET_new(struct GST_BlacklistCheck); 2044 bc = GNUNET_new (struct GST_BlacklistCheck);
2035 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); 2045 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2036 bc->peer = *peer; 2046 bc->peer = *peer;
2037 bc->address = GNUNET_HELLO_address_copy(address); 2047 bc->address = GNUNET_HELLO_address_copy (address);
2038 bc->cont = &confirm_or_drop_neighbour; 2048 bc->cont = &confirm_or_drop_neighbour;
2039 bc->cont_cls = NULL; 2049 bc->cont_cls = NULL;
2040 bc->bl_pos = tcc->tc; 2050 bc->bl_pos = tcc->tc;
2041 if (GNUNET_YES == tcc->first) 2051 if (GNUNET_YES == tcc->first)
2042 { 2052 {
2043 /* all would wait for the same client, no need to 2053 /* all would wait for the same client, no need to
2044 * create more than just the first task right now */ 2054 * create more than just the first task right now */
2045 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2055 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2046 tcc->first = GNUNET_NO; 2056 tcc->first = GNUNET_NO;
2047 } 2057 }
2048} 2058}
2049 2059
2050 2060
@@ -2057,26 +2067,26 @@ test_connection_ok(void *cls,
2057 * @param message the blacklist-init message that was sent 2067 * @param message the blacklist-init message that was sent
2058 */ 2068 */
2059static void 2069static void
2060handle_client_blacklist_init(void *cls, 2070handle_client_blacklist_init (void *cls,
2061 const struct GNUNET_MessageHeader *message) 2071 const struct GNUNET_MessageHeader *message)
2062{ 2072{
2063 struct TransportClient *tc = cls; 2073 struct TransportClient *tc = cls;
2064 struct TestConnectionContext tcc; 2074 struct TestConnectionContext tcc;
2065 2075
2066 if (CT_NONE != tc->type) 2076 if (CT_NONE != tc->type)
2067 { 2077 {
2068 GNUNET_break(0); 2078 GNUNET_break (0);
2069 GNUNET_SERVICE_client_drop(tc->client); 2079 GNUNET_SERVICE_client_drop (tc->client);
2070 return; 2080 return;
2071 } 2081 }
2072 GNUNET_SERVICE_client_mark_monitor(tc->client); 2082 GNUNET_SERVICE_client_mark_monitor (tc->client);
2073 tc->type = CT_BLACKLIST; 2083 tc->type = CT_BLACKLIST;
2074 tc->details.blacklist.call_receive_done = GNUNET_YES; 2084 tc->details.blacklist.call_receive_done = GNUNET_YES;
2075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); 2085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc);
2076 /* confirm that all existing connections are OK! */ 2086 /* confirm that all existing connections are OK! */
2077 tcc.tc = tc; 2087 tcc.tc = tc;
2078 tcc.first = GNUNET_YES; 2088 tcc.first = GNUNET_YES;
2079 GST_neighbours_iterate(&test_connection_ok, &tcc); 2089 GST_neighbours_iterate (&test_connection_ok, &tcc);
2080} 2090}
2081 2091
2082 2092
@@ -2089,13 +2099,13 @@ handle_client_blacklist_init(void *cls,
2089 * @return #GNUNET_OK (continue to iterate) 2099 * @return #GNUNET_OK (continue to iterate)
2090 */ 2100 */
2091static int 2101static int
2092free_blacklist_entry(void *cls, 2102free_blacklist_entry (void *cls,
2093 const struct GNUNET_PeerIdentity *key, 2103 const struct GNUNET_PeerIdentity *key,
2094 void *value) 2104 void *value)
2095{ 2105{
2096 char *be = value; 2106 char *be = value;
2097 2107
2098 GNUNET_free_non_null(be); 2108 GNUNET_free_non_null (be);
2099 return GNUNET_OK; 2109 return GNUNET_OK;
2100} 2110}
2101 2111
@@ -2107,12 +2117,12 @@ free_blacklist_entry(void *cls,
2107 * @param message containing information 2117 * @param message containing information
2108 */ 2118 */
2109static void 2119static void
2110handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm) 2120handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm)
2111{ 2121{
2112 struct TransportClient *tc = cls; 2122 struct TransportClient *tc = cls;
2113 2123
2114 GST_manipulation_set_metric(tm); 2124 GST_manipulation_set_metric (tm);
2115 GNUNET_SERVICE_client_continue(tc->client); 2125 GNUNET_SERVICE_client_continue (tc->client);
2116} 2126}
2117 2127
2118 2128
@@ -2123,58 +2133,58 @@ handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm)
2123 * @param cls closure, unused 2133 * @param cls closure, unused
2124 */ 2134 */
2125static void 2135static void
2126shutdown_task(void *cls) 2136shutdown_task (void *cls)
2127{ 2137{
2128 struct AddressToStringContext *cur; 2138 struct AddressToStringContext *cur;
2129 2139
2130 GST_neighbours_stop(); 2140 GST_neighbours_stop ();
2131 GST_plugins_unload(); 2141 GST_plugins_unload ();
2132 GST_validation_stop(); 2142 GST_validation_stop ();
2133 GST_ats_done(); 2143 GST_ats_done ();
2134 GNUNET_ATS_scheduling_done(GST_ats); 2144 GNUNET_ATS_scheduling_done (GST_ats);
2135 GST_ats = NULL; 2145 GST_ats = NULL;
2136 GNUNET_ATS_connectivity_done(GST_ats_connect); 2146 GNUNET_ATS_connectivity_done (GST_ats_connect);
2137 GST_ats_connect = NULL; 2147 GST_ats_connect = NULL;
2138 GNUNET_NT_scanner_done(GST_is); 2148 GNUNET_NT_scanner_done (GST_is);
2139 GST_is = NULL; 2149 GST_is = NULL;
2140 while (NULL != (cur = a2s_head)) 2150 while (NULL != (cur = a2s_head))
2141 { 2151 {
2142 GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, cur); 2152 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur);
2143 GNUNET_free(cur); 2153 GNUNET_free (cur);
2144 } 2154 }
2145 if (NULL != plugin_nc) 2155 if (NULL != plugin_nc)
2146 { 2156 {
2147 GNUNET_notification_context_destroy(plugin_nc); 2157 GNUNET_notification_context_destroy (plugin_nc);
2148 plugin_nc = NULL; 2158 plugin_nc = NULL;
2149 } 2159 }
2150 GNUNET_CONTAINER_multipeermap_destroy(active_stccs); 2160 GNUNET_CONTAINER_multipeermap_destroy (active_stccs);
2151 active_stccs = NULL; 2161 active_stccs = NULL;
2152 if (NULL != blacklist) 2162 if (NULL != blacklist)
2153 { 2163 {
2154 GNUNET_CONTAINER_multipeermap_iterate(blacklist, 2164 GNUNET_CONTAINER_multipeermap_iterate (blacklist,
2155 &free_blacklist_entry, 2165 &free_blacklist_entry,
2156 NULL); 2166 NULL);
2157 GNUNET_CONTAINER_multipeermap_destroy(blacklist); 2167 GNUNET_CONTAINER_multipeermap_destroy (blacklist);
2158 blacklist = NULL; 2168 blacklist = NULL;
2159 } 2169 }
2160 GST_hello_stop(); 2170 GST_hello_stop ();
2161 GST_manipulation_stop(); 2171 GST_manipulation_stop ();
2162 2172
2163 if (NULL != GST_peerinfo) 2173 if (NULL != GST_peerinfo)
2164 { 2174 {
2165 GNUNET_PEERINFO_disconnect(GST_peerinfo); 2175 GNUNET_PEERINFO_disconnect (GST_peerinfo);
2166 GST_peerinfo = NULL; 2176 GST_peerinfo = NULL;
2167 } 2177 }
2168 if (NULL != GST_stats) 2178 if (NULL != GST_stats)
2169 { 2179 {
2170 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO); 2180 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
2171 GST_stats = NULL; 2181 GST_stats = NULL;
2172 } 2182 }
2173 if (NULL != GST_my_private_key) 2183 if (NULL != GST_my_private_key)
2174 { 2184 {
2175 GNUNET_free(GST_my_private_key); 2185 GNUNET_free (GST_my_private_key);
2176 GST_my_private_key = NULL; 2186 GST_my_private_key = NULL;
2177 } 2187 }
2178} 2188}
2179 2189
2180 2190
@@ -2184,7 +2194,7 @@ shutdown_task(void *cls)
2184 * @param cls the `struct GST_BlacklistCheck *` 2194 * @param cls the `struct GST_BlacklistCheck *`
2185 */ 2195 */
2186static void 2196static void
2187do_blacklist_check(void *cls) 2197do_blacklist_check (void *cls)
2188{ 2198{
2189 struct GST_BlacklistCheck *bc = cls; 2199 struct GST_BlacklistCheck *bc = cls;
2190 struct TransportClient *tc; 2200 struct TransportClient *tc;
@@ -2193,34 +2203,34 @@ do_blacklist_check(void *cls)
2193 2203
2194 bc->task = NULL; 2204 bc->task = NULL;
2195 while (NULL != (tc = bc->bl_pos)) 2205 while (NULL != (tc = bc->bl_pos))
2196 { 2206 {
2197 if (CT_BLACKLIST == tc->type) 2207 if (CT_BLACKLIST == tc->type)
2198 break; 2208 break;
2199 bc->bl_pos = tc->next; 2209 bc->bl_pos = tc->next;
2200 } 2210 }
2201 if (NULL == tc) 2211 if (NULL == tc)
2202 { 2212 {
2203 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2204 "No other blacklist clients active, will allow neighbour `%s'\n", 2214 "No other blacklist clients active, will allow neighbour `%s'\n",
2205 GNUNET_i2s(&bc->peer)); 2215 GNUNET_i2s (&bc->peer));
2206 2216
2207 bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); 2217 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK);
2208 GST_blacklist_test_cancel(bc); 2218 GST_blacklist_test_cancel (bc);
2209 return; 2219 return;
2210 } 2220 }
2211 if ((NULL != tc->details.blacklist.bc) || 2221 if ((NULL != tc->details.blacklist.bc) ||
2212 (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) 2222 (GNUNET_NO != tc->details.blacklist.waiting_for_reply))
2213 return; /* someone else busy with this client */ 2223 return; /* someone else busy with this client */
2214 tc->details.blacklist.bc = bc; 2224 tc->details.blacklist.bc = bc;
2215 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); 2225 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2216 bm->is_allowed = htonl(0); 2226 bm->is_allowed = htonl (0);
2217 bm->peer = bc->peer; 2227 bm->peer = bc->peer;
2218 GNUNET_MQ_send(tc->mq, env); 2228 GNUNET_MQ_send (tc->mq, env);
2219 if (GNUNET_YES == tc->details.blacklist.call_receive_done) 2229 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2220 { 2230 {
2221 tc->details.blacklist.call_receive_done = GNUNET_NO; 2231 tc->details.blacklist.call_receive_done = GNUNET_NO;
2222 GNUNET_SERVICE_client_continue(tc->client); 2232 GNUNET_SERVICE_client_continue (tc->client);
2223 } 2233 }
2224 tc->details.blacklist.waiting_for_reply = GNUNET_YES; 2234 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2225} 2235}
2226 2236
@@ -2232,62 +2242,62 @@ do_blacklist_check(void *cls)
2232 * @param msg the blacklist-reply message that was sent 2242 * @param msg the blacklist-reply message that was sent
2233 */ 2243 */
2234static void 2244static void
2235handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg) 2245handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg)
2236{ 2246{
2237 struct TransportClient *tc = cls; 2247 struct TransportClient *tc = cls;
2238 struct GST_BlacklistCheck *bc; 2248 struct GST_BlacklistCheck *bc;
2239 2249
2240 if (CT_BLACKLIST != tc->type) 2250 if (CT_BLACKLIST != tc->type)
2241 { 2251 {
2242 GNUNET_break(0); 2252 GNUNET_break (0);
2243 GNUNET_SERVICE_client_drop(tc->client); 2253 GNUNET_SERVICE_client_drop (tc->client);
2244 return; 2254 return;
2245 } 2255 }
2246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2247 "Blacklist client %p sent reply for `%s'\n", 2257 "Blacklist client %p sent reply for `%s'\n",
2248 tc, 2258 tc,
2249 GNUNET_i2s(&msg->peer)); 2259 GNUNET_i2s (&msg->peer));
2250 bc = tc->details.blacklist.bc; 2260 bc = tc->details.blacklist.bc;
2251 tc->details.blacklist.bc = NULL; 2261 tc->details.blacklist.bc = NULL;
2252 tc->details.blacklist.waiting_for_reply = GNUNET_NO; 2262 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2253 tc->details.blacklist.call_receive_done = GNUNET_YES; 2263 tc->details.blacklist.call_receive_done = GNUNET_YES;
2254 if (NULL != bc) 2264 if (NULL != bc)
2265 {
2266 /* only run this if the blacklist check has not been
2267 * cancelled in the meantime... */
2268 GNUNET_assert (bc->bl_pos == tc);
2269 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2270 {
2271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2272 "Blacklist check failed, peer not allowed\n");
2273 /* For the duration of the continuation, make the ongoing
2274 check invisible (to avoid double-cancellation); then
2275 add it back again so we can re-use GST_blacklist_test_cancel() */
2276 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2277 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2278 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2279 GST_blacklist_test_cancel (bc);
2280 tc->details.blacklist.call_receive_done = GNUNET_NO;
2281 GNUNET_SERVICE_client_continue (tc->client);
2282 return;
2283 }
2284 else
2255 { 2285 {
2256 /* only run this if the blacklist check has not been 2286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2257 * cancelled in the meantime... */ 2287 "Blacklist check succeeded, continuing with checks\n");
2258 GNUNET_assert(bc->bl_pos == tc); 2288 tc->details.blacklist.call_receive_done = GNUNET_NO;
2259 if (ntohl(msg->is_allowed) == GNUNET_SYSERR) 2289 GNUNET_SERVICE_client_continue (tc->client);
2260 { 2290 bc->bl_pos = tc->next;
2261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2291 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2262 "Blacklist check failed, peer not allowed\n");
2263 /* For the duration of the continuation, make the ongoing
2264 check invisible (to avoid double-cancellation); then
2265 add it back again so we can re-use GST_blacklist_test_cancel() */
2266 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
2267 bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2268 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc);
2269 GST_blacklist_test_cancel(bc);
2270 tc->details.blacklist.call_receive_done = GNUNET_NO;
2271 GNUNET_SERVICE_client_continue(tc->client);
2272 return;
2273 }
2274 else
2275 {
2276 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2277 "Blacklist check succeeded, continuing with checks\n");
2278 tc->details.blacklist.call_receive_done = GNUNET_NO;
2279 GNUNET_SERVICE_client_continue(tc->client);
2280 bc->bl_pos = tc->next;
2281 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
2282 }
2283 } 2292 }
2293 }
2284 /* check if any other blacklist checks are waiting for this blacklister */ 2294 /* check if any other blacklist checks are waiting for this blacklister */
2285 for (bc = bc_head; bc != NULL; bc = bc->next) 2295 for (bc = bc_head; bc != NULL; bc = bc->next)
2286 if ((bc->bl_pos == tc) && (NULL == bc->task)) 2296 if ((bc->bl_pos == tc) && (NULL == bc->task))
2287 { 2297 {
2288 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2298 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2289 break; 2299 break;
2290 } 2300 }
2291} 2301}
2292 2302
2293 2303
@@ -2298,32 +2308,32 @@ handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg)
2298 * @param transport_name transport to blacklist for this peer, NULL for all 2308 * @param transport_name transport to blacklist for this peer, NULL for all
2299 */ 2309 */
2300void 2310void
2301GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer, 2311GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2302 const char *transport_name) 2312 const char *transport_name)
2303{ 2313{
2304 char *transport = NULL; 2314 char *transport = NULL;
2305 2315
2306 if (NULL != transport_name) 2316 if (NULL != transport_name)
2307 { 2317 {
2308 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2309 "Adding peer `%s' with plugin `%s' to blacklist\n", 2319 "Adding peer `%s' with plugin `%s' to blacklist\n",
2310 GNUNET_i2s(peer), 2320 GNUNET_i2s (peer),
2311 transport_name); 2321 transport_name);
2312 transport = GNUNET_strdup(transport_name); 2322 transport = GNUNET_strdup (transport_name);
2313 } 2323 }
2314 else 2324 else
2315 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2325 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2316 "Adding peer `%s' with all plugins to blacklist\n", 2326 "Adding peer `%s' with all plugins to blacklist\n",
2317 GNUNET_i2s(peer)); 2327 GNUNET_i2s (peer));
2318 if (NULL == blacklist) 2328 if (NULL == blacklist)
2319 blacklist = 2329 blacklist =
2320 GNUNET_CONTAINER_multipeermap_create(TRANSPORT_BLACKLIST_HT_SIZE, 2330 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE,
2321 GNUNET_NO); 2331 GNUNET_NO);
2322 2332
2323 GNUNET_CONTAINER_multipeermap_put(blacklist, 2333 GNUNET_CONTAINER_multipeermap_put (blacklist,
2324 peer, 2334 peer,
2325 transport, 2335 transport,
2326 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2336 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2327} 2337}
2328 2338
2329 2339
@@ -2334,27 +2344,27 @@ GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer,
2334 * @param session session used to abort matching checks 2344 * @param session session used to abort matching checks
2335 */ 2345 */
2336void 2346void
2337GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address, 2347GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2338 struct GNUNET_ATS_Session *session) 2348 struct GNUNET_ATS_Session *session)
2339{ 2349{
2340 struct GST_BlacklistCheck *bc; 2350 struct GST_BlacklistCheck *bc;
2341 struct GST_BlacklistCheck *n; 2351 struct GST_BlacklistCheck *n;
2342 2352
2343 n = bc_head; 2353 n = bc_head;
2344 while (NULL != (bc = n)) 2354 while (NULL != (bc = n))
2355 {
2356 n = bc->next;
2357 if ((bc->session == session) &&
2358 (0 == GNUNET_HELLO_address_cmp (bc->address, address)))
2345 { 2359 {
2346 n = bc->next; 2360 bc->cont (bc->cont_cls,
2347 if ((bc->session == session) && 2361 &bc->peer,
2348 (0 == GNUNET_HELLO_address_cmp(bc->address, address))) 2362 bc->address,
2349 { 2363 bc->session,
2350 bc->cont(bc->cont_cls, 2364 GNUNET_SYSERR);
2351 &bc->peer, 2365 GST_blacklist_test_cancel (bc);
2352 bc->address,
2353 bc->session,
2354 GNUNET_SYSERR);
2355 GST_blacklist_test_cancel(bc);
2356 }
2357 } 2366 }
2367 }
2358} 2368}
2359 2369
2360 2370
@@ -2368,7 +2378,7 @@ GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address,
2368 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches 2378 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2369 */ 2379 */
2370static int 2380static int
2371test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 2381test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2372{ 2382{
2373 const char *transport_name = cls; 2383 const char *transport_name = cls;
2374 char *be = value; 2384 char *be = value;
@@ -2382,21 +2392,21 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2382 * 2392 *
2383 */ 2393 */
2384 2394
2385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2386 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", 2396 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2387 GNUNET_i2s(key), 2397 GNUNET_i2s (key),
2388 (NULL == transport_name) ? "unspecified" : transport_name, 2398 (NULL == transport_name) ? "unspecified" : transport_name,
2389 (NULL == be) ? "all plugins" : be); 2399 (NULL == be) ? "all plugins" : be);
2390 /* all plugins for this peer were blacklisted: disallow */ 2400 /* all plugins for this peer were blacklisted: disallow */
2391 if (NULL == value) 2401 if (NULL == value)
2392 return GNUNET_NO; 2402 return GNUNET_NO;
2393 2403
2394 /* blacklist check for specific transport */ 2404 /* blacklist check for specific transport */
2395 if ((NULL != transport_name) && (NULL != value)) 2405 if ((NULL != transport_name) && (NULL != value))
2396 { 2406 {
2397 if (0 == strcmp(transport_name, be)) 2407 if (0 == strcmp (transport_name, be))
2398 return GNUNET_NO; /* plugin is blacklisted! */ 2408 return GNUNET_NO; /* plugin is blacklisted! */
2399 } 2409 }
2400 return GNUNET_OK; 2410 return GNUNET_OK;
2401} 2411}
2402 2412
@@ -2414,70 +2424,70 @@ test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2414 * was made instantly and @a cont was already called 2424 * was made instantly and @a cont was already called
2415 */ 2425 */
2416struct GST_BlacklistCheck * 2426struct GST_BlacklistCheck *
2417GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer, 2427GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2418 const char *transport_name, 2428 const char *transport_name,
2419 GST_BlacklistTestContinuation cont, 2429 GST_BlacklistTestContinuation cont,
2420 void *cont_cls, 2430 void *cont_cls,
2421 const struct GNUNET_HELLO_Address *address, 2431 const struct GNUNET_HELLO_Address *address,
2422 struct GNUNET_ATS_Session *session) 2432 struct GNUNET_ATS_Session *session)
2423{ 2433{
2424 struct GST_BlacklistCheck *bc; 2434 struct GST_BlacklistCheck *bc;
2425 struct TransportClient *tc; 2435 struct TransportClient *tc;
2426 2436
2427 GNUNET_assert(NULL != peer); 2437 GNUNET_assert (NULL != peer);
2428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2429 "Blacklist check for peer `%s':%s\n", 2439 "Blacklist check for peer `%s':%s\n",
2430 GNUNET_i2s(peer), 2440 GNUNET_i2s (peer),
2431 (NULL != transport_name) ? transport_name : "unspecified"); 2441 (NULL != transport_name) ? transport_name : "unspecified");
2432 2442
2433 /* Check local blacklist by iterating over hashmap 2443 /* Check local blacklist by iterating over hashmap
2434 * If iteration is aborted, we found a matching blacklist entry */ 2444 * If iteration is aborted, we found a matching blacklist entry */
2435 if ((NULL != blacklist) && 2445 if ((NULL != blacklist) &&
2436 (GNUNET_SYSERR == 2446 (GNUNET_SYSERR ==
2437 GNUNET_CONTAINER_multipeermap_get_multiple(blacklist, 2447 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist,
2438 peer, 2448 peer,
2439 &test_blacklisted, 2449 &test_blacklisted,
2440 (void *)transport_name))) 2450 (void *) transport_name)))
2441 { 2451 {
2442 /* Disallowed by config, disapprove instantly */ 2452 /* Disallowed by config, disapprove instantly */
2443 GNUNET_STATISTICS_update(GST_stats, 2453 GNUNET_STATISTICS_update (GST_stats,
2444 gettext_noop("# disconnects due to blacklist"), 2454 gettext_noop ("# disconnects due to blacklist"),
2445 1, 2455 1,
2446 GNUNET_NO); 2456 GNUNET_NO);
2447 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2457 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2448 _("Disallowing connection to peer `%s' on transport %s\n"), 2458 _ ("Disallowing connection to peer `%s' on transport %s\n"),
2449 GNUNET_i2s(peer), 2459 GNUNET_i2s (peer),
2450 (NULL != transport_name) ? transport_name : "unspecified"); 2460 (NULL != transport_name) ? transport_name : "unspecified");
2451 if (NULL != cont) 2461 if (NULL != cont)
2452 cont(cont_cls, peer, address, session, GNUNET_NO); 2462 cont (cont_cls, peer, address, session, GNUNET_NO);
2453 return NULL; 2463 return NULL;
2454 } 2464 }
2455 2465
2456 for (tc = clients_head; NULL != tc; tc = tc->next) 2466 for (tc = clients_head; NULL != tc; tc = tc->next)
2457 if (CT_BLACKLIST == tc->type) 2467 if (CT_BLACKLIST == tc->type)
2458 break; 2468 break;
2459 if (NULL == tc) 2469 if (NULL == tc)
2460 { 2470 {
2461 /* no blacklist clients, approve instantly */ 2471 /* no blacklist clients, approve instantly */
2462 if (NULL != cont) 2472 if (NULL != cont)
2463 cont(cont_cls, peer, address, session, GNUNET_OK); 2473 cont (cont_cls, peer, address, session, GNUNET_OK);
2464 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2465 "Allowing connection to peer `%s' %s\n", 2475 "Allowing connection to peer `%s' %s\n",
2466 GNUNET_i2s(peer), 2476 GNUNET_i2s (peer),
2467 (NULL != transport_name) ? transport_name : ""); 2477 (NULL != transport_name) ? transport_name : "");
2468 return NULL; 2478 return NULL;
2469 } 2479 }
2470 2480
2471 /* need to query blacklist clients */ 2481 /* need to query blacklist clients */
2472 bc = GNUNET_new(struct GST_BlacklistCheck); 2482 bc = GNUNET_new (struct GST_BlacklistCheck);
2473 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc); 2483 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2474 bc->peer = *peer; 2484 bc->peer = *peer;
2475 bc->address = GNUNET_HELLO_address_copy(address); 2485 bc->address = GNUNET_HELLO_address_copy (address);
2476 bc->session = session; 2486 bc->session = session;
2477 bc->cont = cont; 2487 bc->cont = cont;
2478 bc->cont_cls = cont_cls; 2488 bc->cont_cls = cont_cls;
2479 bc->bl_pos = tc; 2489 bc->bl_pos = tc;
2480 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc); 2490 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
2481 return bc; 2491 return bc;
2482} 2492}
2483 2493
@@ -2488,25 +2498,25 @@ GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer,
2488 * @param bc check to cancel 2498 * @param bc check to cancel
2489 */ 2499 */
2490void 2500void
2491GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc) 2501GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2492{ 2502{
2493 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc); 2503 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2494 if (NULL != bc->bl_pos) 2504 if (NULL != bc->bl_pos)
2505 {
2506 if ((CT_BLACKLIST == bc->bl_pos->type) &&
2507 (bc->bl_pos->details.blacklist.bc == bc))
2495 { 2508 {
2496 if ((CT_BLACKLIST == bc->bl_pos->type) && 2509 /* we're at the head of the queue, remove us! */
2497 (bc->bl_pos->details.blacklist.bc == bc)) 2510 bc->bl_pos->details.blacklist.bc = NULL;
2498 {
2499 /* we're at the head of the queue, remove us! */
2500 bc->bl_pos->details.blacklist.bc = NULL;
2501 }
2502 } 2511 }
2512 }
2503 if (NULL != bc->task) 2513 if (NULL != bc->task)
2504 { 2514 {
2505 GNUNET_SCHEDULER_cancel(bc->task); 2515 GNUNET_SCHEDULER_cancel (bc->task);
2506 bc->task = NULL; 2516 bc->task = NULL;
2507 } 2517 }
2508 GNUNET_free_non_null(bc->address); 2518 GNUNET_free_non_null (bc->address);
2509 GNUNET_free(bc); 2519 GNUNET_free (bc);
2510} 2520}
2511 2521
2512 2522
@@ -2519,10 +2529,10 @@ GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc)
2519 * @param value value of the option 2529 * @param value value of the option
2520 */ 2530 */
2521static void 2531static void
2522blacklist_cfg_iter(void *cls, 2532blacklist_cfg_iter (void *cls,
2523 const char *section, 2533 const char *section,
2524 const char *option, 2534 const char *option,
2525 const char *value) 2535 const char *value)
2526{ 2536{
2527 unsigned int *res = cls; 2537 unsigned int *res = cls;
2528 struct GNUNET_PeerIdentity peer; 2538 struct GNUNET_PeerIdentity peer;
@@ -2530,32 +2540,32 @@ blacklist_cfg_iter(void *cls,
2530 char *pos; 2540 char *pos;
2531 2541
2532 if (GNUNET_OK != 2542 if (GNUNET_OK !=
2533 GNUNET_CRYPTO_eddsa_public_key_from_string(option, 2543 GNUNET_CRYPTO_eddsa_public_key_from_string (option,
2534 strlen(option), 2544 strlen (option),
2535 &peer.public_key)) 2545 &peer.public_key))
2536 return; 2546 return;
2537 2547
2538 if ((NULL == value) || (0 == strcmp(value, ""))) 2548 if ((NULL == value) || (0 == strcmp (value, "")))
2539 { 2549 {
2540 /* Blacklist whole peer */ 2550 /* Blacklist whole peer */
2541 GST_blacklist_add_peer(&peer, NULL); 2551 GST_blacklist_add_peer (&peer, NULL);
2542 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2552 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2543 _("Adding blacklisting entry for peer `%s'\n"), 2553 _ ("Adding blacklisting entry for peer `%s'\n"),
2544 GNUNET_i2s(&peer)); 2554 GNUNET_i2s (&peer));
2545 } 2555 }
2546 else 2556 else
2557 {
2558 plugs = GNUNET_strdup (value);
2559 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2547 { 2560 {
2548 plugs = GNUNET_strdup(value); 2561 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2549 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " ")) 2562 _ ("Adding blacklisting entry for peer `%s':`%s'\n"),
2550 { 2563 GNUNET_i2s (&peer),
2551 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2564 pos);
2552 _("Adding blacklisting entry for peer `%s':`%s'\n"), 2565 GST_blacklist_add_peer (&peer, pos);
2553 GNUNET_i2s(&peer),
2554 pos);
2555 GST_blacklist_add_peer(&peer, pos);
2556 }
2557 GNUNET_free(plugs);
2558 } 2566 }
2567 GNUNET_free (plugs);
2568 }
2559 (*res)++; 2569 (*res)++;
2560} 2570}
2561 2571
@@ -2567,23 +2577,23 @@ blacklist_cfg_iter(void *cls,
2567 * @param my_id my peer identity 2577 * @param my_id my peer identity
2568 */ 2578 */
2569static void 2579static void
2570read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg, 2580read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2571 const struct GNUNET_PeerIdentity *my_id) 2581 const struct GNUNET_PeerIdentity *my_id)
2572{ 2582{
2573 char cfg_sect[512]; 2583 char cfg_sect[512];
2574 unsigned int res = 0; 2584 unsigned int res = 0;
2575 2585
2576 GNUNET_snprintf(cfg_sect, 2586 GNUNET_snprintf (cfg_sect,
2577 sizeof(cfg_sect), 2587 sizeof(cfg_sect),
2578 "transport-blacklist-%s", 2588 "transport-blacklist-%s",
2579 GNUNET_i2s_full(my_id)); 2589 GNUNET_i2s_full (my_id));
2580 GNUNET_CONFIGURATION_iterate_section_values(cfg, 2590 GNUNET_CONFIGURATION_iterate_section_values (cfg,
2581 cfg_sect, 2591 cfg_sect,
2582 &blacklist_cfg_iter, 2592 &blacklist_cfg_iter,
2583 &res); 2593 &res);
2584 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2585 "Loaded %u blacklisting entries from configuration\n", 2595 "Loaded %u blacklisting entries from configuration\n",
2586 res); 2596 res);
2587} 2597}
2588 2598
2589 2599
@@ -2595,9 +2605,9 @@ read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg,
2595 * @param service the initialized service 2605 * @param service the initialized service
2596 */ 2606 */
2597static void 2607static void
2598run(void *cls, 2608run (void *cls,
2599 const struct GNUNET_CONFIGURATION_Handle *c, 2609 const struct GNUNET_CONFIGURATION_Handle *c,
2600 struct GNUNET_SERVICE_Handle *service) 2610 struct GNUNET_SERVICE_Handle *service)
2601{ 2611{
2602 char *keyfile; 2612 char *keyfile;
2603 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 2613 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
@@ -2608,70 +2618,70 @@ run(void *cls,
2608 2618
2609 /* setup globals */ 2619 /* setup globals */
2610 GST_cfg = c; 2620 GST_cfg = c;
2611 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c, 2621 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c,
2612 "PEER", 2622 "PEER",
2613 "PRIVATE_KEY", 2623 "PRIVATE_KEY",
2614 &keyfile)) 2624 &keyfile))
2615 { 2625 {
2616 GNUNET_log( 2626 GNUNET_log (
2617 GNUNET_ERROR_TYPE_ERROR, 2627 GNUNET_ERROR_TYPE_ERROR,
2618 _( 2628 _ (
2619 "Transport service is lacking key configuration settings. Exiting.\n")); 2629 "Transport service is lacking key configuration settings. Exiting.\n"));
2620 GNUNET_SCHEDULER_shutdown(); 2630 GNUNET_SCHEDULER_shutdown ();
2621 return; 2631 return;
2622 } 2632 }
2623 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(c, 2633 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c,
2624 "transport", 2634 "transport",
2625 "HELLO_EXPIRATION", 2635 "HELLO_EXPIRATION",
2626 &hello_expiration)) 2636 &hello_expiration))
2627 { 2637 {
2628 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 2638 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2629 } 2639 }
2630 pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile); 2640 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
2631 GNUNET_free(keyfile); 2641 GNUNET_free (keyfile);
2632 GNUNET_assert(NULL != pk); 2642 GNUNET_assert (NULL != pk);
2633 GST_my_private_key = pk; 2643 GST_my_private_key = pk;
2634 2644
2635 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg); 2645 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
2636 GST_peerinfo = GNUNET_PEERINFO_connect(GST_cfg); 2646 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg);
2637 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key, 2647 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key,
2638 &GST_my_identity.public_key); 2648 &GST_my_identity.public_key);
2639 GNUNET_assert(NULL != GST_my_private_key); 2649 GNUNET_assert (NULL != GST_my_private_key);
2640 2650
2641 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2651 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2642 "My identity is `%s'\n", 2652 "My identity is `%s'\n",
2643 GNUNET_i2s_full(&GST_my_identity)); 2653 GNUNET_i2s_full (&GST_my_identity));
2644 2654
2645 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 2655 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
2646 if (NULL == GST_peerinfo) 2656 if (NULL == GST_peerinfo)
2647 { 2657 {
2648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2649 _("Could not access PEERINFO service. Exiting.\n")); 2659 _ ("Could not access PEERINFO service. Exiting.\n"));
2650 GNUNET_SCHEDULER_shutdown(); 2660 GNUNET_SCHEDULER_shutdown ();
2651 return; 2661 return;
2652 } 2662 }
2653 2663
2654 max_fd_rlimit = 0; 2664 max_fd_rlimit = 0;
2655#if HAVE_GETRLIMIT 2665#if HAVE_GETRLIMIT
2656 { 2666 {
2657 struct rlimit r_file; 2667 struct rlimit r_file;
2658 2668
2659 if (0 == getrlimit(RLIMIT_NOFILE, &r_file)) 2669 if (0 == getrlimit (RLIMIT_NOFILE, &r_file))
2660 { 2670 {
2661 max_fd_rlimit = r_file.rlim_cur; 2671 max_fd_rlimit = r_file.rlim_cur;
2662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2663 "Maximum number of open files was: %u/%u\n", 2673 "Maximum number of open files was: %u/%u\n",
2664 (unsigned int)r_file.rlim_cur, 2674 (unsigned int) r_file.rlim_cur,
2665 (unsigned int)r_file.rlim_max); 2675 (unsigned int) r_file.rlim_max);
2666 } 2676 }
2667 max_fd_rlimit = 2677 max_fd_rlimit =
2668 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ 2678 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2669 } 2679 }
2670#endif 2680#endif
2671 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(GST_cfg, 2681 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg,
2672 "transport", 2682 "transport",
2673 "MAX_FD", 2683 "MAX_FD",
2674 &max_fd_cfg)) 2684 &max_fd_cfg))
2675 max_fd_cfg = max_fd_rlimit; 2685 max_fd_cfg = max_fd_rlimit;
2676 2686
2677 if (max_fd_cfg > max_fd_rlimit) 2687 if (max_fd_cfg > max_fd_rlimit)
@@ -2681,14 +2691,14 @@ run(void *cls,
2681 if (max_fd < DEFAULT_MAX_FDS) 2691 if (max_fd < DEFAULT_MAX_FDS)
2682 max_fd = DEFAULT_MAX_FDS; 2692 max_fd = DEFAULT_MAX_FDS;
2683 2693
2684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2685 "Limiting number of sockets to %u: validation %u, neighbors: %u\n", 2695 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2686 max_fd, 2696 max_fd,
2687 (max_fd / 3), 2697 (max_fd / 3),
2688 (max_fd / 3) * 2); 2698 (max_fd / 3) * 2);
2689 2699
2690 friend_only = 2700 friend_only =
2691 GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology", "FRIENDS-ONLY"); 2701 GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY");
2692 if (GNUNET_SYSERR == friend_only) 2702 if (GNUNET_SYSERR == friend_only)
2693 friend_only = GNUNET_NO; /* According to topology defaults */ 2703 friend_only = GNUNET_NO; /* According to topology defaults */
2694 /* start subsystems */ 2704 /* start subsystems */
@@ -2697,79 +2707,79 @@ run(void *cls,
2697 struct GNUNET_PeerIdentity dstj; 2707 struct GNUNET_PeerIdentity dstj;
2698 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; 2708 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0";
2699 2709
2700 GNUNET_assert( 2710 GNUNET_assert (
2701 GNUNET_OK == 2711 GNUNET_OK ==
2702 GNUNET_CRYPTO_eddsa_public_key_from_string(ds, 2712 GNUNET_CRYPTO_eddsa_public_key_from_string (ds,
2703 strlen(ds), 2713 strlen (ds),
2704 &dstj.public_key)); 2714 &dstj.public_key));
2705 GST_blacklist_add_peer(&dstj, NULL); 2715 GST_blacklist_add_peer (&dstj, NULL);
2706 } 2716 }
2707 read_blacklist_configuration(GST_cfg, &GST_my_identity); 2717 read_blacklist_configuration (GST_cfg, &GST_my_identity);
2708 GST_is = GNUNET_NT_scanner_init(); 2718 GST_is = GNUNET_NT_scanner_init ();
2709 GST_ats_connect = GNUNET_ATS_connectivity_init(GST_cfg); 2719 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
2710 GST_ats = 2720 GST_ats =
2711 GNUNET_ATS_scheduling_init(GST_cfg, &ats_request_address_change, NULL); 2721 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
2712 GST_ats_init(); 2722 GST_ats_init ();
2713 GST_manipulation_init(); 2723 GST_manipulation_init ();
2714 GST_plugins_load(&GST_manipulation_recv, 2724 GST_plugins_load (&GST_manipulation_recv,
2715 &plugin_env_address_change_notification, 2725 &plugin_env_address_change_notification,
2716 &plugin_env_session_start, 2726 &plugin_env_session_start,
2717 &plugin_env_session_end); 2727 &plugin_env_session_end);
2718 GST_hello_start(friend_only, &process_hello_update, NULL); 2728 GST_hello_start (friend_only, &process_hello_update, NULL);
2719 GST_neighbours_start((max_fd / 3) * 2); 2729 GST_neighbours_start ((max_fd / 3) * 2);
2720 active_stccs = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); 2730 active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
2721 plugin_nc = GNUNET_notification_context_create(0); 2731 plugin_nc = GNUNET_notification_context_create (0);
2722 GST_validation_start((max_fd / 3)); 2732 GST_validation_start ((max_fd / 3));
2723} 2733}
2724 2734
2725 2735
2726/** 2736/**
2727 * Define "main" method using service macro. 2737 * Define "main" method using service macro.
2728 */ 2738 */
2729GNUNET_SERVICE_MAIN( 2739GNUNET_SERVICE_MAIN (
2730 "transport", 2740 "transport",
2731 GNUNET_SERVICE_OPTION_NONE, 2741 GNUNET_SERVICE_OPTION_NONE,
2732 &run, 2742 &run,
2733 &client_connect_cb, 2743 &client_connect_cb,
2734 &client_disconnect_cb, 2744 &client_disconnect_cb,
2735 NULL, 2745 NULL,
2736 GNUNET_MQ_hd_fixed_size(client_start, 2746 GNUNET_MQ_hd_fixed_size (client_start,
2737 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 2747 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2738 struct StartMessage, 2748 struct StartMessage,
2739 NULL), 2749 NULL),
2740 GNUNET_MQ_hd_var_size(client_hello, 2750 GNUNET_MQ_hd_var_size (client_hello,
2741 GNUNET_MESSAGE_TYPE_HELLO, 2751 GNUNET_MESSAGE_TYPE_HELLO,
2742 struct GNUNET_MessageHeader, 2752 struct GNUNET_MessageHeader,
2743 NULL), 2753 NULL),
2744 GNUNET_MQ_hd_var_size(client_send, 2754 GNUNET_MQ_hd_var_size (client_send,
2745 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 2755 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2746 struct OutboundMessage, 2756 struct OutboundMessage,
2747 NULL), 2757 NULL),
2748 GNUNET_MQ_hd_var_size(client_address_to_string, 2758 GNUNET_MQ_hd_var_size (client_address_to_string,
2749 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 2759 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2750 struct AddressLookupMessage, 2760 struct AddressLookupMessage,
2751 NULL), 2761 NULL),
2752 GNUNET_MQ_hd_fixed_size(client_monitor_peers, 2762 GNUNET_MQ_hd_fixed_size (client_monitor_peers,
2753 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, 2763 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2754 struct PeerMonitorMessage, 2764 struct PeerMonitorMessage,
2755 NULL), 2765 NULL),
2756 GNUNET_MQ_hd_fixed_size(client_blacklist_init, 2766 GNUNET_MQ_hd_fixed_size (client_blacklist_init,
2757 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, 2767 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2758 struct GNUNET_MessageHeader, 2768 struct GNUNET_MessageHeader,
2759 NULL), 2769 NULL),
2760 GNUNET_MQ_hd_fixed_size(client_blacklist_reply, 2770 GNUNET_MQ_hd_fixed_size (client_blacklist_reply,
2761 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, 2771 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2762 struct BlacklistMessage, 2772 struct BlacklistMessage,
2763 NULL), 2773 NULL),
2764 GNUNET_MQ_hd_fixed_size(client_set_metric, 2774 GNUNET_MQ_hd_fixed_size (client_set_metric,
2765 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 2775 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2766 struct TrafficMetricMessage, 2776 struct TrafficMetricMessage,
2767 NULL), 2777 NULL),
2768 GNUNET_MQ_hd_fixed_size(client_monitor_plugins, 2778 GNUNET_MQ_hd_fixed_size (client_monitor_plugins,
2769 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, 2779 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2770 struct GNUNET_MessageHeader, 2780 struct GNUNET_MessageHeader,
2771 NULL), 2781 NULL),
2772 GNUNET_MQ_handler_end()); 2782 GNUNET_MQ_handler_end ());
2773 2783
2774 2784
2775/* end of file gnunet-service-transport.c */ 2785/* end of file gnunet-service-transport.c */