aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/gnunet-service-transport_neighbours.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4423
1 files changed, 2256 insertions, 2167 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 73d9a27f1..3de10d108 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -50,7 +50,8 @@
50 * Time we give plugin to transmit DISCONNECT message before the 50 * Time we give plugin to transmit DISCONNECT message before the
51 * neighbour entry self-destructs. 51 * neighbour entry self-destructs.
52 */ 52 */
53#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) 53#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply ( \
54 GNUNET_TIME_UNIT_MILLISECONDS, 500)
54 55
55/** 56/**
56 * How often must a peer violate bandwidth quotas before we start 57 * How often must a peer violate bandwidth quotas before we start
@@ -61,13 +62,15 @@
61/** 62/**
62 * How long are we willing to wait for a response from ATS before timing out? 63 * How long are we willing to wait for a response from ATS before timing out?
63 */ 64 */
64#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 65#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply ( \
66 GNUNET_TIME_UNIT_SECONDS, 5)
65 67
66/** 68/**
67 * How long are we willing to wait for an ACK from the other peer before 69 * How long are we willing to wait for an ACK from the other peer before
68 * giving up on our connect operation? 70 * giving up on our connect operation?
69 */ 71 */
70#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) 72#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply ( \
73 GNUNET_TIME_UNIT_SECONDS, 15)
71 74
72/** 75/**
73 * How long are we willing to wait for a successful reconnect if 76 * How long are we willing to wait for a successful reconnect if
@@ -85,7 +88,8 @@
85/** 88/**
86 * State describing which kind a reply this neighbour should send 89 * State describing which kind a reply this neighbour should send
87 */ 90 */
88enum GST_ACK_State { 91enum GST_ACK_State
92{
89 /** 93 /**
90 * We did not receive a SYN message for this neighbour 94 * We did not receive a SYN message for this neighbour
91 */ 95 */
@@ -115,7 +119,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
115 * a 'ACK'. Once the 'ACK' is received, both peers 119 * a 'ACK'. Once the 'ACK' is received, both peers
116 * should be connected. 120 * should be connected.
117 */ 121 */
118struct TransportSynMessage { 122struct TransportSynMessage
123{
119 /** 124 /**
120 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN 125 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN
121 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK 126 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK
@@ -143,7 +148,8 @@ struct TransportSynMessage {
143 * When the keep alive response with type is received, transport service 148 * When the keep alive response with type is received, transport service
144 * will call the respective plugin to update the session timeout 149 * will call the respective plugin to update the session timeout
145 */ 150 */
146struct GNUNET_ATS_SessionKeepAliveMessage { 151struct GNUNET_ATS_SessionKeepAliveMessage
152{
147 /** 153 /**
148 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or 154 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or
149 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE. 155 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
@@ -162,7 +168,8 @@ struct GNUNET_ATS_SessionKeepAliveMessage {
162 * the other peer should limit transmissions to the indicated 168 * the other peer should limit transmissions to the indicated
163 * quota. 169 * quota.
164 */ 170 */
165struct GNUNET_ATS_SessionQuotaMessage { 171struct GNUNET_ATS_SessionQuotaMessage
172{
166 /** 173 /**
167 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA. 174 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA.
168 */ 175 */
@@ -181,7 +188,8 @@ struct GNUNET_ATS_SessionQuotaMessage {
181 * notification, peers must not rely on always receiving disconnect 188 * notification, peers must not rely on always receiving disconnect
182 * messages. 189 * messages.
183 */ 190 */
184struct GNUNET_ATS_SessionDisconnectMessage { 191struct GNUNET_ATS_SessionDisconnectMessage
192{
185 /** 193 /**
186 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 194 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT
187 */ 195 */
@@ -224,7 +232,8 @@ GNUNET_NETWORK_STRUCT_END
224 * For each neighbour we keep a list of messages 232 * For each neighbour we keep a list of messages
225 * that we still want to transmit to the neighbour. 233 * that we still want to transmit to the neighbour.
226 */ 234 */
227struct MessageQueue { 235struct MessageQueue
236{
228 /** 237 /**
229 * This is a doubly linked list. 238 * This is a doubly linked list.
230 */ 239 */
@@ -266,7 +275,8 @@ struct MessageQueue {
266/** 275/**
267 * A possible address we could use to communicate with a neighbour. 276 * A possible address we could use to communicate with a neighbour.
268 */ 277 */
269struct NeighbourAddress { 278struct NeighbourAddress
279{
270 /** 280 /**
271 * Active session for this address. 281 * Active session for this address.
272 */ 282 */
@@ -309,7 +319,8 @@ struct NeighbourAddress {
309/** 319/**
310 * Entry in neighbours. 320 * Entry in neighbours.
311 */ 321 */
312struct NeighbourMapEntry { 322struct NeighbourMapEntry
323{
313 /** 324 /**
314 * Head of list of messages we would like to send to this peer; 325 * Head of list of messages we would like to send to this peer;
315 * must contain at most one message per client. 326 * must contain at most one message per client.
@@ -483,23 +494,23 @@ static struct GNUNET_SCHEDULER_Task *util_transmission_tk;
483 * @return corresponding human-readable string 494 * @return corresponding human-readable string
484 */ 495 */
485static char * 496static char *
486print_ack_state(enum GST_ACK_State s) 497print_ack_state (enum GST_ACK_State s)
487{ 498{
488 switch (s) 499 switch (s)
489 { 500 {
490 case ACK_UNDEFINED: 501 case ACK_UNDEFINED:
491 return "UNDEFINED"; 502 return "UNDEFINED";
492 503
493 case ACK_SEND_SYN_ACK: 504 case ACK_SEND_SYN_ACK:
494 return "SEND_SYN_ACK"; 505 return "SEND_SYN_ACK";
495 506
496 case ACK_SEND_ACK: 507 case ACK_SEND_ACK:
497 return "SEND_ACK"; 508 return "SEND_ACK";
498 509
499 default: 510 default:
500 GNUNET_break(0); 511 GNUNET_break (0);
501 return "N/A"; 512 return "N/A";
502 } 513 }
503} 514}
504 515
505 516
@@ -511,30 +522,30 @@ print_ack_state(enum GST_ACK_State s)
511 * @param n affected peer 522 * @param n affected peer
512 */ 523 */
513static void 524static void
514send_outbound_quota_to_clients(struct NeighbourMapEntry *n) 525send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
515{ 526{
516 struct QuotaSetMessage q_msg; 527 struct QuotaSetMessage q_msg;
517 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 528 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
518 529
519 if (!GNUNET_TRANSPORT_is_connected(n->state)) 530 if (! GNUNET_TRANSPORT_is_connected (n->state))
520 return; 531 return;
521#if IGNORE_INBOUND_QUOTA 532#if IGNORE_INBOUND_QUOTA
522 bandwidth_min = n->primary_address.bandwidth_out; 533 bandwidth_min = n->primary_address.bandwidth_out;
523#else 534#else
524 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, 535 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
525 n->neighbour_receive_quota); 536 n->neighbour_receive_quota);
526#endif 537#endif
527 538
528 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 539 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
529 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 540 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
530 ntohl(bandwidth_min.value__), 541 ntohl (bandwidth_min.value__),
531 GNUNET_i2s(&n->id)); 542 GNUNET_i2s (&n->id));
532 q_msg.header.size = htons(sizeof(struct QuotaSetMessage)); 543 q_msg.header.size = htons (sizeof(struct QuotaSetMessage));
533 q_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 544 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
534 q_msg.quota = bandwidth_min; 545 q_msg.quota = bandwidth_min;
535 q_msg.peer = n->id; 546 q_msg.peer = n->id;
536 GST_clients_broadcast(&q_msg.header, 547 GST_clients_broadcast (&q_msg.header,
537 GNUNET_NO); 548 GNUNET_NO);
538} 549}
539 550
540 551
@@ -544,28 +555,28 @@ send_outbound_quota_to_clients(struct NeighbourMapEntry *n)
544 * @param n the peer that connected 555 * @param n the peer that connected
545 */ 556 */
546static void 557static void
547neighbours_connect_notification(struct NeighbourMapEntry *n) 558neighbours_connect_notification (struct NeighbourMapEntry *n)
548{ 559{
549 size_t len = sizeof(struct ConnectInfoMessage); 560 size_t len = sizeof(struct ConnectInfoMessage);
550 char buf[len] GNUNET_ALIGN; 561 char buf[len] GNUNET_ALIGN;
551 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *)buf; 562 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
552 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 563 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
553 564
554#if IGNORE_INBOUND_QUOTA 565#if IGNORE_INBOUND_QUOTA
555 bandwidth_min = n->primary_address.bandwidth_out; 566 bandwidth_min = n->primary_address.bandwidth_out;
556#else 567#else
557 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out, 568 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
558 n->neighbour_receive_quota); 569 n->neighbour_receive_quota);
559#endif 570#endif
560 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 571 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
561 "We are now connected to peer `%s'\n", 572 "We are now connected to peer `%s'\n",
562 GNUNET_i2s(&n->id)); 573 GNUNET_i2s (&n->id));
563 connect_msg->header.size = htons(sizeof(buf)); 574 connect_msg->header.size = htons (sizeof(buf));
564 connect_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 575 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
565 connect_msg->id = n->id; 576 connect_msg->id = n->id;
566 connect_msg->quota_out = bandwidth_min; 577 connect_msg->quota_out = bandwidth_min;
567 GST_clients_broadcast(&connect_msg->header, 578 GST_clients_broadcast (&connect_msg->header,
568 GNUNET_NO); 579 GNUNET_NO);
569} 580}
570 581
571 582
@@ -576,13 +587,13 @@ neighbours_connect_notification(struct NeighbourMapEntry *n)
576 * @param n the peer that disconnected 587 * @param n the peer that disconnected
577 */ 588 */
578static void 589static void
579neighbours_disconnect_notification(struct NeighbourMapEntry *n) 590neighbours_disconnect_notification (struct NeighbourMapEntry *n)
580{ 591{
581 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 592 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
582 "Peer `%s' disconnected\n", 593 "Peer `%s' disconnected\n",
583 GNUNET_i2s(&n->id)); 594 GNUNET_i2s (&n->id));
584 GST_manipulation_peer_disconnect(&n->id); 595 GST_manipulation_peer_disconnect (&n->id);
585 GST_clients_broadcast_disconnect(&n->id); 596 GST_clients_broadcast_disconnect (&n->id);
586} 597}
587 598
588 599
@@ -598,26 +609,28 @@ neighbours_disconnect_notification(struct NeighbourMapEntry *n)
598 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect 609 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect
599 */ 610 */
600static void 611static void
601neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, 612neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
602 const struct GNUNET_HELLO_Address *address, 613 const struct GNUNET_HELLO_Address *address,
603 enum GNUNET_TRANSPORT_PeerState state, 614 enum GNUNET_TRANSPORT_PeerState state,
604 struct GNUNET_TIME_Absolute state_timeout, 615 struct GNUNET_TIME_Absolute state_timeout,
605 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 616 struct GNUNET_BANDWIDTH_Value32NBO
606 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 617 bandwidth_in,
607{ 618 struct GNUNET_BANDWIDTH_Value32NBO
608 (void)bandwidth_in; 619 bandwidth_out)
609 (void)bandwidth_out; 620{
610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 621 (void) bandwidth_in;
611 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", 622 (void) bandwidth_out;
612 GNUNET_i2s(peer), 623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 GST_plugins_a2s(address), 624 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
614 GNUNET_TRANSPORT_ps2s(state), 625 GNUNET_i2s (peer),
615 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 626 GST_plugins_a2s (address),
627 GNUNET_TRANSPORT_ps2s (state),
628 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
616 /* FIXME: include bandwidth in notification! */ 629 /* FIXME: include bandwidth in notification! */
617 GST_clients_broadcast_peer_notification(peer, 630 GST_clients_broadcast_peer_notification (peer,
618 address, 631 address,
619 state, 632 state,
620 state_timeout); 633 state_timeout);
621} 634}
622 635
623 636
@@ -628,11 +641,11 @@ neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer,
628 * @return the entry, NULL if there is no existing record 641 * @return the entry, NULL if there is no existing record
629 */ 642 */
630static struct NeighbourMapEntry * 643static struct NeighbourMapEntry *
631lookup_neighbour(const struct GNUNET_PeerIdentity *pid) 644lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
632{ 645{
633 if (NULL == neighbours) 646 if (NULL == neighbours)
634 return NULL; 647 return NULL;
635 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid); 648 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
636} 649}
637 650
638 651
@@ -643,11 +656,11 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
643 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 656 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
644 */ 657 */
645static int 658static int
646test_connected(struct NeighbourMapEntry *n) 659test_connected (struct NeighbourMapEntry *n)
647{ 660{
648 if (NULL == n) 661 if (NULL == n)
649 return GNUNET_NO; 662 return GNUNET_NO;
650 return GNUNET_TRANSPORT_is_connected(n->state); 663 return GNUNET_TRANSPORT_is_connected (n->state);
651} 664}
652 665
653 666
@@ -659,20 +672,20 @@ test_connected(struct NeighbourMapEntry *n)
659 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents! 672 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
660 */ 673 */
661static void 674static void
662free_address(struct NeighbourAddress *na) 675free_address (struct NeighbourAddress *na)
663{ 676{
664 if (GNUNET_YES == na->ats_active) 677 if (GNUNET_YES == na->ats_active)
665 GST_validation_set_address_use(na->address, 678 GST_validation_set_address_use (na->address,
666 GNUNET_NO); 679 GNUNET_NO);
667 if (NULL != na->address) 680 if (NULL != na->address)
668 { 681 {
669 GST_ats_block_address(na->address, 682 GST_ats_block_address (na->address,
670 na->session); 683 na->session);
671 GNUNET_HELLO_address_free(na->address); 684 GNUNET_HELLO_address_free (na->address);
672 na->address = NULL; 685 na->address = NULL;
673 } 686 }
674 na->bandwidth_in = GNUNET_BANDWIDTH_value_init(0); 687 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
675 na->bandwidth_out = GNUNET_BANDWIDTH_value_init(0); 688 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0);
676 na->ats_active = GNUNET_NO; 689 na->ats_active = GNUNET_NO;
677 na->keep_alive_nonce = 0; 690 na->keep_alive_nonce = 0;
678 na->session = NULL; 691 na->session = NULL;
@@ -687,7 +700,7 @@ free_address(struct NeighbourAddress *na)
687 * @param cls the `struct NeighbourMapEntry` for which we are running 700 * @param cls the `struct NeighbourMapEntry` for which we are running
688 */ 701 */
689static void 702static void
690master_task(void *cls); 703master_task (void *cls);
691 704
692 705
693/** 706/**
@@ -698,50 +711,50 @@ master_task(void *cls);
698 * @param timeout the new timeout 711 * @param timeout the new timeout
699 */ 712 */
700static void 713static void
701set_state_and_timeout(struct NeighbourMapEntry *n, 714set_state_and_timeout (struct NeighbourMapEntry *n,
702 enum GNUNET_TRANSPORT_PeerState s, 715 enum GNUNET_TRANSPORT_PeerState s,
703 struct GNUNET_TIME_Absolute timeout) 716 struct GNUNET_TIME_Absolute timeout)
704{ 717{
705 if (GNUNET_TRANSPORT_is_connected(s) && 718 if (GNUNET_TRANSPORT_is_connected (s) &&
706 (!GNUNET_TRANSPORT_is_connected(n->state))) 719 (! GNUNET_TRANSPORT_is_connected (n->state)))
707 { 720 {
708 neighbours_connect_notification(n); 721 neighbours_connect_notification (n);
709 GNUNET_STATISTICS_set(GST_stats, 722 GNUNET_STATISTICS_set (GST_stats,
710 gettext_noop("# peers connected"), 723 gettext_noop ("# peers connected"),
711 ++neighbours_connected, 724 ++neighbours_connected,
712 GNUNET_NO); 725 GNUNET_NO);
713 } 726 }
714 if ((!GNUNET_TRANSPORT_is_connected(s)) && 727 if ((! GNUNET_TRANSPORT_is_connected (s)) &&
715 GNUNET_TRANSPORT_is_connected(n->state)) 728 GNUNET_TRANSPORT_is_connected (n->state))
716 { 729 {
717 GNUNET_STATISTICS_set(GST_stats, 730 GNUNET_STATISTICS_set (GST_stats,
718 gettext_noop("# peers connected"), 731 gettext_noop ("# peers connected"),
719 --neighbours_connected, 732 --neighbours_connected,
720 GNUNET_NO); 733 GNUNET_NO);
721 neighbours_disconnect_notification(n); 734 neighbours_disconnect_notification (n);
722 } 735 }
723 n->state = s; 736 n->state = s;
724 if ((timeout.abs_value_us < n->timeout.abs_value_us) && 737 if ((timeout.abs_value_us < n->timeout.abs_value_us) &&
725 (NULL != n->task)) 738 (NULL != n->task))
726 { 739 {
727 /* new timeout is earlier, reschedule master task */ 740 /* new timeout is earlier, reschedule master task */
728 GNUNET_SCHEDULER_cancel(n->task); 741 GNUNET_SCHEDULER_cancel (n->task);
729 n->task = GNUNET_SCHEDULER_add_at(timeout, 742 n->task = GNUNET_SCHEDULER_add_at (timeout,
730 &master_task, 743 &master_task,
731 n); 744 n);
732 } 745 }
733 n->timeout = timeout; 746 n->timeout = timeout;
734 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 747 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
735 "Neighbour `%s' changed state to %s with timeout %s\n", 748 "Neighbour `%s' changed state to %s with timeout %s\n",
736 GNUNET_i2s(&n->id), 749 GNUNET_i2s (&n->id),
737 GNUNET_TRANSPORT_ps2s(s), 750 GNUNET_TRANSPORT_ps2s (s),
738 GNUNET_STRINGS_absolute_time_to_string(timeout)); 751 GNUNET_STRINGS_absolute_time_to_string (timeout));
739 neighbours_changed_notification(&n->id, 752 neighbours_changed_notification (&n->id,
740 n->primary_address.address, 753 n->primary_address.address,
741 n->state, 754 n->state,
742 n->timeout, 755 n->timeout,
743 n->primary_address.bandwidth_in, 756 n->primary_address.bandwidth_in,
744 n->primary_address.bandwidth_out); 757 n->primary_address.bandwidth_out);
745} 758}
746 759
747 760
@@ -757,62 +770,62 @@ set_state_and_timeout(struct NeighbourMapEntry *n,
757 * @param bandwidth_out outbound quota to be used when connection is up 770 * @param bandwidth_out outbound quota to be used when connection is up
758 */ 771 */
759static void 772static void
760set_alternative_address(struct NeighbourMapEntry *n, 773set_alternative_address (struct NeighbourMapEntry *n,
761 const struct GNUNET_HELLO_Address *address, 774 const struct GNUNET_HELLO_Address *address,
762 struct GNUNET_ATS_Session *session, 775 struct GNUNET_ATS_Session *session,
763 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 776 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
764 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 777 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
765{ 778{
766 struct GNUNET_TRANSPORT_PluginFunctions *papi; 779 struct GNUNET_TRANSPORT_PluginFunctions *papi;
767 780
768 if (NULL == (papi = GST_plugins_find(address->transport_name))) 781 if (NULL == (papi = GST_plugins_find (address->transport_name)))
769 { 782 {
770 GNUNET_break(0); 783 GNUNET_break (0);
771 return; 784 return;
772 } 785 }
773 if (session == n->alternative_address.session) 786 if (session == n->alternative_address.session)
774 { 787 {
775 n->alternative_address.bandwidth_in = bandwidth_in; 788 n->alternative_address.bandwidth_in = bandwidth_in;
776 n->alternative_address.bandwidth_out = bandwidth_out; 789 n->alternative_address.bandwidth_out = bandwidth_out;
777 return; 790 return;
778 } 791 }
779 if (NULL != n->alternative_address.address) 792 if (NULL != n->alternative_address.address)
780 { 793 {
781 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Replacing existing alternative address with another one\n"); 795 "Replacing existing alternative address with another one\n");
783 free_address(&n->alternative_address); 796 free_address (&n->alternative_address);
784 } 797 }
785 if (NULL == session) 798 if (NULL == session)
786 session = papi->get_session(papi->cls, 799 session = papi->get_session (papi->cls,
787 address); 800 address);
788 if (NULL == session) 801 if (NULL == session)
789 { 802 {
790 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
791 "Failed to obtain new session for peer `%s' and address '%s'\n", 804 "Failed to obtain new session for peer `%s' and address '%s'\n",
792 GNUNET_i2s(&address->peer), 805 GNUNET_i2s (&address->peer),
793 GST_plugins_a2s(address)); 806 GST_plugins_a2s (address));
794 GNUNET_STATISTICS_update(GST_stats, 807 GNUNET_STATISTICS_update (GST_stats,
795 gettext_noop("# session creation failed"), 808 gettext_noop ("# session creation failed"),
796 1, 809 1,
797 GNUNET_NO); 810 GNUNET_NO);
798 return; 811 return;
799 } 812 }
800 GST_ats_new_session(address, 813 GST_ats_new_session (address,
801 session); 814 session);
802 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 815 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
803 "Neighbour `%s' configured alternative address %s\n", 816 "Neighbour `%s' configured alternative address %s\n",
804 GNUNET_i2s(&n->id), 817 GNUNET_i2s (&n->id),
805 GST_plugins_a2s(address)); 818 GST_plugins_a2s (address));
806 819
807 n->alternative_address.address = GNUNET_HELLO_address_copy(address); 820 n->alternative_address.address = GNUNET_HELLO_address_copy (address);
808 n->alternative_address.bandwidth_in = bandwidth_in; 821 n->alternative_address.bandwidth_in = bandwidth_in;
809 n->alternative_address.bandwidth_out = bandwidth_out; 822 n->alternative_address.bandwidth_out = bandwidth_out;
810 n->alternative_address.session = session; 823 n->alternative_address.session = session;
811 n->alternative_address.ats_active = GNUNET_NO; 824 n->alternative_address.ats_active = GNUNET_NO;
812 n->alternative_address.keep_alive_nonce = 0; 825 n->alternative_address.keep_alive_nonce = 0;
813 GNUNET_assert(GNUNET_YES == 826 GNUNET_assert (GNUNET_YES ==
814 GST_ats_is_known(n->alternative_address.address, 827 GST_ats_is_known (n->alternative_address.address,
815 n->alternative_address.session)); 828 n->alternative_address.session));
816} 829}
817 830
818 831
@@ -833,40 +846,44 @@ set_alternative_address(struct NeighbourMapEntry *n,
833 * @a use_keepalive_timeout is #GNUNET_YES. 846 * @a use_keepalive_timeout is #GNUNET_YES.
834 */ 847 */
835static struct GNUNET_TIME_Relative 848static struct GNUNET_TIME_Relative
836send_with_session(struct NeighbourMapEntry *n, 849send_with_session (struct NeighbourMapEntry *n,
837 const void *msgbuf, 850 const void *msgbuf,
838 size_t msgbuf_size, 851 size_t msgbuf_size,
839 uint32_t priority, 852 uint32_t priority,
840 struct GNUNET_TIME_Relative timeout, 853 struct GNUNET_TIME_Relative timeout,
841 unsigned int use_keepalive_timeout, 854 unsigned int use_keepalive_timeout,
842 GNUNET_TRANSPORT_TransmitContinuation cont, 855 GNUNET_TRANSPORT_TransmitContinuation cont,
843 void *cont_cls) 856 void *cont_cls)
844{ 857{
845 struct GNUNET_TRANSPORT_PluginFunctions *papi; 858 struct GNUNET_TRANSPORT_PluginFunctions *papi;
846 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; 859 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
847 860
848 GNUNET_assert(NULL != n->primary_address.session); 861 GNUNET_assert (NULL != n->primary_address.session);
849 if (((NULL == (papi = GST_plugins_find(n->primary_address.address->transport_name)) || 862 if ((((NULL == (papi = GST_plugins_find (
850 (-1 == papi->send(papi->cls, 863 n->primary_address.address->transport_name))) ||
851 n->primary_address.session, 864 (-1 == papi->send (papi->cls,
852 msgbuf, 865 n->primary_address.session,
853 msgbuf_size, 866 msgbuf,
854 priority, 867 msgbuf_size,
855 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : 868 priority,
856 GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 869 (result = (GNUNET_NO == use_keepalive_timeout) ?
857 papi->query_keepalive_factor(papi->cls))), 870 timeout :
858 cont, 871 GNUNET_TIME_relative_divide (
859 cont_cls)))) && 872 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
873 papi->
874 query_keepalive_factor (papi->cls))),
875 cont,
876 cont_cls)))) &&
860 (NULL != cont)) 877 (NULL != cont))
861 cont(cont_cls, 878 cont (cont_cls,
862 &n->id, 879 &n->id,
863 GNUNET_SYSERR, 880 GNUNET_SYSERR,
864 msgbuf_size, 881 msgbuf_size,
865 0); 882 0);
866 GST_neighbours_notify_data_sent(n->primary_address.address, 883 GST_neighbours_notify_data_sent (n->primary_address.address,
867 n->primary_address.session, 884 n->primary_address.session,
868 msgbuf_size); 885 msgbuf_size);
869 GNUNET_break(NULL != papi); 886 GNUNET_break (NULL != papi);
870 return result; 887 return result;
871} 888}
872 889
@@ -878,20 +895,20 @@ send_with_session(struct NeighbourMapEntry *n,
878 * @param n the neighbour 895 * @param n the neighbour
879 */ 896 */
880static void 897static void
881unset_primary_address(struct NeighbourMapEntry *n) 898unset_primary_address (struct NeighbourMapEntry *n)
882{ 899{
883 /* Notify monitoring about change */ 900 /* Notify monitoring about change */
884 if (NULL == n->primary_address.address) 901 if (NULL == n->primary_address.address)
885 return; 902 return;
886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
887 "Disabling primary address\n"); 904 "Disabling primary address\n");
888 neighbours_changed_notification(&n->id, 905 neighbours_changed_notification (&n->id,
889 n->primary_address.address, 906 n->primary_address.address,
890 n->state, 907 n->state,
891 n->timeout, 908 n->timeout,
892 GNUNET_BANDWIDTH_value_init(0), 909 GNUNET_BANDWIDTH_value_init (0),
893 GNUNET_BANDWIDTH_value_init(0)); 910 GNUNET_BANDWIDTH_value_init (0));
894 free_address(&n->primary_address); 911 free_address (&n->primary_address);
895} 912}
896 913
897 914
@@ -901,68 +918,68 @@ unset_primary_address(struct NeighbourMapEntry *n)
901 * @param n entry to free 918 * @param n entry to free
902 */ 919 */
903static void 920static void
904free_neighbour(struct NeighbourMapEntry *n) 921free_neighbour (struct NeighbourMapEntry *n)
905{ 922{
906 struct MessageQueue *mq; 923 struct MessageQueue *mq;
907 924
908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Freeing neighbour state of peer `%s'\n", 926 "Freeing neighbour state of peer `%s'\n",
910 GNUNET_i2s(&n->id)); 927 GNUNET_i2s (&n->id));
911 n->is_active = NULL; /* always free'd by its own continuation! */ 928 n->is_active = NULL; /* always free'd by its own continuation! */
912 929
913 /* fail messages currently in the queue */ 930 /* fail messages currently in the queue */
914 while (NULL != (mq = n->messages_head)) 931 while (NULL != (mq = n->messages_head))
915 { 932 {
916 GNUNET_CONTAINER_DLL_remove(n->messages_head, 933 GNUNET_CONTAINER_DLL_remove (n->messages_head,
917 n->messages_tail, 934 n->messages_tail,
918 mq); 935 mq);
919 if (NULL != mq->cont) 936 if (NULL != mq->cont)
920 mq->cont(mq->cont_cls, 937 mq->cont (mq->cont_cls,
921 GNUNET_SYSERR, 938 GNUNET_SYSERR,
922 mq->message_buf_size, 939 mq->message_buf_size,
923 0); 940 0);
924 GNUNET_free(mq); 941 GNUNET_free (mq);
925 } 942 }
926 /* Mark peer as disconnected */ 943 /* Mark peer as disconnected */
927 set_state_and_timeout(n, 944 set_state_and_timeout (n,
928 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, 945 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED,
929 GNUNET_TIME_UNIT_FOREVER_ABS); 946 GNUNET_TIME_UNIT_FOREVER_ABS);
930 /* free addresses and mark as unused */ 947 /* free addresses and mark as unused */
931 unset_primary_address(n); 948 unset_primary_address (n);
932 949
933 if (NULL != n->alternative_address.address) 950 if (NULL != n->alternative_address.address)
934 { 951 {
935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 952 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Cleaning up alternative address\n"); 953 "Cleaning up alternative address\n");
937 free_address(&n->alternative_address); 954 free_address (&n->alternative_address);
938 } 955 }
939 GNUNET_assert(GNUNET_YES == 956 GNUNET_assert (GNUNET_YES ==
940 GNUNET_CONTAINER_multipeermap_remove(neighbours, 957 GNUNET_CONTAINER_multipeermap_remove (neighbours,
941 &n->id, 958 &n->id,
942 n)); 959 n));
943 960
944 /* Cancel address requests for this peer */ 961 /* Cancel address requests for this peer */
945 if (NULL != n->suggest_handle) 962 if (NULL != n->suggest_handle)
946 { 963 {
947 GNUNET_ATS_connectivity_suggest_cancel(n->suggest_handle); 964 GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle);
948 n->suggest_handle = NULL; 965 n->suggest_handle = NULL;
949 } 966 }
950 967
951 /* Cancel the disconnect task */ 968 /* Cancel the disconnect task */
952 if (NULL != n->delayed_disconnect_task) 969 if (NULL != n->delayed_disconnect_task)
953 { 970 {
954 GNUNET_SCHEDULER_cancel(n->delayed_disconnect_task); 971 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task);
955 n->delayed_disconnect_task = NULL; 972 n->delayed_disconnect_task = NULL;
956 } 973 }
957 974
958 /* Cancel the master task */ 975 /* Cancel the master task */
959 if (NULL != n->task) 976 if (NULL != n->task)
960 { 977 {
961 GNUNET_SCHEDULER_cancel(n->task); 978 GNUNET_SCHEDULER_cancel (n->task);
962 n->task = NULL; 979 n->task = NULL;
963 } 980 }
964 /* free rest of memory */ 981 /* free rest of memory */
965 GNUNET_free(n); 982 GNUNET_free (n);
966} 983}
967 984
968 985
@@ -977,26 +994,26 @@ free_neighbour(struct NeighbourMapEntry *n)
977 * @param physical bytes on wire 994 * @param physical bytes on wire
978 */ 995 */
979static void 996static void
980send_disconnect_cont(void *cls, 997send_disconnect_cont (void *cls,
981 const struct GNUNET_PeerIdentity *target, 998 const struct GNUNET_PeerIdentity *target,
982 int result, 999 int result,
983 size_t payload, 1000 size_t payload,
984 size_t physical) 1001 size_t physical)
985{ 1002{
986 struct NeighbourMapEntry *n; 1003 struct NeighbourMapEntry *n;
987 1004
988 (void)cls; 1005 (void) cls;
989 (void)result; 1006 (void) result;
990 (void)payload; 1007 (void) payload;
991 (void)physical; 1008 (void) physical;
992 n = lookup_neighbour(target); 1009 n = lookup_neighbour (target);
993 if (NULL == n) 1010 if (NULL == n)
994 return; /* already gone */ 1011 return; /* already gone */
995 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state) 1012 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state)
996 return; /* have created a fresh entry since */ 1013 return; /* have created a fresh entry since */
997 if (NULL != n->task) 1014 if (NULL != n->task)
998 GNUNET_SCHEDULER_cancel(n->task); 1015 GNUNET_SCHEDULER_cancel (n->task);
999 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 1016 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1000} 1017}
1001 1018
1002 1019
@@ -1006,43 +1023,44 @@ send_disconnect_cont(void *cls,
1006 * @param n neighbour to send DISCONNECT message. 1023 * @param n neighbour to send DISCONNECT message.
1007 */ 1024 */
1008static void 1025static void
1009send_disconnect(struct NeighbourMapEntry *n) 1026send_disconnect (struct NeighbourMapEntry *n)
1010{ 1027{
1011 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg; 1028 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg;
1012 1029
1013 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1030 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1014 "Sending DISCONNECT message to peer `%4s'\n", 1031 "Sending DISCONNECT message to peer `%4s'\n",
1015 GNUNET_i2s(&n->id)); 1032 GNUNET_i2s (&n->id));
1016 disconnect_msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionDisconnectMessage)); 1033 disconnect_msg.header.size = htons (sizeof(struct
1034 GNUNET_ATS_SessionDisconnectMessage));
1017 disconnect_msg.header.type = 1035 disconnect_msg.header.type =
1018 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1036 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1019 disconnect_msg.reserved = htonl(0); 1037 disconnect_msg.reserved = htonl (0);
1020 disconnect_msg.purpose.size = 1038 disconnect_msg.purpose.size =
1021 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 1039 htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
1022 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + 1040 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
1023 sizeof(struct GNUNET_TIME_AbsoluteNBO)); 1041 + sizeof(struct GNUNET_TIME_AbsoluteNBO));
1024 disconnect_msg.purpose.purpose = 1042 disconnect_msg.purpose.purpose =
1025 htonl(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1043 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1026 disconnect_msg.timestamp = 1044 disconnect_msg.timestamp =
1027 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get()); 1045 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1028 disconnect_msg.public_key = GST_my_identity.public_key; 1046 disconnect_msg.public_key = GST_my_identity.public_key;
1029 GNUNET_assert(GNUNET_OK == 1047 GNUNET_assert (GNUNET_OK ==
1030 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key, 1048 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
1031 &disconnect_msg.purpose, 1049 &disconnect_msg.purpose,
1032 &disconnect_msg.signature)); 1050 &disconnect_msg.signature));
1033 1051
1034 (void)send_with_session(n, 1052 (void) send_with_session (n,
1035 &disconnect_msg, 1053 &disconnect_msg,
1036 sizeof(disconnect_msg), 1054 sizeof(disconnect_msg),
1037 UINT32_MAX, 1055 UINT32_MAX,
1038 GNUNET_TIME_UNIT_FOREVER_REL, 1056 GNUNET_TIME_UNIT_FOREVER_REL,
1039 GNUNET_NO, 1057 GNUNET_NO,
1040 &send_disconnect_cont, 1058 &send_disconnect_cont,
1041 NULL); 1059 NULL);
1042 GNUNET_STATISTICS_update(GST_stats, 1060 GNUNET_STATISTICS_update (GST_stats,
1043 gettext_noop("# DISCONNECT messages sent"), 1061 gettext_noop ("# DISCONNECT messages sent"),
1044 1, 1062 1,
1045 GNUNET_NO); 1063 GNUNET_NO);
1046} 1064}
1047 1065
1048 1066
@@ -1052,81 +1070,81 @@ send_disconnect(struct NeighbourMapEntry *n)
1052 * @param n neighbour to disconnect from 1070 * @param n neighbour to disconnect from
1053 */ 1071 */
1054static void 1072static void
1055disconnect_neighbour(struct NeighbourMapEntry *n) 1073disconnect_neighbour (struct NeighbourMapEntry *n)
1056{ 1074{
1057 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1058 "Disconnecting from peer %s in state %s\n", 1076 "Disconnecting from peer %s in state %s\n",
1059 GNUNET_i2s(&n->id), 1077 GNUNET_i2s (&n->id),
1060 GNUNET_TRANSPORT_ps2s(n->state)); 1078 GNUNET_TRANSPORT_ps2s (n->state));
1061 /* depending on state, notify neighbour and/or upper layers of this peer 1079 /* depending on state, notify neighbour and/or upper layers of this peer
1062 about disconnect */ 1080 about disconnect */
1063 switch (n->state) 1081 switch (n->state)
1064 { 1082 {
1065 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 1083 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
1066 case GNUNET_TRANSPORT_PS_INIT_ATS: 1084 case GNUNET_TRANSPORT_PS_INIT_ATS:
1067 /* other peer is completely unaware of us, no need to send DISCONNECT */ 1085 /* other peer is completely unaware of us, no need to send DISCONNECT */
1068 free_neighbour(n); 1086 free_neighbour (n);
1069 return; 1087 return;
1070
1071 case GNUNET_TRANSPORT_PS_SYN_SENT:
1072 send_disconnect(n);
1073 set_state_and_timeout(n,
1074 GNUNET_TRANSPORT_PS_DISCONNECT,
1075 GNUNET_TIME_UNIT_FOREVER_ABS);
1076 break;
1077
1078 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1079 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1080 free_neighbour(n);
1081 return;
1082
1083 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1084 /* we DID ACK the other peer's request, must send DISCONNECT */
1085 send_disconnect(n);
1086 set_state_and_timeout(n,
1087 GNUNET_TRANSPORT_PS_DISCONNECT,
1088 GNUNET_TIME_UNIT_FOREVER_ABS);
1089 break;
1090
1091 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1092 case GNUNET_TRANSPORT_PS_CONNECTED:
1093 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1094 /* we are currently connected, need to send disconnect and do
1095 internal notifications and update statistics */
1096 send_disconnect(n);
1097 set_state_and_timeout(n,
1098 GNUNET_TRANSPORT_PS_DISCONNECT,
1099 GNUNET_TIME_UNIT_FOREVER_ABS);
1100 break;
1101 1088
1102 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 1089 case GNUNET_TRANSPORT_PS_SYN_SENT:
1103 /* Disconnecting while waiting for an ATS address to reconnect, 1090 send_disconnect (n);
1104 * cannot send DISCONNECT */ 1091 set_state_and_timeout (n,
1105 free_neighbour(n); 1092 GNUNET_TRANSPORT_PS_DISCONNECT,
1106 return; 1093 GNUNET_TIME_UNIT_FOREVER_ABS);
1094 break;
1107 1095
1108 case GNUNET_TRANSPORT_PS_DISCONNECT: 1096 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1109 /* already disconnected, ignore */ 1097 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1110 break; 1098 free_neighbour (n);
1099 return;
1111 1100
1112 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 1101 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1113 /* already cleaned up, how did we get here!? */ 1102 /* we DID ACK the other peer's request, must send DISCONNECT */
1114 GNUNET_assert(0); 1103 send_disconnect (n);
1115 break; 1104 set_state_and_timeout (n,
1105 GNUNET_TRANSPORT_PS_DISCONNECT,
1106 GNUNET_TIME_UNIT_FOREVER_ABS);
1107 break;
1108
1109 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1110 case GNUNET_TRANSPORT_PS_CONNECTED:
1111 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1112 /* we are currently connected, need to send disconnect and do
1113 internal notifications and update statistics */
1114 send_disconnect (n);
1115 set_state_and_timeout (n,
1116 GNUNET_TRANSPORT_PS_DISCONNECT,
1117 GNUNET_TIME_UNIT_FOREVER_ABS);
1118 break;
1119
1120 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1121 /* Disconnecting while waiting for an ATS address to reconnect,
1122 * cannot send DISCONNECT */
1123 free_neighbour (n);
1124 return;
1116 1125
1117 default: 1126 case GNUNET_TRANSPORT_PS_DISCONNECT:
1118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1127 /* already disconnected, ignore */
1119 "Unhandled state `%s'\n", 1128 break;
1120 GNUNET_TRANSPORT_ps2s(n->state)); 1129
1121 GNUNET_break(0); 1130 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
1122 break; 1131 /* already cleaned up, how did we get here!? */
1123 } 1132 GNUNET_assert (0);
1133 break;
1134
1135 default:
1136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1137 "Unhandled state `%s'\n",
1138 GNUNET_TRANSPORT_ps2s (n->state));
1139 GNUNET_break (0);
1140 break;
1141 }
1124 /* schedule timeout to clean up */ 1142 /* schedule timeout to clean up */
1125 if (NULL != n->task) 1143 if (NULL != n->task)
1126 GNUNET_SCHEDULER_cancel(n->task); 1144 GNUNET_SCHEDULER_cancel (n->task);
1127 n->task = GNUNET_SCHEDULER_add_delayed(DISCONNECT_SENT_TIMEOUT, 1145 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT,
1128 &master_task, 1146 &master_task,
1129 n); 1147 n);
1130} 1148}
1131 1149
1132 1150
@@ -1141,39 +1159,39 @@ disconnect_neighbour(struct NeighbourMapEntry *n)
1141 * @a n was freed 1159 * @a n was freed
1142 */ 1160 */
1143static int 1161static int
1144set_incoming_quota(struct NeighbourMapEntry *n, 1162set_incoming_quota (struct NeighbourMapEntry *n,
1145 struct GNUNET_BANDWIDTH_Value32NBO quota) 1163 struct GNUNET_BANDWIDTH_Value32NBO quota)
1146{ 1164{
1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1148 "Setting inbound quota of %u Bps for peer `%s' to all clients\n", 1166 "Setting inbound quota of %u Bps for peer `%s' to all clients\n",
1149 ntohl(quota.value__), GNUNET_i2s(&n->id)); 1167 ntohl (quota.value__), GNUNET_i2s (&n->id));
1150 GNUNET_BANDWIDTH_tracker_update_quota(&n->in_tracker, 1168 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
1151 quota); 1169 quota);
1152 if (0 != ntohl(quota.value__)) 1170 if (0 != ntohl (quota.value__))
1153 { 1171 {
1154 struct GNUNET_ATS_SessionQuotaMessage sqm; 1172 struct GNUNET_ATS_SessionQuotaMessage sqm;
1155 1173
1156 sqm.header.size = htons(sizeof(struct GNUNET_ATS_SessionQuotaMessage)); 1174 sqm.header.size = htons (sizeof(struct GNUNET_ATS_SessionQuotaMessage));
1157 sqm.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA); 1175 sqm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA);
1158 sqm.quota = quota.value__; 1176 sqm.quota = quota.value__;
1159 if (NULL != n->primary_address.session) 1177 if (NULL != n->primary_address.session)
1160 (void)send_with_session(n, 1178 (void) send_with_session (n,
1161 &sqm, 1179 &sqm,
1162 sizeof(sqm), 1180 sizeof(sqm),
1163 UINT32_MAX - 1, 1181 UINT32_MAX - 1,
1164 GNUNET_TIME_UNIT_FOREVER_REL, 1182 GNUNET_TIME_UNIT_FOREVER_REL,
1165 GNUNET_NO, 1183 GNUNET_NO,
1166 NULL, NULL); 1184 NULL, NULL);
1167 return GNUNET_YES; 1185 return GNUNET_YES;
1168 } 1186 }
1169 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1187 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1170 "Disconnecting peer `%s' due to SET_QUOTA\n", 1188 "Disconnecting peer `%s' due to SET_QUOTA\n",
1171 GNUNET_i2s(&n->id)); 1189 GNUNET_i2s (&n->id));
1172 if (GNUNET_YES == test_connected(n)) 1190 if (GNUNET_YES == test_connected (n))
1173 GNUNET_STATISTICS_update(GST_stats, 1191 GNUNET_STATISTICS_update (GST_stats,
1174 gettext_noop("# disconnects due to quota of 0"), 1192 gettext_noop ("# disconnects due to quota of 0"),
1175 1, GNUNET_NO); 1193 1, GNUNET_NO);
1176 disconnect_neighbour(n); 1194 disconnect_neighbour (n);
1177 return GNUNET_NO; 1195 return GNUNET_NO;
1178} 1196}
1179 1197
@@ -1190,78 +1208,78 @@ set_incoming_quota(struct NeighbourMapEntry *n,
1190 * @param bandwidth_out outbound quota to be used when connection is up 1208 * @param bandwidth_out outbound quota to be used when connection is up
1191 */ 1209 */
1192static void 1210static void
1193set_primary_address(struct NeighbourMapEntry *n, 1211set_primary_address (struct NeighbourMapEntry *n,
1194 const struct GNUNET_HELLO_Address *address, 1212 const struct GNUNET_HELLO_Address *address,
1195 struct GNUNET_ATS_Session *session, 1213 struct GNUNET_ATS_Session *session,
1196 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1214 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1215 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1198{ 1216{
1199 if (session == n->primary_address.session) 1217 if (session == n->primary_address.session)
1218 {
1219 GST_validation_set_address_use (n->primary_address.address,
1220 GNUNET_YES);
1221 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1200 { 1222 {
1201 GST_validation_set_address_use(n->primary_address.address, 1223 n->primary_address.bandwidth_in = bandwidth_in;
1202 GNUNET_YES); 1224 if (GNUNET_YES !=
1203 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 1225 set_incoming_quota (n,
1204 { 1226 bandwidth_in))
1205 n->primary_address.bandwidth_in = bandwidth_in; 1227 return;
1206 if (GNUNET_YES !=
1207 set_incoming_quota(n,
1208 bandwidth_in))
1209 return;
1210 }
1211 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1212 {
1213 n->primary_address.bandwidth_out = bandwidth_out;
1214 send_outbound_quota_to_clients(n);
1215 }
1216 return;
1217 } 1228 }
1218 if ((NULL != n->primary_address.address) && 1229 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1219 (0 == GNUNET_HELLO_address_cmp(address,
1220 n->primary_address.address)))
1221 { 1230 {
1222 GNUNET_break(0); 1231 n->primary_address.bandwidth_out = bandwidth_out;
1223 return; 1232 send_outbound_quota_to_clients (n);
1224 } 1233 }
1234 return;
1235 }
1236 if ((NULL != n->primary_address.address) &&
1237 (0 == GNUNET_HELLO_address_cmp (address,
1238 n->primary_address.address)))
1239 {
1240 GNUNET_break (0);
1241 return;
1242 }
1225 if (NULL == session) 1243 if (NULL == session)
1226 { 1244 {
1227 GNUNET_break(0); 1245 GNUNET_break (0);
1228 GST_ats_block_address(address, 1246 GST_ats_block_address (address,
1229 session); 1247 session);
1230 return; 1248 return;
1231 } 1249 }
1232 if (NULL != n->primary_address.address) 1250 if (NULL != n->primary_address.address)
1233 { 1251 {
1234 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1235 "Replacing existing primary address with another one\n"); 1253 "Replacing existing primary address with another one\n");
1236 free_address(&n->primary_address); 1254 free_address (&n->primary_address);
1237 } 1255 }
1238 n->primary_address.address = GNUNET_HELLO_address_copy(address); 1256 n->primary_address.address = GNUNET_HELLO_address_copy (address);
1239 n->primary_address.bandwidth_in = bandwidth_in; 1257 n->primary_address.bandwidth_in = bandwidth_in;
1240 n->primary_address.bandwidth_out = bandwidth_out; 1258 n->primary_address.bandwidth_out = bandwidth_out;
1241 n->primary_address.session = session; 1259 n->primary_address.session = session;
1242 n->primary_address.keep_alive_nonce = 0; 1260 n->primary_address.keep_alive_nonce = 0;
1243 GNUNET_assert(GNUNET_YES == 1261 GNUNET_assert (GNUNET_YES ==
1244 GST_ats_is_known(n->primary_address.address, 1262 GST_ats_is_known (n->primary_address.address,
1245 n->primary_address.session)); 1263 n->primary_address.session));
1246 /* subsystems about address use */ 1264 /* subsystems about address use */
1247 GST_validation_set_address_use(n->primary_address.address, 1265 GST_validation_set_address_use (n->primary_address.address,
1248 GNUNET_YES); 1266 GNUNET_YES);
1249 if (GNUNET_YES != 1267 if (GNUNET_YES !=
1250 set_incoming_quota(n, 1268 set_incoming_quota (n,
1251 bandwidth_in)) 1269 bandwidth_in))
1252 return; 1270 return;
1253 send_outbound_quota_to_clients(n); 1271 send_outbound_quota_to_clients (n);
1254 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1272 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1255 "Neighbour `%s' switched to address `%s'\n", 1273 "Neighbour `%s' switched to address `%s'\n",
1256 GNUNET_i2s(&n->id), 1274 GNUNET_i2s (&n->id),
1257 GST_plugins_a2s(address)); 1275 GST_plugins_a2s (address));
1258 1276
1259 neighbours_changed_notification(&n->id, 1277 neighbours_changed_notification (&n->id,
1260 n->primary_address.address, 1278 n->primary_address.address,
1261 n->state, 1279 n->state,
1262 n->timeout, 1280 n->timeout,
1263 n->primary_address.bandwidth_in, 1281 n->primary_address.bandwidth_in,
1264 n->primary_address.bandwidth_out); 1282 n->primary_address.bandwidth_out);
1265} 1283}
1266 1284
1267 1285
@@ -1275,75 +1293,78 @@ set_primary_address(struct NeighbourMapEntry *n,
1275 * @param physical bytes sent on wire 1293 * @param physical bytes sent on wire
1276 */ 1294 */
1277static void 1295static void
1278transmit_send_continuation(void *cls, 1296transmit_send_continuation (void *cls,
1279 const struct GNUNET_PeerIdentity *receiver, 1297 const struct GNUNET_PeerIdentity *receiver,
1280 int success, 1298 int success,
1281 size_t size_payload, 1299 size_t size_payload,
1282 size_t physical) 1300 size_t physical)
1283{ 1301{
1284 struct MessageQueue *mq = cls; 1302 struct MessageQueue *mq = cls;
1285 struct NeighbourMapEntry *n; 1303 struct NeighbourMapEntry *n;
1286 1304
1287 if (NULL == (n = lookup_neighbour(receiver))) 1305 if (NULL == (n = lookup_neighbour (receiver)))
1288 { 1306 {
1289 if (NULL != mq->cont) 1307 if (NULL != mq->cont)
1290 mq->cont(mq->cont_cls, 1308 mq->cont (mq->cont_cls,
1291 GNUNET_SYSERR /* not connected */, 1309 GNUNET_SYSERR /* not connected */,
1292 size_payload, 1310 size_payload,
1293 0); 1311 0);
1294 GNUNET_free(mq); 1312 GNUNET_free (mq);
1295 return; /* disconnect or other error while transmitting, can happen */ 1313 return; /* disconnect or other error while transmitting, can happen */
1296 } 1314 }
1297 if (n->is_active == mq) 1315 if (n->is_active == mq)
1298 { 1316 {
1299 /* this is still "our" neighbour, remove us from its queue 1317 /* this is still "our" neighbour, remove us from its queue
1300 and allow it to send the next message now */ 1318 and allow it to send the next message now */
1301 n->is_active = NULL; 1319 n->is_active = NULL;
1302 if (NULL != n->task) 1320 if (NULL != n->task)
1303 GNUNET_SCHEDULER_cancel(n->task); 1321 GNUNET_SCHEDULER_cancel (n->task);
1304 n->task = GNUNET_SCHEDULER_add_now(&master_task, 1322 n->task = GNUNET_SCHEDULER_add_now (&master_task,
1305 n); 1323 n);
1306 } 1324 }
1307 if (bytes_in_send_queue < mq->message_buf_size) 1325 if (bytes_in_send_queue < mq->message_buf_size)
1308 { 1326 {
1309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1310 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n", 1328 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n",
1311 bytes_in_send_queue, 1329 bytes_in_send_queue,
1312 (unsigned int)mq->message_buf_size, 1330 (unsigned int) mq->message_buf_size,
1313 (GNUNET_OK == success) ? "OK" : "FAIL", 1331 (GNUNET_OK == success) ? "OK" : "FAIL",
1314 (unsigned int)size_payload, 1332 (unsigned int) size_payload,
1315 (unsigned int)physical); 1333 (unsigned int) physical);
1316 GNUNET_break(0); 1334 GNUNET_break (0);
1317 } 1335 }
1318 1336
1319 GNUNET_break(size_payload == mq->message_buf_size); 1337 GNUNET_break (size_payload == mq->message_buf_size);
1320 bytes_in_send_queue -= mq->message_buf_size; 1338 bytes_in_send_queue -= mq->message_buf_size;
1321 GNUNET_STATISTICS_set(GST_stats, 1339 GNUNET_STATISTICS_set (GST_stats,
1322 gettext_noop("# bytes in message queue for other peers"), 1340 gettext_noop (
1323 bytes_in_send_queue, 1341 "# bytes in message queue for other peers"),
1324 GNUNET_NO); 1342 bytes_in_send_queue,
1343 GNUNET_NO);
1325 if (GNUNET_OK == success) 1344 if (GNUNET_OK == success)
1326 GNUNET_STATISTICS_update(GST_stats, 1345 GNUNET_STATISTICS_update (GST_stats,
1327 gettext_noop("# messages transmitted to other peers"), 1346 gettext_noop (
1328 1, 1347 "# messages transmitted to other peers"),
1329 GNUNET_NO); 1348 1,
1349 GNUNET_NO);
1330 else 1350 else
1331 GNUNET_STATISTICS_update(GST_stats, 1351 GNUNET_STATISTICS_update (GST_stats,
1332 gettext_noop 1352 gettext_noop
1333 ("# transmission failures for messages to other peers"), 1353 (
1334 1, GNUNET_NO); 1354 "# transmission failures for messages to other peers"),
1335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1355 1, GNUNET_NO);
1336 "Sending message to `%s' of type %u with %u bytes was a %s\n", 1356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1337 GNUNET_i2s(receiver), 1357 "Sending message to `%s' of type %u with %u bytes was a %s\n",
1338 ntohs(((struct GNUNET_MessageHeader *)mq->message_buf)->type), 1358 GNUNET_i2s (receiver),
1339 (unsigned int)mq->message_buf_size, 1359 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
1340 (success == GNUNET_OK) ? "success" : "FAILURE"); 1360 (unsigned int) mq->message_buf_size,
1361 (success == GNUNET_OK) ? "success" : "FAILURE");
1341 if (NULL != mq->cont) 1362 if (NULL != mq->cont)
1342 mq->cont(mq->cont_cls, 1363 mq->cont (mq->cont_cls,
1343 success, 1364 success,
1344 size_payload, 1365 size_payload,
1345 physical); 1366 physical);
1346 GNUNET_free(mq); 1367 GNUNET_free (mq);
1347} 1368}
1348 1369
1349 1370
@@ -1359,77 +1380,78 @@ transmit_send_continuation(void *cls,
1359 * @param n target peer for which to transmit 1380 * @param n target peer for which to transmit
1360 */ 1381 */
1361static void 1382static void
1362try_transmission_to_peer(struct NeighbourMapEntry *n) 1383try_transmission_to_peer (struct NeighbourMapEntry *n)
1363{ 1384{
1364 struct MessageQueue *mq; 1385 struct MessageQueue *mq;
1365 struct GNUNET_TIME_Relative timeout; 1386 struct GNUNET_TIME_Relative timeout;
1366 1387
1367 if (NULL == n->primary_address.address) 1388 if (NULL == n->primary_address.address)
1368 { 1389 {
1369 /* no address, why are we here? */ 1390 /* no address, why are we here? */
1370 GNUNET_break(0); 1391 GNUNET_break (0);
1371 return; 1392 return;
1372 } 1393 }
1373 if ((0 == n->primary_address.address->address_length) && 1394 if ((0 == n->primary_address.address->address_length) &&
1374 (NULL == n->primary_address.session)) 1395 (NULL == n->primary_address.session))
1375 { 1396 {
1376 /* no address, why are we here? */ 1397 /* no address, why are we here? */
1377 GNUNET_break(0); 1398 GNUNET_break (0);
1378 return; 1399 return;
1379 } 1400 }
1380 if (NULL != n->is_active) 1401 if (NULL != n->is_active)
1381 { 1402 {
1382 /* transmission already pending */ 1403 /* transmission already pending */
1383 return; 1404 return;
1384 } 1405 }
1385 1406
1386 /* timeout messages from the queue that are past their due date */ 1407 /* timeout messages from the queue that are past their due date */
1387 while (NULL != (mq = n->messages_head)) 1408 while (NULL != (mq = n->messages_head))
1388 { 1409 {
1389 timeout = GNUNET_TIME_absolute_get_remaining(mq->timeout); 1410 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1390 if (timeout.rel_value_us > 0) 1411 if (timeout.rel_value_us > 0)
1391 break; 1412 break;
1392 GNUNET_STATISTICS_update(GST_stats, 1413 GNUNET_STATISTICS_update (GST_stats,
1393 gettext_noop("# messages timed out while in transport queue"), 1414 gettext_noop (
1394 1, 1415 "# messages timed out while in transport queue"),
1395 GNUNET_NO); 1416 1,
1396 GNUNET_CONTAINER_DLL_remove(n->messages_head, 1417 GNUNET_NO);
1397 n->messages_tail, 1418 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1398 mq); 1419 n->messages_tail,
1399 n->is_active = mq; 1420 mq);
1400 transmit_send_continuation(mq, 1421 n->is_active = mq;
1401 &n->id, 1422 transmit_send_continuation (mq,
1402 GNUNET_SYSERR, 1423 &n->id,
1403 mq->message_buf_size, 1424 GNUNET_SYSERR,
1404 0); /* timeout */ 1425 mq->message_buf_size,
1405 } 1426 0); /* timeout */
1427 }
1406 if (NULL == mq) 1428 if (NULL == mq)
1407 return; /* no more messages */ 1429 return; /* no more messages */
1408 if (NULL == n->primary_address.address) 1430 if (NULL == n->primary_address.address)
1409 { 1431 {
1410 /* transmit_send_continuation() caused us to drop session, 1432 /* transmit_send_continuation() caused us to drop session,
1411 can't try transmission anymore. */ 1433 can't try transmission anymore. */
1412 return; 1434 return;
1413 } 1435 }
1414 1436
1415 1437
1416 GNUNET_CONTAINER_DLL_remove(n->messages_head, 1438 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1417 n->messages_tail, 1439 n->messages_tail,
1418 mq); 1440 mq);
1419 n->is_active = mq; 1441 n->is_active = mq;
1420 1442
1421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1422 "Giving message with %u bytes to plugin session %p\n", 1444 "Giving message with %u bytes to plugin session %p\n",
1423 (unsigned int)mq->message_buf_size, 1445 (unsigned int) mq->message_buf_size,
1424 n->primary_address.session); 1446 n->primary_address.session);
1425 (void)send_with_session(n, 1447 (void) send_with_session (n,
1426 mq->message_buf, 1448 mq->message_buf,
1427 mq->message_buf_size, 1449 mq->message_buf_size,
1428 0 /* priority */, 1450 0 /* priority */,
1429 timeout, 1451 timeout,
1430 GNUNET_NO, 1452 GNUNET_NO,
1431 &transmit_send_continuation, 1453 &transmit_send_continuation,
1432 mq); 1454 mq);
1433} 1455}
1434 1456
1435 1457
@@ -1442,45 +1464,45 @@ try_transmission_to_peer(struct NeighbourMapEntry *n)
1442 * @param n neighbour that went idle and needs a keepalive 1464 * @param n neighbour that went idle and needs a keepalive
1443 */ 1465 */
1444static void 1466static void
1445send_keepalive(struct NeighbourMapEntry *n) 1467send_keepalive (struct NeighbourMapEntry *n)
1446{ 1468{
1447 struct GNUNET_ATS_SessionKeepAliveMessage m; 1469 struct GNUNET_ATS_SessionKeepAliveMessage m;
1448 struct GNUNET_TIME_Relative timeout; 1470 struct GNUNET_TIME_Relative timeout;
1449 uint32_t nonce; 1471 uint32_t nonce;
1450 1472
1451 GNUNET_assert((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || 1473 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) ||
1452 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); 1474 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state));
1453 if (GNUNET_TIME_absolute_get_remaining(n->keep_alive_time).rel_value_us > 0) 1475 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0)
1454 return; /* no keepalive needed at this time */ 1476 return; /* no keepalive needed at this time */
1455 1477
1456 nonce = 0; /* 0 indicates 'not set' */ 1478 nonce = 0; /* 0 indicates 'not set' */
1457 while (0 == nonce) 1479 while (0 == nonce)
1458 nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 1480 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1459 UINT32_MAX); 1481 UINT32_MAX);
1460 1482
1461 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1462 "Sending KEEPALIVE to peer `%s' with nonce %u\n", 1484 "Sending KEEPALIVE to peer `%s' with nonce %u\n",
1463 GNUNET_i2s(&n->id), 1485 GNUNET_i2s (&n->id),
1464 nonce); 1486 nonce);
1465 m.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); 1487 m.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1466 m.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1488 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1467 m.nonce = htonl(nonce); 1489 m.nonce = htonl (nonce);
1468 1490
1469 timeout = send_with_session(n, 1491 timeout = send_with_session (n,
1470 &m, 1492 &m,
1471 sizeof(m), 1493 sizeof(m),
1472 UINT32_MAX /* priority */, 1494 UINT32_MAX /* priority */,
1473 GNUNET_TIME_UNIT_FOREVER_REL, 1495 GNUNET_TIME_UNIT_FOREVER_REL,
1474 GNUNET_YES, 1496 GNUNET_YES,
1475 NULL, NULL); 1497 NULL, NULL);
1476 GNUNET_STATISTICS_update(GST_stats, 1498 GNUNET_STATISTICS_update (GST_stats,
1477 gettext_noop("# KEEPALIVES sent"), 1499 gettext_noop ("# KEEPALIVES sent"),
1478 1, 1500 1,
1479 GNUNET_NO); 1501 GNUNET_NO);
1480 n->primary_address.keep_alive_nonce = nonce; 1502 n->primary_address.keep_alive_nonce = nonce;
1481 n->expect_latency_response = GNUNET_YES; 1503 n->expect_latency_response = GNUNET_YES;
1482 n->last_keep_alive_time = GNUNET_TIME_absolute_get(); 1504 n->last_keep_alive_time = GNUNET_TIME_absolute_get ();
1483 n->keep_alive_time = GNUNET_TIME_relative_to_absolute(timeout); 1505 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout);
1484} 1506}
1485 1507
1486 1508
@@ -1492,57 +1514,59 @@ send_keepalive(struct NeighbourMapEntry *n)
1492 * @param m the keep alive message containing the nonce to respond to 1514 * @param m the keep alive message containing the nonce to respond to
1493 */ 1515 */
1494void 1516void
1495GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour, 1517GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
1496 const struct GNUNET_MessageHeader *m) 1518 const struct GNUNET_MessageHeader *m)
1497{ 1519{
1498 struct NeighbourMapEntry *n; 1520 struct NeighbourMapEntry *n;
1499 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in; 1521 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in;
1500 struct GNUNET_ATS_SessionKeepAliveMessage msg; 1522 struct GNUNET_ATS_SessionKeepAliveMessage msg;
1501 1523
1502 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) 1524 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size))
1503 { 1525 {
1504 GNUNET_break_op(0); 1526 GNUNET_break_op (0);
1505 return; 1527 return;
1506 } 1528 }
1507 1529
1508 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; 1530 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m;
1509 if (NULL == (n = lookup_neighbour(neighbour))) 1531 if (NULL == (n = lookup_neighbour (neighbour)))
1510 { 1532 {
1511 GNUNET_STATISTICS_update(GST_stats, 1533 GNUNET_STATISTICS_update (GST_stats,
1512 gettext_noop 1534 gettext_noop
1513 ("# KEEPALIVE messages discarded (peer unknown)"), 1535 ("# KEEPALIVE messages discarded (peer unknown)"),
1514 1, GNUNET_NO); 1536 1, GNUNET_NO);
1515 return; 1537 return;
1516 } 1538 }
1517 if (NULL == n->primary_address.session) 1539 if (NULL == n->primary_address.session)
1518 { 1540 {
1519 GNUNET_STATISTICS_update(GST_stats, 1541 GNUNET_STATISTICS_update (GST_stats,
1520 gettext_noop 1542 gettext_noop
1521 ("# KEEPALIVE messages discarded (no session)"), 1543 ("# KEEPALIVE messages discarded (no session)"),
1522 1, GNUNET_NO); 1544 1, GNUNET_NO);
1523 return; 1545 return;
1524 } 1546 }
1525 1547
1526 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1527 "Received KEEPALIVE request from peer `%s' with nonce %u\n", 1549 "Received KEEPALIVE request from peer `%s' with nonce %u\n",
1528 GNUNET_i2s(&n->id), 1550 GNUNET_i2s (&n->id),
1529 ntohl(msg_in->nonce)); 1551 ntohl (msg_in->nonce));
1530 GNUNET_STATISTICS_update(GST_stats, 1552 GNUNET_STATISTICS_update (GST_stats,
1531 gettext_noop("# KEEPALIVES received in good order"), 1553 gettext_noop (
1532 1, 1554 "# KEEPALIVES received in good order"),
1533 GNUNET_NO); 1555 1,
1556 GNUNET_NO);
1534 1557
1535 /* send reply to allow neighbour to measure latency */ 1558 /* send reply to allow neighbour to measure latency */
1536 msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage)); 1559 msg.header.size = htons (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1537 msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 1560 msg.header.type = htons (
1561 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1538 msg.nonce = msg_in->nonce; 1562 msg.nonce = msg_in->nonce;
1539 (void)send_with_session(n, 1563 (void) send_with_session (n,
1540 &msg, 1564 &msg,
1541 sizeof(struct GNUNET_ATS_SessionKeepAliveMessage), 1565 sizeof(struct GNUNET_ATS_SessionKeepAliveMessage),
1542 UINT32_MAX /* priority */, 1566 UINT32_MAX /* priority */,
1543 GNUNET_TIME_UNIT_FOREVER_REL, 1567 GNUNET_TIME_UNIT_FOREVER_REL,
1544 GNUNET_YES, 1568 GNUNET_YES,
1545 NULL, NULL); 1569 NULL, NULL);
1546} 1570}
1547 1571
1548 1572
@@ -1555,97 +1579,105 @@ GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour,
1555 * @param m the message containing the keep alive response 1579 * @param m the message containing the keep alive response
1556 */ 1580 */
1557void 1581void
1558GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour, 1582GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1559 const struct GNUNET_MessageHeader *m) 1583 const struct GNUNET_MessageHeader *m)
1560{ 1584{
1561 struct NeighbourMapEntry *n; 1585 struct NeighbourMapEntry *n;
1562 const struct GNUNET_ATS_SessionKeepAliveMessage *msg; 1586 const struct GNUNET_ATS_SessionKeepAliveMessage *msg;
1563 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1587 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1564 struct GNUNET_TIME_Relative latency; 1588 struct GNUNET_TIME_Relative latency;
1565 1589
1566 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size)) 1590 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size))
1567 { 1591 {
1568 GNUNET_break_op(0); 1592 GNUNET_break_op (0);
1569 return; 1593 return;
1570 } 1594 }
1571 1595
1572 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m; 1596 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m;
1573 if (NULL == (n = lookup_neighbour(neighbour))) 1597 if (NULL == (n = lookup_neighbour (neighbour)))
1574 { 1598 {
1575 GNUNET_STATISTICS_update(GST_stats, 1599 GNUNET_STATISTICS_update (GST_stats,
1576 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not connected)"), 1600 gettext_noop (
1577 1, 1601 "# KEEPALIVE_RESPONSEs discarded (not connected)"),
1578 GNUNET_NO); 1602 1,
1579 return; 1603 GNUNET_NO);
1580 } 1604 return;
1605 }
1581 if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) || 1606 if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) ||
1582 (GNUNET_YES != n->expect_latency_response)) 1607 (GNUNET_YES != n->expect_latency_response))
1583 { 1608 {
1584 GNUNET_STATISTICS_update(GST_stats, 1609 GNUNET_STATISTICS_update (GST_stats,
1585 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not expected)"), 1610 gettext_noop (
1586 1, 1611 "# KEEPALIVE_RESPONSEs discarded (not expected)"),
1587 GNUNET_NO); 1612 1,
1588 return; 1613 GNUNET_NO);
1589 } 1614 return;
1615 }
1590 if (NULL == n->primary_address.address) 1616 if (NULL == n->primary_address.address)
1591 { 1617 {
1592 GNUNET_STATISTICS_update(GST_stats, 1618 GNUNET_STATISTICS_update (GST_stats,
1593 gettext_noop("# KEEPALIVE_RESPONSEs discarded (address changed)"), 1619 gettext_noop (
1594 1, 1620 "# KEEPALIVE_RESPONSEs discarded (address changed)"),
1595 GNUNET_NO); 1621 1,
1596 return; 1622 GNUNET_NO);
1597 } 1623 return;
1598 if (n->primary_address.keep_alive_nonce != ntohl(msg->nonce)) 1624 }
1599 { 1625 if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce))
1600 if (0 == n->primary_address.keep_alive_nonce) 1626 {
1601 GNUNET_STATISTICS_update(GST_stats, 1627 if (0 == n->primary_address.keep_alive_nonce)
1602 gettext_noop("# KEEPALIVE_RESPONSEs discarded (no nonce)"), 1628 GNUNET_STATISTICS_update (GST_stats,
1603 1, 1629 gettext_noop (
1604 GNUNET_NO); 1630 "# KEEPALIVE_RESPONSEs discarded (no nonce)"),
1605 else 1631 1,
1606 GNUNET_STATISTICS_update(GST_stats, 1632 GNUNET_NO);
1607 gettext_noop("# KEEPALIVE_RESPONSEs discarded (bad nonce)"), 1633 else
1608 1, 1634 GNUNET_STATISTICS_update (GST_stats,
1609 GNUNET_NO); 1635 gettext_noop (
1610 return; 1636 "# KEEPALIVE_RESPONSEs discarded (bad nonce)"),
1611 } 1637 1,
1612 GNUNET_STATISTICS_update(GST_stats, 1638 GNUNET_NO);
1613 gettext_noop("# KEEPALIVE_RESPONSEs received (OK)"), 1639 return;
1614 1, 1640 }
1615 GNUNET_NO); 1641 GNUNET_STATISTICS_update (GST_stats,
1642 gettext_noop (
1643 "# KEEPALIVE_RESPONSEs received (OK)"),
1644 1,
1645 GNUNET_NO);
1616 1646
1617 1647
1618 /* Update session timeout here */ 1648 /* Update session timeout here */
1619 if (NULL != (papi = GST_plugins_find(n->primary_address.address->transport_name))) 1649 if (NULL != (papi = GST_plugins_find (
1620 { 1650 n->primary_address.address->transport_name)))
1621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1651 {
1622 "Updating session for peer `%s' for session %p\n", 1652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1623 GNUNET_i2s(&n->id), 1653 "Updating session for peer `%s' for session %p\n",
1624 n->primary_address.session); 1654 GNUNET_i2s (&n->id),
1625 papi->update_session_timeout(papi->cls, 1655 n->primary_address.session);
1626 &n->id, 1656 papi->update_session_timeout (papi->cls,
1627 n->primary_address.session); 1657 &n->id,
1628 } 1658 n->primary_address.session);
1659 }
1629 else 1660 else
1630 { 1661 {
1631 GNUNET_break(0); 1662 GNUNET_break (0);
1632 } 1663 }
1633 1664
1634 n->primary_address.keep_alive_nonce = 0; 1665 n->primary_address.keep_alive_nonce = 0;
1635 n->expect_latency_response = GNUNET_NO; 1666 n->expect_latency_response = GNUNET_NO;
1636 set_state_and_timeout(n, 1667 set_state_and_timeout (n,
1637 n->state, 1668 n->state,
1638 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 1669 GNUNET_TIME_relative_to_absolute (
1639 1670 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
1640 latency = GNUNET_TIME_absolute_get_duration(n->last_keep_alive_time); 1671
1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1672 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time);
1642 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n", 1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1643 GNUNET_i2s(&n->id), 1674 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n",
1644 GNUNET_STRINGS_relative_time_to_string(latency, 1675 GNUNET_i2s (&n->id),
1645 GNUNET_YES)); 1676 GNUNET_STRINGS_relative_time_to_string (latency,
1646 GST_ats_update_delay(n->primary_address.address, 1677 GNUNET_YES));
1647 GNUNET_TIME_relative_divide(latency, 1678 GST_ats_update_delay (n->primary_address.address,
1648 2)); 1679 GNUNET_TIME_relative_divide (latency,
1680 2));
1649} 1681}
1650 1682
1651 1683
@@ -1662,74 +1694,76 @@ GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour,
1662 * @return how long to wait before reading more from this sender 1694 * @return how long to wait before reading more from this sender
1663 */ 1695 */
1664struct GNUNET_TIME_Relative 1696struct GNUNET_TIME_Relative
1665GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, 1697GST_neighbours_calculate_receive_delay (const struct
1666 ssize_t size, 1698 GNUNET_PeerIdentity *sender,
1667 int *do_forward) 1699 ssize_t size,
1700 int *do_forward)
1668{ 1701{
1669 struct NeighbourMapEntry *n; 1702 struct NeighbourMapEntry *n;
1670 struct GNUNET_TIME_Relative ret; 1703 struct GNUNET_TIME_Relative ret;
1671 1704
1672 if (NULL == neighbours) 1705 if (NULL == neighbours)
1673 { 1706 {
1674 *do_forward = GNUNET_NO; 1707 *do_forward = GNUNET_NO;
1675 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */ 1708 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */
1676 } 1709 }
1677 if (NULL == (n = lookup_neighbour(sender))) 1710 if (NULL == (n = lookup_neighbour (sender)))
1678 { 1711 {
1679 GNUNET_STATISTICS_update(GST_stats, 1712 GNUNET_STATISTICS_update (GST_stats,
1680 gettext_noop("# messages discarded due to lack of neighbour record"), 1713 gettext_noop (
1681 1, 1714 "# messages discarded due to lack of neighbour record"),
1682 GNUNET_NO); 1715 1,
1683 *do_forward = GNUNET_NO; 1716 GNUNET_NO);
1684 return GNUNET_TIME_UNIT_ZERO; 1717 *do_forward = GNUNET_NO;
1685 } 1718 return GNUNET_TIME_UNIT_ZERO;
1686 if (!test_connected(n)) 1719 }
1687 { 1720 if (! test_connected (n))
1688 *do_forward = GNUNET_SYSERR; 1721 {
1689 return GNUNET_TIME_UNIT_ZERO; 1722 *do_forward = GNUNET_SYSERR;
1690 } 1723 return GNUNET_TIME_UNIT_ZERO;
1691 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, size)) 1724 }
1692 { 1725 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
1693 n->quota_violation_count++; 1726 {
1694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1727 n->quota_violation_count++;
1695 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 1728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1696 n->in_tracker.available_bytes_per_s__, 1729 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
1697 n->quota_violation_count); 1730 n->in_tracker.available_bytes_per_s__,
1698 /* Discount 32k per violation */ 1731 n->quota_violation_count);
1699 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, -32 * 1024); 1732 /* Discount 32k per violation */
1700 } 1733 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
1734 }
1701 else 1735 else
1736 {
1737 if (n->quota_violation_count > 0)
1702 { 1738 {
1703 if (n->quota_violation_count > 0) 1739 /* try to add 32k back */
1704 { 1740 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
1705 /* try to add 32k back */ 1741 n->quota_violation_count--;
1706 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, 32 * 1024);
1707 n->quota_violation_count--;
1708 }
1709 } 1742 }
1743 }
1710 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 1744 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
1711 { 1745 {
1712 GNUNET_STATISTICS_update(GST_stats, 1746 GNUNET_STATISTICS_update (GST_stats,
1713 gettext_noop 1747 gettext_noop
1714 ("# bandwidth quota violations by other peers"), 1748 ("# bandwidth quota violations by other peers"),
1715 1, GNUNET_NO); 1749 1, GNUNET_NO);
1716 *do_forward = GNUNET_NO; 1750 *do_forward = GNUNET_NO;
1717 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; 1751 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
1718 } 1752 }
1719 *do_forward = GNUNET_YES; 1753 *do_forward = GNUNET_YES;
1720 ret = GNUNET_BANDWIDTH_tracker_get_delay(&n->in_tracker, 32 * 1024); 1754 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 32 * 1024);
1721 if (ret.rel_value_us > 0) 1755 if (ret.rel_value_us > 0)
1722 { 1756 {
1723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1724 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", 1758 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1725 (long long)n->in_tracker.consumption_since_last_update__, 1759 (long long) n->in_tracker.consumption_since_last_update__,
1726 (unsigned int)n->in_tracker.available_bytes_per_s__, 1760 (unsigned int) n->in_tracker.available_bytes_per_s__,
1727 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES)); 1761 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES));
1728 GNUNET_STATISTICS_update(GST_stats, 1762 GNUNET_STATISTICS_update (GST_stats,
1729 gettext_noop("# ms throttling suggested"), 1763 gettext_noop ("# ms throttling suggested"),
1730 (int64_t)ret.rel_value_us / 1000LL, 1764 (int64_t) ret.rel_value_us / 1000LL,
1731 GNUNET_NO); 1765 GNUNET_NO);
1732 } 1766 }
1733 return ret; 1767 return ret;
1734} 1768}
1735 1769
@@ -1745,61 +1779,61 @@ GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender,
1745 * @param cont_cls closure for @a cont 1779 * @param cont_cls closure for @a cont
1746 */ 1780 */
1747void 1781void
1748GST_neighbours_send(const struct GNUNET_PeerIdentity *target, 1782GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1749 const void *msg, 1783 const void *msg,
1750 size_t msg_size, 1784 size_t msg_size,
1751 struct GNUNET_TIME_Relative timeout, 1785 struct GNUNET_TIME_Relative timeout,
1752 GST_NeighbourSendContinuation cont, 1786 GST_NeighbourSendContinuation cont,
1753 void *cont_cls) 1787 void *cont_cls)
1754{ 1788{
1755 struct NeighbourMapEntry *n; 1789 struct NeighbourMapEntry *n;
1756 struct MessageQueue *mq; 1790 struct MessageQueue *mq;
1757 1791
1758 /* All ove these cases should never happen; they are all API violations. 1792 /* All ove these cases should never happen; they are all API violations.
1759 But we check anyway, just to be sure. */ 1793 But we check anyway, just to be sure. */
1760 if (NULL == (n = lookup_neighbour(target))) 1794 if (NULL == (n = lookup_neighbour (target)))
1761 { 1795 {
1762 GNUNET_break(0); 1796 GNUNET_break (0);
1763 if (NULL != cont) 1797 if (NULL != cont)
1764 cont(cont_cls, 1798 cont (cont_cls,
1765 GNUNET_SYSERR, 1799 GNUNET_SYSERR,
1766 msg_size, 1800 msg_size,
1767 0); 1801 0);
1768 return; 1802 return;
1769 } 1803 }
1770 if (GNUNET_YES != test_connected(n)) 1804 if (GNUNET_YES != test_connected (n))
1771 { 1805 {
1772 GNUNET_break(0); 1806 GNUNET_break (0);
1773 if (NULL != cont) 1807 if (NULL != cont)
1774 cont(cont_cls, 1808 cont (cont_cls,
1775 GNUNET_SYSERR, 1809 GNUNET_SYSERR,
1776 msg_size, 1810 msg_size,
1777 0); 1811 0);
1778 return; 1812 return;
1779 } 1813 }
1780 bytes_in_send_queue += msg_size; 1814 bytes_in_send_queue += msg_size;
1781 GNUNET_STATISTICS_set(GST_stats, 1815 GNUNET_STATISTICS_set (GST_stats,
1782 gettext_noop 1816 gettext_noop
1783 ("# bytes in message queue for other peers"), 1817 ("# bytes in message queue for other peers"),
1784 bytes_in_send_queue, GNUNET_NO); 1818 bytes_in_send_queue, GNUNET_NO);
1785 mq = GNUNET_malloc(sizeof(struct MessageQueue) + msg_size); 1819 mq = GNUNET_malloc (sizeof(struct MessageQueue) + msg_size);
1786 mq->cont = cont; 1820 mq->cont = cont;
1787 mq->cont_cls = cont_cls; 1821 mq->cont_cls = cont_cls;
1788 GNUNET_memcpy(&mq[1], msg, msg_size); 1822 GNUNET_memcpy (&mq[1], msg, msg_size);
1789 mq->message_buf = (const char *)&mq[1]; 1823 mq->message_buf = (const char *) &mq[1];
1790 mq->message_buf_size = msg_size; 1824 mq->message_buf_size = msg_size;
1791 mq->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1825 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1792 1826
1793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1794 "Enqueueing %u bytes to send to peer %s\n", 1828 "Enqueueing %u bytes to send to peer %s\n",
1795 (unsigned int)msg_size, 1829 (unsigned int) msg_size,
1796 GNUNET_i2s(target)); 1830 GNUNET_i2s (target));
1797 GNUNET_CONTAINER_DLL_insert_tail(n->messages_head, 1831 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
1798 n->messages_tail, 1832 n->messages_tail,
1799 mq); 1833 mq);
1800 if (NULL != n->task) 1834 if (NULL != n->task)
1801 GNUNET_SCHEDULER_cancel(n->task); 1835 GNUNET_SCHEDULER_cancel (n->task);
1802 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 1836 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1803} 1837}
1804 1838
1805 1839
@@ -1816,77 +1850,81 @@ GST_neighbours_send(const struct GNUNET_PeerIdentity *target,
1816 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 1850 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1817 */ 1851 */
1818static void 1852static void
1819send_session_syn_cont(void *cls, 1853send_session_syn_cont (void *cls,
1820 const struct GNUNET_PeerIdentity *target, 1854 const struct GNUNET_PeerIdentity *target,
1821 int result, 1855 int result,
1822 size_t size_payload, 1856 size_t size_payload,
1823 size_t size_on_wire) 1857 size_t size_on_wire)
1824{ 1858{
1825 struct NeighbourMapEntry *n; 1859 struct NeighbourMapEntry *n;
1826 1860
1827 (void)cls; 1861 (void) cls;
1828 (void)size_payload; 1862 (void) size_payload;
1829 (void)size_on_wire; 1863 (void) size_on_wire;
1830 n = lookup_neighbour(target); 1864 n = lookup_neighbour (target);
1831 if (NULL == n) 1865 if (NULL == n)
1832 { 1866 {
1833 /* SYN continuation was called after neighbor was freed, 1867 /* SYN continuation was called after neighbor was freed,
1834 * for example due to a time out for the state or the session 1868 * for example due to a time out for the state or the session
1835 * used was already terminated: nothing to do here... */ 1869 * used was already terminated: nothing to do here... */
1836 return; 1870 return;
1837 } 1871 }
1838 1872
1839 if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) && 1873 if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) &&
1840 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) && 1874 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) &&
1841 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state)) 1875 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state))
1842 { 1876 {
1843 /* SYN continuation was called after neighbor changed state, 1877 /* SYN continuation was called after neighbor changed state,
1844 * for example due to a time out for the state or the session 1878 * for example due to a time out for the state or the session
1845 * used was already terminated: nothing to do here... */ 1879 * used was already terminated: nothing to do here... */
1846 return; 1880 return;
1847 } 1881 }
1848 if (GNUNET_OK == result) 1882 if (GNUNET_OK == result)
1849 return; 1883 return;
1850 1884
1851 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1885 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1852 _("Failed to send SYN message to peer `%s'\n"), 1886 _ ("Failed to send SYN message to peer `%s'\n"),
1853 GNUNET_i2s(target)); 1887 GNUNET_i2s (target));
1854 switch (n->state) 1888 switch (n->state)
1855 { 1889 {
1856 case GNUNET_TRANSPORT_PS_SYN_SENT: 1890 case GNUNET_TRANSPORT_PS_SYN_SENT:
1857 /* Remove address and request an additional one */ 1891 /* Remove address and request an additional one */
1858 unset_primary_address(n); 1892 unset_primary_address (n);
1859 set_state_and_timeout(n, 1893 set_state_and_timeout (n,
1860 GNUNET_TRANSPORT_PS_INIT_ATS, 1894 GNUNET_TRANSPORT_PS_INIT_ATS,
1861 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); 1895 GNUNET_TIME_relative_to_absolute (
1862 break; 1896 FAST_RECONNECT_TIMEOUT));
1863 1897 break;
1864 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1898
1865 /* Remove address and request an additional one */ 1899 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1866 unset_primary_address(n); 1900 /* Remove address and request an additional one */
1867 set_state_and_timeout(n, 1901 unset_primary_address (n);
1868 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1902 set_state_and_timeout (n,
1869 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 1903 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1870 break; 1904 GNUNET_TIME_relative_to_absolute (
1871 1905 ATS_RESPONSE_TIMEOUT));
1872 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1906 break;
1873 /* Remove address and request and go back to primary address */ 1907
1874 GNUNET_STATISTICS_update(GST_stats, 1908 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1875 gettext_noop("# Failed attempts to switch addresses (failed to send SYN CONT)"), 1909 /* Remove address and request and go back to primary address */
1876 1, 1910 GNUNET_STATISTICS_update (GST_stats,
1877 GNUNET_NO); 1911 gettext_noop (
1878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1912 "# Failed attempts to switch addresses (failed to send SYN CONT)"),
1879 "Switch failed, cleaning up alternative address\n"); 1913 1,
1880 free_address(&n->alternative_address); 1914 GNUNET_NO);
1881 set_state_and_timeout(n, 1915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1882 GNUNET_TRANSPORT_PS_CONNECTED, 1916 "Switch failed, cleaning up alternative address\n");
1883 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 1917 free_address (&n->alternative_address);
1884 break; 1918 set_state_and_timeout (n,
1885 1919 GNUNET_TRANSPORT_PS_CONNECTED,
1886 default: 1920 GNUNET_TIME_relative_to_absolute (
1887 disconnect_neighbour(n); 1921 ATS_RESPONSE_TIMEOUT));
1888 break; 1922 break;
1889 } 1923
1924 default:
1925 disconnect_neighbour (n);
1926 break;
1927 }
1890} 1928}
1891 1929
1892 1930
@@ -1896,94 +1934,98 @@ send_session_syn_cont(void *cls,
1896 * @param na address to use 1934 * @param na address to use
1897 */ 1935 */
1898static void 1936static void
1899send_syn(struct NeighbourAddress *na) 1937send_syn (struct NeighbourAddress *na)
1900{ 1938{
1901 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1939 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1902 struct TransportSynMessage connect_msg; 1940 struct TransportSynMessage connect_msg;
1903 struct NeighbourMapEntry *n; 1941 struct NeighbourMapEntry *n;
1904 1942
1905 GNUNET_assert(NULL != na->session); 1943 GNUNET_assert (NULL != na->session);
1906 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1944 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1907 "Sending SYN message to peer `%s' at %s\n", 1945 "Sending SYN message to peer `%s' at %s\n",
1908 GNUNET_i2s(&na->address->peer), 1946 GNUNET_i2s (&na->address->peer),
1909 GST_plugins_a2s(na->address)); 1947 GST_plugins_a2s (na->address));
1910 1948
1911 papi = GST_plugins_find(na->address->transport_name); 1949 papi = GST_plugins_find (na->address->transport_name);
1912 GNUNET_assert(NULL != papi); 1950 GNUNET_assert (NULL != papi);
1913 GNUNET_STATISTICS_update(GST_stats, 1951 GNUNET_STATISTICS_update (GST_stats,
1914 gettext_noop 1952 gettext_noop
1915 ("# SYN messages sent"), 1953 ("# SYN messages sent"),
1916 1, GNUNET_NO); 1954 1, GNUNET_NO);
1917 na->connect_timestamp = GNUNET_TIME_absolute_get(); 1955 na->connect_timestamp = GNUNET_TIME_absolute_get ();
1918 connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); 1956 connect_msg.header.size = htons (sizeof(struct TransportSynMessage));
1919 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN); 1957 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN);
1920 connect_msg.reserved = htonl(0); 1958 connect_msg.reserved = htonl (0);
1921 connect_msg.timestamp = GNUNET_TIME_absolute_hton(na->connect_timestamp); 1959 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp);
1922 if (-1 == 1960 if (-1 ==
1923 papi->send(papi->cls, 1961 papi->send (papi->cls,
1924 na->session, 1962 na->session,
1925 (const char *)&connect_msg, 1963 (const char *) &connect_msg,
1926 sizeof(struct TransportSynMessage), 1964 sizeof(struct TransportSynMessage),
1927 UINT_MAX, 1965 UINT_MAX,
1928 SETUP_CONNECTION_TIMEOUT, 1966 SETUP_CONNECTION_TIMEOUT,
1929 &send_session_syn_cont, NULL)) 1967 &send_session_syn_cont, NULL))
1930 { 1968 {
1931 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1969 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1932 _("Failed to transmit SYN message to %s\n"), 1970 _ ("Failed to transmit SYN message to %s\n"),
1933 GST_plugins_a2s(na->address)); 1971 GST_plugins_a2s (na->address));
1934 n = lookup_neighbour(&na->address->peer); 1972 n = lookup_neighbour (&na->address->peer);
1935 if (NULL == n) 1973 if (NULL == n)
1936 { 1974 {
1937 GNUNET_break(0); 1975 GNUNET_break (0);
1938 return;
1939 }
1940 switch (n->state)
1941 {
1942 case GNUNET_TRANSPORT_PS_SYN_SENT:
1943 /* Remove address and request and additional one */
1944 GNUNET_assert(na == &n->primary_address);
1945 unset_primary_address(n);
1946 set_state_and_timeout(n,
1947 GNUNET_TRANSPORT_PS_INIT_ATS,
1948 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
1949 /* Hard failure to send the SYN message with this address:
1950 Destroy address and session */
1951 break;
1952
1953 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1954 /* Remove address and request an additional one */
1955 GNUNET_assert(na == &n->primary_address);
1956 unset_primary_address(n);
1957 set_state_and_timeout(n,
1958 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1959 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1960 break;
1961
1962 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1963 GNUNET_assert(na == &n->alternative_address);
1964 GNUNET_STATISTICS_update(GST_stats,
1965 gettext_noop("# Failed attempts to switch addresses (failed to send SYN)"),
1966 1,
1967 GNUNET_NO);
1968 /* Remove address and request an additional one */
1969 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1970 "Switch failed, cleaning up alternative address\n");
1971 free_address(&n->alternative_address);
1972 set_state_and_timeout(n,
1973 GNUNET_TRANSPORT_PS_CONNECTED,
1974 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1975 break;
1976
1977 default:
1978 GNUNET_break(0);
1979 disconnect_neighbour(n);
1980 break;
1981 }
1982 return; 1976 return;
1983 } 1977 }
1984 GST_neighbours_notify_data_sent(na->address, 1978 switch (n->state)
1985 na->session, 1979 {
1986 sizeof(struct TransportSynMessage)); 1980 case GNUNET_TRANSPORT_PS_SYN_SENT:
1981 /* Remove address and request and additional one */
1982 GNUNET_assert (na == &n->primary_address);
1983 unset_primary_address (n);
1984 set_state_and_timeout (n,
1985 GNUNET_TRANSPORT_PS_INIT_ATS,
1986 GNUNET_TIME_relative_to_absolute (
1987 FAST_RECONNECT_TIMEOUT));
1988 /* Hard failure to send the SYN message with this address:
1989 Destroy address and session */
1990 break;
1991
1992 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1993 /* Remove address and request an additional one */
1994 GNUNET_assert (na == &n->primary_address);
1995 unset_primary_address (n);
1996 set_state_and_timeout (n,
1997 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1998 GNUNET_TIME_relative_to_absolute (
1999 ATS_RESPONSE_TIMEOUT));
2000 break;
2001
2002 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2003 GNUNET_assert (na == &n->alternative_address);
2004 GNUNET_STATISTICS_update (GST_stats,
2005 gettext_noop (
2006 "# Failed attempts to switch addresses (failed to send SYN)"),
2007 1,
2008 GNUNET_NO);
2009 /* Remove address and request an additional one */
2010 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2011 "Switch failed, cleaning up alternative address\n");
2012 free_address (&n->alternative_address);
2013 set_state_and_timeout (n,
2014 GNUNET_TRANSPORT_PS_CONNECTED,
2015 GNUNET_TIME_relative_to_absolute (
2016 ATS_RESPONSE_TIMEOUT));
2017 break;
2018
2019 default:
2020 GNUNET_break (0);
2021 disconnect_neighbour (n);
2022 break;
2023 }
2024 return;
2025 }
2026 GST_neighbours_notify_data_sent (na->address,
2027 na->session,
2028 sizeof(struct TransportSynMessage));
1987} 2029}
1988 2030
1989 2031
@@ -2000,50 +2042,52 @@ send_syn(struct NeighbourAddress *na)
2000 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 2042 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
2001 */ 2043 */
2002static void 2044static void
2003send_session_syn_ack_cont(void *cls, 2045send_session_syn_ack_cont (void *cls,
2004 const struct GNUNET_PeerIdentity *target, 2046 const struct GNUNET_PeerIdentity *target,
2005 int result, 2047 int result,
2006 size_t size_payload, 2048 size_t size_payload,
2007 size_t size_on_wire) 2049 size_t size_on_wire)
2008{ 2050{
2009 struct NeighbourMapEntry *n; 2051 struct NeighbourMapEntry *n;
2010 2052
2011 (void)cls; 2053 (void) cls;
2012 (void)size_payload; 2054 (void) size_payload;
2013 (void)size_on_wire; 2055 (void) size_on_wire;
2014 n = lookup_neighbour(target); 2056 n = lookup_neighbour (target);
2015 if (NULL == n) 2057 if (NULL == n)
2016 { 2058 {
2017 /* SYN_ACK continuation was called after neighbor was freed, 2059 /* SYN_ACK continuation was called after neighbor was freed,
2018 * for example due to a time out for the state or the session 2060 * for example due to a time out for the state or the session
2019 * used was already terminated: nothing to do here... */ 2061 * used was already terminated: nothing to do here... */
2020 return; 2062 return;
2021 } 2063 }
2022 2064
2023 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) 2065 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state)
2024 { 2066 {
2025 /* SYN_ACK continuation was called after neighbor changed state, 2067 /* SYN_ACK continuation was called after neighbor changed state,
2026 * for example due to a time out for the state or the session 2068 * for example due to a time out for the state or the session
2027 * used was already terminated: nothing to do here... */ 2069 * used was already terminated: nothing to do here... */
2028 return; 2070 return;
2029 } 2071 }
2030 if (GNUNET_OK == result) 2072 if (GNUNET_OK == result)
2031 return; 2073 return;
2032 2074
2033 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2034 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), 2076 _ (
2035 GNUNET_i2s(target), 2077 "Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
2036 GST_plugins_a2s(n->primary_address.address)); 2078 GNUNET_i2s (target),
2079 GST_plugins_a2s (n->primary_address.address));
2037 2080
2038 /* Remove address and request and additional one */ 2081 /* Remove address and request and additional one */
2039 /* FIXME: what if the neighbour's primary address 2082 /* FIXME: what if the neighbour's primary address
2040 changed in the meantime? Might want to instead 2083 changed in the meantime? Might want to instead
2041 pass "something" around in closure to be sure. */ 2084 pass "something" around in closure to be sure. */
2042 unset_primary_address(n); 2085 unset_primary_address (n);
2043 n->ack_state = ACK_SEND_SYN_ACK; 2086 n->ack_state = ACK_SEND_SYN_ACK;
2044 set_state_and_timeout(n, 2087 set_state_and_timeout (n,
2045 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2088 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2046 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2089 GNUNET_TIME_relative_to_absolute (
2090 ATS_RESPONSE_TIMEOUT));
2047} 2091}
2048 2092
2049 2093
@@ -2055,8 +2099,8 @@ send_session_syn_ack_cont(void *cls,
2055 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise 2099 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise
2056 */ 2100 */
2057static void 2101static void
2058send_syn_ack_message(struct NeighbourAddress *na, 2102send_syn_ack_message (struct NeighbourAddress *na,
2059 struct GNUNET_TIME_Absolute timestamp) 2103 struct GNUNET_TIME_Absolute timestamp)
2060{ 2104{
2061 const struct GNUNET_HELLO_Address *address = na->address; 2105 const struct GNUNET_HELLO_Address *address = na->address;
2062 struct GNUNET_ATS_Session *session = na->session; 2106 struct GNUNET_ATS_Session *session = na->session;
@@ -2064,61 +2108,63 @@ send_syn_ack_message(struct NeighbourAddress *na,
2064 struct TransportSynMessage connect_msg; 2108 struct TransportSynMessage connect_msg;
2065 struct NeighbourMapEntry *n; 2109 struct NeighbourMapEntry *n;
2066 2110
2067 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2111 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2068 "Sending SYN_ACK to peer `%s'\n", 2112 "Sending SYN_ACK to peer `%s'\n",
2069 GNUNET_i2s(&address->peer)); 2113 GNUNET_i2s (&address->peer));
2070 2114
2071 if (NULL == (papi = GST_plugins_find(address->transport_name))) 2115 if (NULL == (papi = GST_plugins_find (address->transport_name)))
2072 { 2116 {
2073 GNUNET_break(0); 2117 GNUNET_break (0);
2074 return; 2118 return;
2075 } 2119 }
2076 if (NULL == session) 2120 if (NULL == session)
2077 session = papi->get_session(papi->cls, 2121 session = papi->get_session (papi->cls,
2078 address); 2122 address);
2079 if (NULL == session) 2123 if (NULL == session)
2080 { 2124 {
2081 GNUNET_break(0); 2125 GNUNET_break (0);
2082 return; 2126 return;
2083 } 2127 }
2084 GST_ats_new_session(address, 2128 GST_ats_new_session (address,
2085 session); 2129 session);
2086 GNUNET_STATISTICS_update(GST_stats, 2130 GNUNET_STATISTICS_update (GST_stats,
2087 gettext_noop 2131 gettext_noop
2088 ("# SYN_ACK messages sent"), 2132 ("# SYN_ACK messages sent"),
2089 1, GNUNET_NO); 2133 1, GNUNET_NO);
2090 connect_msg.header.size = htons(sizeof(struct TransportSynMessage)); 2134 connect_msg.header.size = htons (sizeof(struct TransportSynMessage));
2091 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK); 2135 connect_msg.header.type = htons (
2092 connect_msg.reserved = htonl(0); 2136 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK);
2093 connect_msg.timestamp = GNUNET_TIME_absolute_hton(timestamp); 2137 connect_msg.reserved = htonl (0);
2138 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp);
2094 2139
2095 if (GNUNET_SYSERR == 2140 if (GNUNET_SYSERR ==
2096 papi->send(papi->cls, 2141 papi->send (papi->cls,
2097 session, 2142 session,
2098 (const char *)&connect_msg, 2143 (const char *) &connect_msg,
2099 sizeof(struct TransportSynMessage), 2144 sizeof(struct TransportSynMessage),
2100 UINT_MAX, 2145 UINT_MAX,
2101 GNUNET_TIME_UNIT_FOREVER_REL, 2146 GNUNET_TIME_UNIT_FOREVER_REL,
2102 &send_session_syn_ack_cont, NULL)) 2147 &send_session_syn_ack_cont, NULL))
2103 { 2148 {
2104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2149 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2105 _("Failed to transmit SYN_ACK message to %s\n"), 2150 _ ("Failed to transmit SYN_ACK message to %s\n"),
2106 GST_plugins_a2s(address)); 2151 GST_plugins_a2s (address));
2107 2152
2108 n = lookup_neighbour(&address->peer); 2153 n = lookup_neighbour (&address->peer);
2109 if (NULL == n) 2154 if (NULL == n)
2110 { 2155 {
2111 GNUNET_break(0); 2156 GNUNET_break (0);
2112 return;
2113 }
2114 /* Remove address and request and additional one */
2115 unset_primary_address(n);
2116 n->ack_state = ACK_SEND_SYN_ACK;
2117 set_state_and_timeout(n,
2118 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2119 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2120 return; 2157 return;
2121 } 2158 }
2159 /* Remove address and request and additional one */
2160 unset_primary_address (n);
2161 n->ack_state = ACK_SEND_SYN_ACK;
2162 set_state_and_timeout (n,
2163 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2164 GNUNET_TIME_relative_to_absolute (
2165 ATS_RESPONSE_TIMEOUT));
2166 return;
2167 }
2122} 2168}
2123 2169
2124 2170
@@ -2131,7 +2177,7 @@ send_syn_ack_message(struct NeighbourAddress *na,
2131 * @param cls the `struct NeighbourMapEntry` to update calculations for 2177 * @param cls the `struct NeighbourMapEntry` to update calculations for
2132 */ 2178 */
2133static void 2179static void
2134inbound_bw_tracker_update(void *cls) 2180inbound_bw_tracker_update (void *cls)
2135{ 2181{
2136 struct NeighbourMapEntry *n = cls; 2182 struct NeighbourMapEntry *n = cls;
2137 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2183 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2140,23 +2186,23 @@ inbound_bw_tracker_update(void *cls)
2140 2186
2141 if (NULL == n->primary_address.address) 2187 if (NULL == n->primary_address.address)
2142 return; /* not active, ignore */ 2188 return; /* not active, ignore */
2143 papi = GST_plugins_find(n->primary_address.address->transport_name); 2189 papi = GST_plugins_find (n->primary_address.address->transport_name);
2144 GNUNET_assert(NULL != papi); 2190 GNUNET_assert (NULL != papi);
2145 if (NULL == papi->update_inbound_delay) 2191 if (NULL == papi->update_inbound_delay)
2146 return; 2192 return;
2147 delay = GST_neighbours_calculate_receive_delay(&n->id, 2193 delay = GST_neighbours_calculate_receive_delay (&n->id,
2148 0, 2194 0,
2149 &do_forward); 2195 &do_forward);
2150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2151 "New inbound delay for peer `%s' is %llu ms\n", 2197 "New inbound delay for peer `%s' is %llu ms\n",
2152 GNUNET_i2s(&n->id), 2198 GNUNET_i2s (&n->id),
2153 (unsigned long long)delay.rel_value_us / 1000LL); 2199 (unsigned long long) delay.rel_value_us / 1000LL);
2154 if (NULL == n->primary_address.session) 2200 if (NULL == n->primary_address.session)
2155 return; 2201 return;
2156 papi->update_inbound_delay(papi->cls, 2202 papi->update_inbound_delay (papi->cls,
2157 &n->id, 2203 &n->id,
2158 n->primary_address.session, 2204 n->primary_address.session,
2159 delay); 2205 delay);
2160} 2206}
2161 2207
2162 2208
@@ -2167,44 +2213,44 @@ inbound_bw_tracker_update(void *cls)
2167 * @return new neighbour map entry 2213 * @return new neighbour map entry
2168 */ 2214 */
2169static struct NeighbourMapEntry * 2215static struct NeighbourMapEntry *
2170setup_neighbour(const struct GNUNET_PeerIdentity *peer) 2216setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2171{ 2217{
2172 struct NeighbourMapEntry *n; 2218 struct NeighbourMapEntry *n;
2173 2219
2174 if (0 == 2220 if (0 ==
2175 memcmp(&GST_my_identity, 2221 memcmp (&GST_my_identity,
2176 peer, 2222 peer,
2177 sizeof(struct GNUNET_PeerIdentity))) 2223 sizeof(struct GNUNET_PeerIdentity)))
2178 { 2224 {
2179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2180 "Cowardly refusing to consider myself my neighbour!\n"); 2226 "Cowardly refusing to consider myself my neighbour!\n");
2181 return NULL; 2227 return NULL;
2182 } 2228 }
2183 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2184 "Creating new neighbour entry for `%s'\n", 2230 "Creating new neighbour entry for `%s'\n",
2185 GNUNET_i2s(peer)); 2231 GNUNET_i2s (peer));
2186 n = GNUNET_new(struct NeighbourMapEntry); 2232 n = GNUNET_new (struct NeighbourMapEntry);
2187 n->id = *peer; 2233 n->id = *peer;
2188 n->ack_state = ACK_UNDEFINED; 2234 n->ack_state = ACK_UNDEFINED;
2189 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2235 n->last_util_transmission = GNUNET_TIME_absolute_get ();
2190 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2236 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2191 GNUNET_BANDWIDTH_tracker_init(&n->in_tracker, 2237 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
2192 &inbound_bw_tracker_update, 2238 &inbound_bw_tracker_update,
2193 n, 2239 n,
2194 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 2240 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2195 MAX_BANDWIDTH_CARRY_S); 2241 MAX_BANDWIDTH_CARRY_S);
2196 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 2242 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
2197 set_state_and_timeout(n, 2243 set_state_and_timeout (n,
2198 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 2244 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
2199 GNUNET_TIME_UNIT_FOREVER_ABS); 2245 GNUNET_TIME_UNIT_FOREVER_ABS);
2200 GNUNET_assert(GNUNET_OK == 2246 GNUNET_assert (GNUNET_OK ==
2201 GNUNET_CONTAINER_multipeermap_put(neighbours, 2247 GNUNET_CONTAINER_multipeermap_put (neighbours,
2202 &n->id, 2248 &n->id,
2203 n, 2249 n,
2204 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2250 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2205 n->suggest_handle = GNUNET_ATS_connectivity_suggest(GST_ats_connect, 2251 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2206 peer, 2252 peer,
2207 0); 2253 0);
2208 2254
2209 return n; 2255 return n;
2210} 2256}
@@ -2213,7 +2259,8 @@ setup_neighbour(const struct GNUNET_PeerIdentity *peer)
2213/** 2259/**
2214 * Entry in a DLL we use to keep track of pending blacklist checks. 2260 * Entry in a DLL we use to keep track of pending blacklist checks.
2215 */ 2261 */
2216struct BlacklistCheckSwitchContext { 2262struct BlacklistCheckSwitchContext
2263{
2217 /** 2264 /**
2218 * DLL prev pointer. 2265 * DLL prev pointer.
2219 */ 2266 */
@@ -2250,145 +2297,149 @@ struct BlacklistCheckSwitchContext {
2250 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 2297 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2251 */ 2298 */
2252int 2299int
2253GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message, 2300GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2254 const struct GNUNET_PeerIdentity *peer) 2301 const struct GNUNET_PeerIdentity *peer)
2255{ 2302{
2256 const struct TransportSynMessage *scm; 2303 const struct TransportSynMessage *scm;
2257 struct NeighbourMapEntry *n; 2304 struct NeighbourMapEntry *n;
2258 struct GNUNET_TIME_Absolute ts; 2305 struct GNUNET_TIME_Absolute ts;
2259 2306
2260 if (ntohs(message->size) != sizeof(struct TransportSynMessage)) 2307 if (ntohs (message->size) != sizeof(struct TransportSynMessage))
2261 { 2308 {
2262 GNUNET_break_op(0); 2309 GNUNET_break_op (0);
2263 return GNUNET_SYSERR; 2310 return GNUNET_SYSERR;
2264 } 2311 }
2265 GNUNET_STATISTICS_update(GST_stats, 2312 GNUNET_STATISTICS_update (GST_stats,
2266 gettext_noop 2313 gettext_noop
2267 ("# SYN messages received"), 2314 ("# SYN messages received"),
2268 1, GNUNET_NO); 2315 1, GNUNET_NO);
2269 if (NULL == neighbours) 2316 if (NULL == neighbours)
2270 { 2317 {
2271 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2272 _("SYN request from peer `%s' ignored due impending shutdown\n"), 2319 _ (
2273 GNUNET_i2s(peer)); 2320 "SYN request from peer `%s' ignored due impending shutdown\n"),
2274 return GNUNET_OK; /* we're shutting down */ 2321 GNUNET_i2s (peer));
2275 } 2322 return GNUNET_OK; /* we're shutting down */
2276 scm = (const struct TransportSynMessage *)message; 2323 }
2277 GNUNET_break_op(0 == ntohl(scm->reserved)); 2324 scm = (const struct TransportSynMessage *) message;
2278 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); 2325 GNUNET_break_op (0 == ntohl (scm->reserved));
2326 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2279 if (0 == 2327 if (0 ==
2280 memcmp(&GST_my_identity, 2328 memcmp (&GST_my_identity,
2281 peer, 2329 peer,
2282 sizeof(struct GNUNET_PeerIdentity))) 2330 sizeof(struct GNUNET_PeerIdentity)))
2283 { 2331 {
2284 /* loopback connection-to-self, ignore */ 2332 /* loopback connection-to-self, ignore */
2285 return GNUNET_SYSERR; 2333 return GNUNET_SYSERR;
2286 } 2334 }
2287 n = lookup_neighbour(peer); 2335 n = lookup_neighbour (peer);
2288 if (NULL == n) 2336 if (NULL == n)
2289 { 2337 {
2290 /* This is a new neighbour and set to not connected */ 2338 /* This is a new neighbour and set to not connected */
2291 n = setup_neighbour(peer); 2339 n = setup_neighbour (peer);
2292 GNUNET_assert(NULL != n); 2340 GNUNET_assert (NULL != n);
2293 } 2341 }
2294 2342
2295 /* Remember this SYN message in neighbour */ 2343 /* Remember this SYN message in neighbour */
2296 n->ack_state = ACK_SEND_SYN_ACK; 2344 n->ack_state = ACK_SEND_SYN_ACK;
2297 n->connect_ack_timestamp = ts; 2345 n->connect_ack_timestamp = ts;
2298 2346
2299 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2347 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2300 "Received SYN for peer `%s' in state %s/%s\n", 2348 "Received SYN for peer `%s' in state %s/%s\n",
2301 GNUNET_i2s(peer), 2349 GNUNET_i2s (peer),
2302 GNUNET_TRANSPORT_ps2s(n->state), 2350 GNUNET_TRANSPORT_ps2s (n->state),
2303 print_ack_state(n->ack_state)); 2351 print_ack_state (n->ack_state));
2304 2352
2305 switch (n->state) 2353 switch (n->state)
2306 { 2354 {
2307 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2355 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2308 /* Request an address from ATS to send SYN_ACK to this peer */ 2356 /* Request an address from ATS to send SYN_ACK to this peer */
2309 set_state_and_timeout(n, 2357 set_state_and_timeout (n,
2310 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2358 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2311 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2359 GNUNET_TIME_relative_to_absolute (
2312 break; 2360 ATS_RESPONSE_TIMEOUT));
2313 2361 break;
2314 case GNUNET_TRANSPORT_PS_INIT_ATS: 2362
2315 /* SYN message takes priority over us asking ATS for address: 2363 case GNUNET_TRANSPORT_PS_INIT_ATS:
2316 * Wait for ATS to suggest an address and send SYN_ACK */ 2364 /* SYN message takes priority over us asking ATS for address:
2317 set_state_and_timeout(n, 2365 * Wait for ATS to suggest an address and send SYN_ACK */
2318 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2366 set_state_and_timeout (n,
2319 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2367 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2320 break; 2368 GNUNET_TIME_relative_to_absolute (
2321 2369 ATS_RESPONSE_TIMEOUT));
2322 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 2370 break;
2323 /* We already wait for an address to send an SYN_ACK */ 2371
2324 break; 2372 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2325 2373 /* We already wait for an address to send an SYN_ACK */
2326 case GNUNET_TRANSPORT_PS_SYN_SENT: 2374 break;
2327 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 2375
2328 /* Send ACK immediately */ 2376 case GNUNET_TRANSPORT_PS_SYN_SENT:
2329 n->ack_state = ACK_SEND_ACK; 2377 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2330 send_syn_ack_message(&n->primary_address, 2378 /* Send ACK immediately */
2331 ts); 2379 n->ack_state = ACK_SEND_ACK;
2332 break; 2380 send_syn_ack_message (&n->primary_address,
2333 2381 ts);
2334 case GNUNET_TRANSPORT_PS_CONNECTED: 2382 break;
2335 /* we are already connected and can thus send the ACK immediately */ 2383
2336 GNUNET_assert(NULL != n->primary_address.address); 2384 case GNUNET_TRANSPORT_PS_CONNECTED:
2337 GNUNET_assert(NULL != n->primary_address.session); 2385 /* we are already connected and can thus send the ACK immediately */
2338 n->ack_state = ACK_SEND_ACK; 2386 GNUNET_assert (NULL != n->primary_address.address);
2339 send_syn_ack_message(&n->primary_address, 2387 GNUNET_assert (NULL != n->primary_address.session);
2340 ts); 2388 n->ack_state = ACK_SEND_ACK;
2341 break; 2389 send_syn_ack_message (&n->primary_address,
2342 2390 ts);
2343 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2391 break;
2344 /* We wait for ATS address suggestion */ 2392
2345 break; 2393 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2346 2394 /* We wait for ATS address suggestion */
2347 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 2395 break;
2348 /* We received a SYN message while waiting for a SYN_ACK in fast 2396
2349 * reconnect. Send SYN_ACK immediately */ 2397 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2350 n->ack_state = ACK_SEND_ACK; 2398 /* We received a SYN message while waiting for a SYN_ACK in fast
2351 send_syn_ack_message(&n->primary_address, 2399 * reconnect. Send SYN_ACK immediately */
2352 n->connect_ack_timestamp); 2400 n->ack_state = ACK_SEND_ACK;
2353 break; 2401 send_syn_ack_message (&n->primary_address,
2354 2402 n->connect_ack_timestamp);
2355 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2403 break;
2356 /* We are already connected and can thus send the ACK immediately; 2404
2357 still, it can never hurt to have an alternative address, so also 2405 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2358 tell ATS about it */ 2406 /* We are already connected and can thus send the ACK immediately;
2359 GNUNET_assert(NULL != n->primary_address.address); 2407 still, it can never hurt to have an alternative address, so also
2360 GNUNET_assert(NULL != n->primary_address.session); 2408 tell ATS about it */
2361 n->ack_state = ACK_SEND_ACK; 2409 GNUNET_assert (NULL != n->primary_address.address);
2362 send_syn_ack_message(&n->primary_address, 2410 GNUNET_assert (NULL != n->primary_address.session);
2363 ts); 2411 n->ack_state = ACK_SEND_ACK;
2364 break; 2412 send_syn_ack_message (&n->primary_address,
2365 2413 ts);
2366 case GNUNET_TRANSPORT_PS_DISCONNECT: 2414 break;
2367 /* Get rid of remains and re-try */ 2415
2368 free_neighbour(n); 2416 case GNUNET_TRANSPORT_PS_DISCONNECT:
2369 n = setup_neighbour(peer); 2417 /* Get rid of remains and re-try */
2370 GNUNET_assert(NULL != n); 2418 free_neighbour (n);
2371 /* Remember the SYN time stamp for ACK message */ 2419 n = setup_neighbour (peer);
2372 n->ack_state = ACK_SEND_SYN_ACK; 2420 GNUNET_assert (NULL != n);
2373 n->connect_ack_timestamp = ts; 2421 /* Remember the SYN time stamp for ACK message */
2374 /* Request an address for the peer */ 2422 n->ack_state = ACK_SEND_SYN_ACK;
2375 set_state_and_timeout(n, 2423 n->connect_ack_timestamp = ts;
2376 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2424 /* Request an address for the peer */
2377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 2425 set_state_and_timeout (n,
2378 break; 2426 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2379 2427 GNUNET_TIME_relative_to_absolute (
2380 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2428 ATS_RESPONSE_TIMEOUT));
2381 /* should not be possible */ 2429 break;
2382 GNUNET_assert(0); 2430
2383 break; 2431 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2384 2432 /* should not be possible */
2385 default: 2433 GNUNET_assert (0);
2386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2434 break;
2387 "Unhandled state `%s'\n", 2435
2388 GNUNET_TRANSPORT_ps2s(n->state)); 2436 default:
2389 GNUNET_break(0); 2437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2390 return GNUNET_SYSERR; 2438 "Unhandled state `%s'\n",
2391 } 2439 GNUNET_TRANSPORT_ps2s (n->state));
2440 GNUNET_break (0);
2441 return GNUNET_SYSERR;
2442 }
2392 return GNUNET_OK; 2443 return GNUNET_OK;
2393} 2444}
2394 2445
@@ -2410,43 +2461,43 @@ GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message,
2410 * #GNUNET_NO if more extensive changes are required (address changed) 2461 * #GNUNET_NO if more extensive changes are required (address changed)
2411 */ 2462 */
2412static int 2463static int
2413try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address, 2464try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2414 struct GNUNET_ATS_Session *session, 2465 struct GNUNET_ATS_Session *session,
2415 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2466 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2416 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2467 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2417{ 2468{
2418 struct NeighbourMapEntry *n; 2469 struct NeighbourMapEntry *n;
2419 2470
2420 n = lookup_neighbour(&address->peer); 2471 n = lookup_neighbour (&address->peer);
2421 if ((NULL == n) || 2472 if ((NULL == n) ||
2422 (NULL == n->primary_address.address) || 2473 (NULL == n->primary_address.address) ||
2423 (0 != GNUNET_HELLO_address_cmp(address, 2474 (0 != GNUNET_HELLO_address_cmp (address,
2424 n->primary_address.address))) 2475 n->primary_address.address)))
2425 return GNUNET_NO; 2476 return GNUNET_NO;
2426 /* We are not really switching addresses, but merely adjusting 2477 /* We are not really switching addresses, but merely adjusting
2427 session and/or bandwidth, can do fast ATS update! */ 2478 session and/or bandwidth, can do fast ATS update! */
2428 if (session != n->primary_address.session) 2479 if (session != n->primary_address.session)
2429 { 2480 {
2430 /* switch to a different session, but keeping same address; could 2481 /* switch to a different session, but keeping same address; could
2431 happen if there is a 2nd inbound connection */ 2482 happen if there is a 2nd inbound connection */
2432 n->primary_address.session = session; 2483 n->primary_address.session = session;
2433 GNUNET_assert(GNUNET_YES == 2484 GNUNET_assert (GNUNET_YES ==
2434 GST_ats_is_known(n->primary_address.address, 2485 GST_ats_is_known (n->primary_address.address,
2435 n->primary_address.session)); 2486 n->primary_address.session));
2436 } 2487 }
2437 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 2488 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
2438 { 2489 {
2439 n->primary_address.bandwidth_in = bandwidth_in; 2490 n->primary_address.bandwidth_in = bandwidth_in;
2440 if (GNUNET_YES != 2491 if (GNUNET_YES !=
2441 set_incoming_quota(n, 2492 set_incoming_quota (n,
2442 bandwidth_in)) 2493 bandwidth_in))
2443 return GNUNET_NO; 2494 return GNUNET_NO;
2444 } 2495 }
2445 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 2496 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
2446 { 2497 {
2447 n->primary_address.bandwidth_out = bandwidth_out; 2498 n->primary_address.bandwidth_out = bandwidth_out;
2448 send_outbound_quota_to_clients(n); 2499 send_outbound_quota_to_clients (n);
2449 } 2500 }
2450 return GNUNET_OK; 2501 return GNUNET_OK;
2451} 2502}
2452 2503
@@ -2465,11 +2516,11 @@ try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address,
2465 * #GNUNET_SYSERR if operation was aborted 2516 * #GNUNET_SYSERR if operation was aborted
2466 */ 2517 */
2467static void 2518static void
2468switch_address_bl_check_cont(void *cls, 2519switch_address_bl_check_cont (void *cls,
2469 const struct GNUNET_PeerIdentity *peer, 2520 const struct GNUNET_PeerIdentity *peer,
2470 const struct GNUNET_HELLO_Address *address, 2521 const struct GNUNET_HELLO_Address *address,
2471 struct GNUNET_ATS_Session *session, 2522 struct GNUNET_ATS_Session *session,
2472 int result) 2523 int result)
2473{ 2524{
2474 struct BlacklistCheckSwitchContext *blc_ctx = cls; 2525 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2475 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2526 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2478,289 +2529,297 @@ switch_address_bl_check_cont(void *cls,
2478 if (GNUNET_SYSERR == result) 2529 if (GNUNET_SYSERR == result)
2479 goto cleanup; 2530 goto cleanup;
2480 2531
2481 papi = GST_plugins_find(address->transport_name); 2532 papi = GST_plugins_find (address->transport_name);
2482 if (NULL == papi) 2533 if (NULL == papi)
2483 { 2534 {
2484 /* This can happen during shutdown. */ 2535 /* This can happen during shutdown. */
2485 goto cleanup; 2536 goto cleanup;
2486 } 2537 }
2487 2538
2488 if (GNUNET_NO == result) 2539 if (GNUNET_NO == result)
2489 { 2540 {
2490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2491 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", 2542 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n",
2492 GST_plugins_a2s(address), 2543 GST_plugins_a2s (address),
2493 session, 2544 session,
2494 GNUNET_i2s(peer)); 2545 GNUNET_i2s (peer));
2495 GNUNET_STATISTICS_update(GST_stats, 2546 GNUNET_STATISTICS_update (GST_stats,
2496 "# ATS suggestions ignored (blacklist denied)", 2547 "# ATS suggestions ignored (blacklist denied)",
2497 1, 2548 1,
2498 GNUNET_NO); 2549 GNUNET_NO);
2499 if (NULL != session) 2550 if (NULL != session)
2500 papi->disconnect_session(papi->cls, 2551 papi->disconnect_session (papi->cls,
2501 session); 2552 session);
2502 if (GNUNET_YES != 2553 if (GNUNET_YES !=
2503 GNUNET_HELLO_address_check_option(address, 2554 GNUNET_HELLO_address_check_option (address,
2504 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 2555 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2505 GST_ats_block_address(address, 2556 GST_ats_block_address (address,
2506 NULL); 2557 NULL);
2507 goto cleanup; 2558 goto cleanup;
2508 } 2559 }
2509 2560
2510 2561
2511 if (NULL == session) 2562 if (NULL == session)
2512 { 2563 {
2513 /* need to create a session, ATS only gave us an address */ 2564 /* need to create a session, ATS only gave us an address */
2514 session = papi->get_session(papi->cls, 2565 session = papi->get_session (papi->cls,
2515 address); 2566 address);
2516 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2517 "Obtained new session for peer `%s' and address '%s': %p\n", 2568 "Obtained new session for peer `%s' and address '%s': %p\n",
2518 GNUNET_i2s(&address->peer), 2569 GNUNET_i2s (&address->peer),
2519 GST_plugins_a2s(address), 2570 GST_plugins_a2s (address),
2520 session); 2571 session);
2521 if (NULL != session) 2572 if (NULL != session)
2522 GST_ats_new_session(address, 2573 GST_ats_new_session (address,
2523 session); 2574 session);
2524 } 2575 }
2525 if (NULL == session) 2576 if (NULL == session)
2526 { 2577 {
2527 /* session creation failed, bad!, fail! */ 2578 /* session creation failed, bad!, fail! */
2528 GNUNET_STATISTICS_update(GST_stats, 2579 GNUNET_STATISTICS_update (GST_stats,
2529 "# ATS suggestions ignored (failed to create session)", 2580 "# ATS suggestions ignored (failed to create session)",
2530 1, 2581 1,
2531 GNUNET_NO); 2582 GNUNET_NO);
2532 /* No session could be obtained, remove blacklist check and clean up */ 2583 /* No session could be obtained, remove blacklist check and clean up */
2533 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2534 "Failed to obtain new session for peer `%s' and address '%s'\n", 2585 "Failed to obtain new session for peer `%s' and address '%s'\n",
2535 GNUNET_i2s(&address->peer), 2586 GNUNET_i2s (&address->peer),
2536 GST_plugins_a2s(address)); 2587 GST_plugins_a2s (address));
2537 GST_ats_block_address(address, 2588 GST_ats_block_address (address,
2538 session); 2589 session);
2539 goto cleanup; 2590 goto cleanup;
2540 } 2591 }
2541 2592
2542 /* We did this check already before going into blacklist, but 2593 /* We did this check already before going into blacklist, but
2543 it is theoretically possible that the situation changed in 2594 it is theoretically possible that the situation changed in
2544 the meantime, hence we check again here */ 2595 the meantime, hence we check again here */
2545 if (GNUNET_OK == 2596 if (GNUNET_OK ==
2546 try_run_fast_ats_update(address, 2597 try_run_fast_ats_update (address,
2547 session, 2598 session,
2548 blc_ctx->bandwidth_in, 2599 blc_ctx->bandwidth_in,
2549 blc_ctx->bandwidth_out)) 2600 blc_ctx->bandwidth_out))
2550 goto cleanup; /* was just a minor update, we're done */ 2601 goto cleanup; /* was just a minor update, we're done */
2551 2602
2552 /* check if we also need to setup the neighbour entry */ 2603 /* check if we also need to setup the neighbour entry */
2553 if (NULL == (n = lookup_neighbour(peer))) 2604 if (NULL == (n = lookup_neighbour (peer)))
2605 {
2606 n = setup_neighbour (peer);
2607 if (NULL == n)
2554 { 2608 {
2555 n = setup_neighbour(peer); 2609 /* not sure how this can happen... */
2556 if (NULL == n) 2610 GNUNET_break (0);
2557 { 2611 goto cleanup;
2558 /* not sure how this can happen... */
2559 GNUNET_break(0);
2560 goto cleanup;
2561 }
2562 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2563 } 2612 }
2613 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2614 }
2564 2615
2565 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2566 "Peer `%s' switches to address `%s'\n", 2617 "Peer `%s' switches to address `%s'\n",
2567 GNUNET_i2s(&address->peer), 2618 GNUNET_i2s (&address->peer),
2568 GST_plugins_a2s(address)); 2619 GST_plugins_a2s (address));
2569 2620
2570 switch (n->state) 2621 switch (n->state)
2571 { 2622 {
2572 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2623 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2573 GNUNET_break(0); 2624 GNUNET_break (0);
2574 GST_ats_block_address(address, 2625 GST_ats_block_address (address,
2575 session); 2626 session);
2576 free_neighbour(n); 2627 free_neighbour (n);
2577 return; 2628 return;
2578
2579 case GNUNET_TRANSPORT_PS_INIT_ATS:
2580 /* We requested an address and ATS suggests one:
2581 * set primary address and send SYN message*/
2582 set_primary_address(n,
2583 address,
2584 session,
2585 blc_ctx->bandwidth_in,
2586 blc_ctx->bandwidth_out);
2587 if (ACK_SEND_SYN_ACK == n->ack_state)
2588 {
2589 /* Send pending SYN_ACK message */
2590 n->ack_state = ACK_SEND_ACK;
2591 send_syn_ack_message(&n->primary_address,
2592 n->connect_ack_timestamp);
2593 }
2594 set_state_and_timeout(n,
2595 GNUNET_TRANSPORT_PS_SYN_SENT,
2596 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2597 send_syn(&n->primary_address);
2598 break;
2599
2600 case GNUNET_TRANSPORT_PS_SYN_SENT:
2601 /* ATS suggested a new address while waiting for an SYN_ACK:
2602 * Switch and send new SYN */
2603 /* ATS suggests a different address, switch again */
2604 set_primary_address(n,
2605 address,
2606 session,
2607 blc_ctx->bandwidth_in,
2608 blc_ctx->bandwidth_out);
2609 if (ACK_SEND_SYN_ACK == n->ack_state)
2610 {
2611 /* Send pending SYN_ACK message */
2612 n->ack_state = ACK_SEND_ACK;
2613 send_syn_ack_message(&n->primary_address,
2614 n->connect_ack_timestamp);
2615 }
2616 set_state_and_timeout(n,
2617 GNUNET_TRANSPORT_PS_SYN_SENT,
2618 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2619 send_syn(&n->primary_address);
2620 break;
2621
2622 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2623 /* We requested an address and ATS suggests one:
2624 * set primary address and send SYN_ACK message*/
2625 set_primary_address(n,
2626 address,
2627 session,
2628 blc_ctx->bandwidth_in,
2629 blc_ctx->bandwidth_out);
2630 /* Send an ACK message as a response to the SYN msg */
2631 set_state_and_timeout(n,
2632 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2633 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2634 send_syn_ack_message(&n->primary_address,
2635 n->connect_ack_timestamp);
2636 if ((ACK_SEND_SYN_ACK == n->ack_state) ||
2637 (ACK_UNDEFINED == n->ack_state))
2638 n->ack_state = ACK_SEND_ACK;
2639 break;
2640
2641 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2642 /* ATS asks us to switch while we were trying to connect; switch to new
2643 address and check blacklist again */
2644 if ((ACK_SEND_SYN_ACK == n->ack_state))
2645 {
2646 n->ack_state = ACK_SEND_ACK;
2647 send_syn_ack_message(&n->primary_address,
2648 n->connect_ack_timestamp);
2649 }
2650 set_primary_address(n,
2651 address,
2652 session,
2653 blc_ctx->bandwidth_in,
2654 blc_ctx->bandwidth_out);
2655 set_state_and_timeout(n,
2656 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2657 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2658 break;
2659
2660 case GNUNET_TRANSPORT_PS_CONNECTED:
2661 GNUNET_assert(NULL != n->primary_address.address);
2662 GNUNET_assert(NULL != n->primary_address.session);
2663 GNUNET_break(n->primary_address.session != session);
2664 /* ATS asks us to switch a life connection; see if we can get
2665 a SYN_ACK on it before we actually do this! */
2666 set_alternative_address(n,
2667 address,
2668 session,
2669 blc_ctx->bandwidth_in,
2670 blc_ctx->bandwidth_out);
2671 set_state_and_timeout(n,
2672 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2673 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2674 GNUNET_STATISTICS_update(GST_stats,
2675 gettext_noop("# Attempts to switch addresses"),
2676 1,
2677 GNUNET_NO);
2678 send_syn(&n->alternative_address);
2679 break;
2680
2681 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2682 set_primary_address(n,
2683 address,
2684 session,
2685 blc_ctx->bandwidth_in,
2686 blc_ctx->bandwidth_out);
2687 if (ACK_SEND_SYN_ACK == n->ack_state)
2688 {
2689 /* Send pending SYN_ACK message */
2690 n->ack_state = ACK_SEND_ACK;
2691 send_syn_ack_message(&n->primary_address,
2692 n->connect_ack_timestamp);
2693 }
2694 set_state_and_timeout(n,
2695 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2696 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
2697 send_syn(&n->primary_address);
2698 break;
2699
2700 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2701 /* ATS asks us to switch while we were trying to reconnect; switch to new
2702 address and send SYN again */
2703 set_primary_address(n,
2704 address,
2705 session,
2706 blc_ctx->bandwidth_in,
2707 blc_ctx->bandwidth_out);
2708 set_state_and_timeout(n,
2709 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2710 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
2711 send_syn(&n->primary_address);
2712 break;
2713
2714 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2715 if ((0 == GNUNET_HELLO_address_cmp(n->primary_address.address,
2716 address)) &&
2717 (n->primary_address.session == session))
2718 {
2719 /* ATS switches back to still-active session */
2720 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2721 "ATS double-switched, cleaning up alternative address\n");
2722 free_address(&n->alternative_address);
2723 set_state_and_timeout(n,
2724 GNUNET_TRANSPORT_PS_CONNECTED,
2725 n->timeout);
2726 break;
2727 }
2728 /* ATS asks us to switch a life connection, send */
2729 set_alternative_address(n,
2730 address,
2731 session,
2732 blc_ctx->bandwidth_in,
2733 blc_ctx->bandwidth_out);
2734 set_state_and_timeout(n,
2735 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2736 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2737 send_syn(&n->alternative_address);
2738 break;
2739
2740 case GNUNET_TRANSPORT_PS_DISCONNECT:
2741 /* not going to switch addresses while disconnecting */
2742 GNUNET_STATISTICS_update(GST_stats,
2743 "# ATS suggestion ignored (disconnecting)",
2744 1,
2745 GNUNET_NO);
2746 return;
2747 2629
2748 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2630 case GNUNET_TRANSPORT_PS_INIT_ATS:
2749 GNUNET_assert(0); 2631 /* We requested an address and ATS suggests one:
2750 break; 2632 * set primary address and send SYN message*/
2633 set_primary_address (n,
2634 address,
2635 session,
2636 blc_ctx->bandwidth_in,
2637 blc_ctx->bandwidth_out);
2638 if (ACK_SEND_SYN_ACK == n->ack_state)
2639 {
2640 /* Send pending SYN_ACK message */
2641 n->ack_state = ACK_SEND_ACK;
2642 send_syn_ack_message (&n->primary_address,
2643 n->connect_ack_timestamp);
2644 }
2645 set_state_and_timeout (n,
2646 GNUNET_TRANSPORT_PS_SYN_SENT,
2647 GNUNET_TIME_relative_to_absolute (
2648 SETUP_CONNECTION_TIMEOUT));
2649 send_syn (&n->primary_address);
2650 break;
2651
2652 case GNUNET_TRANSPORT_PS_SYN_SENT:
2653 /* ATS suggested a new address while waiting for an SYN_ACK:
2654 * Switch and send new SYN */
2655 /* ATS suggests a different address, switch again */
2656 set_primary_address (n,
2657 address,
2658 session,
2659 blc_ctx->bandwidth_in,
2660 blc_ctx->bandwidth_out);
2661 if (ACK_SEND_SYN_ACK == n->ack_state)
2662 {
2663 /* Send pending SYN_ACK message */
2664 n->ack_state = ACK_SEND_ACK;
2665 send_syn_ack_message (&n->primary_address,
2666 n->connect_ack_timestamp);
2667 }
2668 set_state_and_timeout (n,
2669 GNUNET_TRANSPORT_PS_SYN_SENT,
2670 GNUNET_TIME_relative_to_absolute (
2671 SETUP_CONNECTION_TIMEOUT));
2672 send_syn (&n->primary_address);
2673 break;
2674
2675 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2676 /* We requested an address and ATS suggests one:
2677 * set primary address and send SYN_ACK message*/
2678 set_primary_address (n,
2679 address,
2680 session,
2681 blc_ctx->bandwidth_in,
2682 blc_ctx->bandwidth_out);
2683 /* Send an ACK message as a response to the SYN msg */
2684 set_state_and_timeout (n,
2685 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2686 GNUNET_TIME_relative_to_absolute (
2687 SETUP_CONNECTION_TIMEOUT));
2688 send_syn_ack_message (&n->primary_address,
2689 n->connect_ack_timestamp);
2690 if ((ACK_SEND_SYN_ACK == n->ack_state) ||
2691 (ACK_UNDEFINED == n->ack_state))
2692 n->ack_state = ACK_SEND_ACK;
2693 break;
2751 2694
2752 default: 2695 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2753 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2696 /* ATS asks us to switch while we were trying to connect; switch to new
2754 "Unhandled state `%s'\n", 2697 address and check blacklist again */
2755 GNUNET_TRANSPORT_ps2s(n->state)); 2698 if ((ACK_SEND_SYN_ACK == n->ack_state))
2756 GNUNET_break(0); 2699 {
2700 n->ack_state = ACK_SEND_ACK;
2701 send_syn_ack_message (&n->primary_address,
2702 n->connect_ack_timestamp);
2703 }
2704 set_primary_address (n,
2705 address,
2706 session,
2707 blc_ctx->bandwidth_in,
2708 blc_ctx->bandwidth_out);
2709 set_state_and_timeout (n,
2710 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2711 GNUNET_TIME_relative_to_absolute (
2712 SETUP_CONNECTION_TIMEOUT));
2713 break;
2714
2715 case GNUNET_TRANSPORT_PS_CONNECTED:
2716 GNUNET_assert (NULL != n->primary_address.address);
2717 GNUNET_assert (NULL != n->primary_address.session);
2718 GNUNET_break (n->primary_address.session != session);
2719 /* ATS asks us to switch a life connection; see if we can get
2720 a SYN_ACK on it before we actually do this! */
2721 set_alternative_address (n,
2722 address,
2723 session,
2724 blc_ctx->bandwidth_in,
2725 blc_ctx->bandwidth_out);
2726 set_state_and_timeout (n,
2727 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2728 GNUNET_TIME_relative_to_absolute (
2729 SETUP_CONNECTION_TIMEOUT));
2730 GNUNET_STATISTICS_update (GST_stats,
2731 gettext_noop ("# Attempts to switch addresses"),
2732 1,
2733 GNUNET_NO);
2734 send_syn (&n->alternative_address);
2735 break;
2736
2737 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2738 set_primary_address (n,
2739 address,
2740 session,
2741 blc_ctx->bandwidth_in,
2742 blc_ctx->bandwidth_out);
2743 if (ACK_SEND_SYN_ACK == n->ack_state)
2744 {
2745 /* Send pending SYN_ACK message */
2746 n->ack_state = ACK_SEND_ACK;
2747 send_syn_ack_message (&n->primary_address,
2748 n->connect_ack_timestamp);
2749 }
2750 set_state_and_timeout (n,
2751 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2752 GNUNET_TIME_relative_to_absolute (
2753 FAST_RECONNECT_TIMEOUT));
2754 send_syn (&n->primary_address);
2755 break;
2756
2757 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2758 /* ATS asks us to switch while we were trying to reconnect; switch to new
2759 address and send SYN again */
2760 set_primary_address (n,
2761 address,
2762 session,
2763 blc_ctx->bandwidth_in,
2764 blc_ctx->bandwidth_out);
2765 set_state_and_timeout (n,
2766 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
2767 GNUNET_TIME_relative_to_absolute (
2768 FAST_RECONNECT_TIMEOUT));
2769 send_syn (&n->primary_address);
2770 break;
2771
2772 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2773 if ((0 == GNUNET_HELLO_address_cmp (n->primary_address.address,
2774 address)) &&
2775 (n->primary_address.session == session))
2776 {
2777 /* ATS switches back to still-active session */
2778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2779 "ATS double-switched, cleaning up alternative address\n");
2780 free_address (&n->alternative_address);
2781 set_state_and_timeout (n,
2782 GNUNET_TRANSPORT_PS_CONNECTED,
2783 n->timeout);
2757 break; 2784 break;
2758 } 2785 }
2786 /* ATS asks us to switch a life connection, send */
2787 set_alternative_address (n,
2788 address,
2789 session,
2790 blc_ctx->bandwidth_in,
2791 blc_ctx->bandwidth_out);
2792 set_state_and_timeout (n,
2793 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2794 GNUNET_TIME_relative_to_absolute (
2795 SETUP_CONNECTION_TIMEOUT));
2796 send_syn (&n->alternative_address);
2797 break;
2798
2799 case GNUNET_TRANSPORT_PS_DISCONNECT:
2800 /* not going to switch addresses while disconnecting */
2801 GNUNET_STATISTICS_update (GST_stats,
2802 "# ATS suggestion ignored (disconnecting)",
2803 1,
2804 GNUNET_NO);
2805 return;
2806
2807 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2808 GNUNET_assert (0);
2809 break;
2810
2811 default:
2812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2813 "Unhandled state `%s'\n",
2814 GNUNET_TRANSPORT_ps2s (n->state));
2815 GNUNET_break (0);
2816 break;
2817 }
2759cleanup: 2818cleanup:
2760 GNUNET_CONTAINER_DLL_remove(pending_bc_head, 2819 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2761 pending_bc_tail, 2820 pending_bc_tail,
2762 blc_ctx); 2821 blc_ctx);
2763 GNUNET_free(blc_ctx); 2822 GNUNET_free (blc_ctx);
2764} 2823}
2765 2824
2766 2825
@@ -2782,65 +2841,67 @@ cleanup:
2782 * 0 to disconnect from peer 2841 * 0 to disconnect from peer
2783 */ 2842 */
2784void 2843void
2785GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address, 2844GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2786 struct GNUNET_ATS_Session *session, 2845 struct GNUNET_ATS_Session *session,
2787 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2846 struct GNUNET_BANDWIDTH_Value32NBO
2788 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2847 bandwidth_in,
2848 struct GNUNET_BANDWIDTH_Value32NBO
2849 bandwidth_out)
2789{ 2850{
2790 struct GST_BlacklistCheck *blc; 2851 struct GST_BlacklistCheck *blc;
2791 struct BlacklistCheckSwitchContext *blc_ctx; 2852 struct BlacklistCheckSwitchContext *blc_ctx;
2792 2853
2793 GNUNET_assert(NULL != address->transport_name); 2854 GNUNET_assert (NULL != address->transport_name);
2794 if (GNUNET_OK == 2855 if (GNUNET_OK ==
2795 try_run_fast_ats_update(address, 2856 try_run_fast_ats_update (address,
2796 session, 2857 session,
2797 bandwidth_in, 2858 bandwidth_in,
2798 bandwidth_out)) 2859 bandwidth_out))
2799 return; 2860 return;
2800 2861
2801 /* Check if plugin is available */ 2862 /* Check if plugin is available */
2802 if (NULL == (GST_plugins_find(address->transport_name))) 2863 if (NULL == (GST_plugins_find (address->transport_name)))
2803 { 2864 {
2804 /* we don't have the plugin for this address */ 2865 /* we don't have the plugin for this address */
2805 GNUNET_break(0); 2866 GNUNET_break (0);
2806 GST_ats_block_address(address, 2867 GST_ats_block_address (address,
2807 session); 2868 session);
2808 return; 2869 return;
2809 } 2870 }
2810 if ((NULL == session) && 2871 if ((NULL == session) &&
2811 (GNUNET_HELLO_address_check_option(address, 2872 (GNUNET_HELLO_address_check_option (address,
2812 GNUNET_HELLO_ADDRESS_INFO_INBOUND))) 2873 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
2813 { 2874 {
2814 /* This is a inbound address and we do not have a session to use! */ 2875 /* This is a inbound address and we do not have a session to use! */
2815 GNUNET_break(0); 2876 GNUNET_break (0);
2816 GST_ats_block_address(address, 2877 GST_ats_block_address (address,
2817 session); 2878 session);
2818 return; 2879 return;
2819 } 2880 }
2820 2881
2821 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2822 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n", 2883 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n",
2823 GST_plugins_a2s(address), 2884 GST_plugins_a2s (address),
2824 GNUNET_i2s(&address->peer), 2885 GNUNET_i2s (&address->peer),
2825 (unsigned int)ntohl(bandwidth_in.value__), 2886 (unsigned int) ntohl (bandwidth_in.value__),
2826 (unsigned int)ntohl(bandwidth_out.value__)); 2887 (unsigned int) ntohl (bandwidth_out.value__));
2827 2888
2828 /* Perform blacklist check */ 2889 /* Perform blacklist check */
2829 blc_ctx = GNUNET_new(struct BlacklistCheckSwitchContext); 2890 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2830 blc_ctx->bandwidth_in = bandwidth_in; 2891 blc_ctx->bandwidth_in = bandwidth_in;
2831 blc_ctx->bandwidth_out = bandwidth_out; 2892 blc_ctx->bandwidth_out = bandwidth_out;
2832 GNUNET_CONTAINER_DLL_insert(pending_bc_head, 2893 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
2833 pending_bc_tail, 2894 pending_bc_tail,
2834 blc_ctx); 2895 blc_ctx);
2835 if (NULL != (blc = GST_blacklist_test_allowed(&address->peer, 2896 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer,
2836 address->transport_name, 2897 address->transport_name,
2837 &switch_address_bl_check_cont, 2898 &switch_address_bl_check_cont,
2838 blc_ctx, 2899 blc_ctx,
2839 address, 2900 address,
2840 session))) 2901 session)))
2841 { 2902 {
2842 blc_ctx->blc = blc; 2903 blc_ctx->blc = blc;
2843 } 2904 }
2844} 2905}
2845 2906
2846 2907
@@ -2854,39 +2915,40 @@ GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address,
2854 * @return #GNUNET_OK (continue to iterate) 2915 * @return #GNUNET_OK (continue to iterate)
2855 */ 2916 */
2856static int 2917static int
2857send_utilization_data(void *cls, 2918send_utilization_data (void *cls,
2858 const struct GNUNET_PeerIdentity *key, 2919 const struct GNUNET_PeerIdentity *key,
2859 void *value) 2920 void *value)
2860{ 2921{
2861 struct NeighbourMapEntry *n = value; 2922 struct NeighbourMapEntry *n = value;
2862 uint32_t bps_in; 2923 uint32_t bps_in;
2863 uint32_t bps_out; 2924 uint32_t bps_out;
2864 struct GNUNET_TIME_Relative delta; 2925 struct GNUNET_TIME_Relative delta;
2865 2926
2866 (void)cls; 2927 (void) cls;
2867 if ((GNUNET_YES != test_connected(n)) || 2928 if ((GNUNET_YES != test_connected (n)) ||
2868 (NULL == n->primary_address.address)) 2929 (NULL == n->primary_address.address))
2869 return GNUNET_OK; 2930 return GNUNET_OK;
2870 delta = GNUNET_TIME_absolute_get_difference(n->last_util_transmission, 2931 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission,
2871 GNUNET_TIME_absolute_get()); 2932 GNUNET_TIME_absolute_get ());
2872 bps_in = 0; 2933 bps_in = 0;
2873 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us)) 2934 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us))
2874 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us); 2935 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv)
2936 / (delta.rel_value_us);
2875 bps_out = 0; 2937 bps_out = 0;
2876 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us)) 2938 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us))
2877 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us; 2939 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us;
2878 2940
2879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2941 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2880 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n", 2942 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n",
2881 GNUNET_i2s(key), 2943 GNUNET_i2s (key),
2882 bps_in, 2944 bps_in,
2883 bps_out); 2945 bps_out);
2884 GST_ats_update_utilization(n->primary_address.address, 2946 GST_ats_update_utilization (n->primary_address.address,
2885 bps_in, 2947 bps_in,
2886 bps_out); 2948 bps_out);
2887 n->util_total_bytes_recv = 0; 2949 n->util_total_bytes_recv = 0;
2888 n->util_total_bytes_sent = 0; 2950 n->util_total_bytes_sent = 0;
2889 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2951 n->last_util_transmission = GNUNET_TIME_absolute_get ();
2890 return GNUNET_OK; 2952 return GNUNET_OK;
2891} 2953}
2892 2954
@@ -2897,17 +2959,17 @@ send_utilization_data(void *cls,
2897 * @param cls the `struct NeighbourMapEntry` for which we are running 2959 * @param cls the `struct NeighbourMapEntry` for which we are running
2898 */ 2960 */
2899static void 2961static void
2900utilization_transmission(void *cls) 2962utilization_transmission (void *cls)
2901{ 2963{
2902 (void)cls; 2964 (void) cls;
2903 util_transmission_tk = NULL; 2965 util_transmission_tk = NULL;
2904 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 2966 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
2905 &send_utilization_data, 2967 &send_utilization_data,
2906 NULL); 2968 NULL);
2907 util_transmission_tk 2969 util_transmission_tk
2908 = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, 2970 = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL,
2909 &utilization_transmission, 2971 &utilization_transmission,
2910 NULL); 2972 NULL);
2911} 2973}
2912 2974
2913 2975
@@ -2920,15 +2982,15 @@ utilization_transmission(void *cls)
2920 * @param message the message we received (really only the size is used) 2982 * @param message the message we received (really only the size is used)
2921 */ 2983 */
2922void 2984void
2923GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address, 2985GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
2924 const struct GNUNET_MessageHeader *message) 2986 const struct GNUNET_MessageHeader *message)
2925{ 2987{
2926 struct NeighbourMapEntry *n; 2988 struct NeighbourMapEntry *n;
2927 2989
2928 n = lookup_neighbour(&address->peer); 2990 n = lookup_neighbour (&address->peer);
2929 if (NULL == n) 2991 if (NULL == n)
2930 return; 2992 return;
2931 n->util_total_bytes_recv += ntohs(message->size); 2993 n->util_total_bytes_recv += ntohs (message->size);
2932} 2994}
2933 2995
2934 2996
@@ -2942,13 +3004,13 @@ GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address,
2942 * @param message the message we sent (really only the size is used) 3004 * @param message the message we sent (really only the size is used)
2943 */ 3005 */
2944void 3006void
2945GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, 3007GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
2946 struct GNUNET_ATS_Session *session, 3008 struct GNUNET_ATS_Session *session,
2947 size_t size) 3009 size_t size)
2948{ 3010{
2949 struct NeighbourMapEntry *n; 3011 struct NeighbourMapEntry *n;
2950 3012
2951 n = lookup_neighbour(&address->peer); 3013 n = lookup_neighbour (&address->peer);
2952 if (NULL == n) 3014 if (NULL == n)
2953 return; 3015 return;
2954 if (n->primary_address.session != session) 3016 if (n->primary_address.session != session)
@@ -2965,157 +3027,160 @@ GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address,
2965 * @param cls the 'struct NeighbourMapEntry' for which we are running 3027 * @param cls the 'struct NeighbourMapEntry' for which we are running
2966 */ 3028 */
2967static void 3029static void
2968master_task(void *cls) 3030master_task (void *cls)
2969{ 3031{
2970 struct NeighbourMapEntry *n = cls; 3032 struct NeighbourMapEntry *n = cls;
2971 struct GNUNET_TIME_Relative delay; 3033 struct GNUNET_TIME_Relative delay;
2972 3034
2973 n->task = NULL; 3035 n->task = NULL;
2974 delay = GNUNET_TIME_absolute_get_remaining(n->timeout); 3036 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
2975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2976 "Master task runs for neighbour `%s' in state %s with timeout in %s\n", 3038 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2977 GNUNET_i2s(&n->id), 3039 GNUNET_i2s (&n->id),
2978 GNUNET_TRANSPORT_ps2s(n->state), 3040 GNUNET_TRANSPORT_ps2s (n->state),
2979 GNUNET_STRINGS_relative_time_to_string(delay, 3041 GNUNET_STRINGS_relative_time_to_string (delay,
2980 GNUNET_YES)); 3042 GNUNET_YES));
2981 switch (n->state) 3043 switch (n->state)
3044 {
3045 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3046 /* invalid state for master task, clean up */
3047 GNUNET_break (0);
3048 free_neighbour (n);
3049 return;
3050
3051 case GNUNET_TRANSPORT_PS_INIT_ATS:
3052 if (0 == delay.rel_value_us)
2982 { 3053 {
2983 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3054 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2984 /* invalid state for master task, clean up */ 3055 "Connection to `%s' timed out waiting for ATS to provide address\n",
2985 GNUNET_break(0); 3056 GNUNET_i2s (&n->id));
2986 free_neighbour(n); 3057 free_neighbour (n);
2987 return; 3058 return;
3059 }
3060 break;
2988 3061
2989 case GNUNET_TRANSPORT_PS_INIT_ATS: 3062 case GNUNET_TRANSPORT_PS_SYN_SENT:
2990 if (0 == delay.rel_value_us) 3063 if (0 == delay.rel_value_us)
2991 { 3064 {
2992 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3065 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2993 "Connection to `%s' timed out waiting for ATS to provide address\n", 3066 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
2994 GNUNET_i2s(&n->id)); 3067 GNUNET_i2s (&n->id));
2995 free_neighbour(n); 3068 /* Remove address and request and additional one */
2996 return; 3069 unset_primary_address (n);
2997 } 3070 set_state_and_timeout (n,
2998 break; 3071 GNUNET_TRANSPORT_PS_INIT_ATS,
2999 3072 GNUNET_TIME_relative_to_absolute (
3000 case GNUNET_TRANSPORT_PS_SYN_SENT: 3073 ATS_RESPONSE_TIMEOUT));
3001 if (0 == delay.rel_value_us) 3074 return;
3002 { 3075 }
3003 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3076 break;
3004 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
3005 GNUNET_i2s(&n->id));
3006 /* Remove address and request and additional one */
3007 unset_primary_address(n);
3008 set_state_and_timeout(n,
3009 GNUNET_TRANSPORT_PS_INIT_ATS,
3010 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3011 return;
3012 }
3013 break;
3014
3015 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3016 if (0 == delay.rel_value_us)
3017 {
3018 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3019 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3020 GNUNET_i2s(&n->id));
3021 free_neighbour(n);
3022 return;
3023 }
3024 break;
3025
3026 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3027 if (0 == delay.rel_value_us)
3028 {
3029 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3030 "Connection to `%s' timed out waiting for other peer to send ACK\n",
3031 GNUNET_i2s(&n->id));
3032 disconnect_neighbour(n);
3033 return;
3034 }
3035 break;
3036
3037 case GNUNET_TRANSPORT_PS_CONNECTED:
3038 if (0 == delay.rel_value_us)
3039 {
3040 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3041 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3042 GNUNET_i2s(&n->id));
3043 disconnect_neighbour(n);
3044 return;
3045 }
3046 try_transmission_to_peer(n);
3047 send_keepalive(n);
3048 break;
3049 3077
3050 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3078 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3051 if (0 == delay.rel_value_us) 3079 if (0 == delay.rel_value_us)
3052 { 3080 {
3053 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3081 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3054 "Connection to `%s' timed out, waiting for ATS replacement address\n", 3082 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3055 GNUNET_i2s(&n->id)); 3083 GNUNET_i2s (&n->id));
3056 disconnect_neighbour(n); 3084 free_neighbour (n);
3057 return; 3085 return;
3058 } 3086 }
3059 break; 3087 break;
3060 3088
3061 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3089 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3062 if (0 == delay.rel_value_us) 3090 if (0 == delay.rel_value_us)
3063 { 3091 {
3064 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3092 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3065 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n", 3093 "Connection to `%s' timed out waiting for other peer to send ACK\n",
3066 GNUNET_i2s(&n->id)); 3094 GNUNET_i2s (&n->id));
3067 disconnect_neighbour(n); 3095 disconnect_neighbour (n);
3068 return; 3096 return;
3069 } 3097 }
3070 break; 3098 break;
3071 3099
3072 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3100 case GNUNET_TRANSPORT_PS_CONNECTED:
3073 if (0 == delay.rel_value_us) 3101 if (0 == delay.rel_value_us)
3074 { 3102 {
3075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3076 "Switch failed, cleaning up alternative address\n"); 3104 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3077 free_address(&n->alternative_address); 3105 GNUNET_i2s (&n->id));
3078 set_state_and_timeout(n, 3106 disconnect_neighbour (n);
3079 GNUNET_TRANSPORT_PS_CONNECTED, 3107 return;
3080 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT)); 3108 }
3081 } 3109 try_transmission_to_peer (n);
3082 try_transmission_to_peer(n); 3110 send_keepalive (n);
3083 send_keepalive(n); 3111 break;
3084 break;
3085 3112
3086 case GNUNET_TRANSPORT_PS_DISCONNECT: 3113 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3087 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3114 if (0 == delay.rel_value_us)
3088 "Cleaning up connection to `%s' after sending DISCONNECT\n", 3115 {
3089 GNUNET_i2s(&n->id)); 3116 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3090 free_neighbour(n); 3117 "Connection to `%s' timed out, waiting for ATS replacement address\n",
3118 GNUNET_i2s (&n->id));
3119 disconnect_neighbour (n);
3091 return; 3120 return;
3121 }
3122 break;
3092 3123
3093 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3124 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3094 /* how did we get here!? */ 3125 if (0 == delay.rel_value_us)
3095 GNUNET_assert(0); 3126 {
3096 break; 3127 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3128 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n",
3129 GNUNET_i2s (&n->id));
3130 disconnect_neighbour (n);
3131 return;
3132 }
3133 break;
3097 3134
3098 default: 3135 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3099 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3136 if (0 == delay.rel_value_us)
3100 "Unhandled state `%s'\n", 3137 {
3101 GNUNET_TRANSPORT_ps2s(n->state)); 3138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3102 GNUNET_break(0); 3139 "Switch failed, cleaning up alternative address\n");
3103 break; 3140 free_address (&n->alternative_address);
3141 set_state_and_timeout (n,
3142 GNUNET_TRANSPORT_PS_CONNECTED,
3143 GNUNET_TIME_relative_to_absolute (
3144 SETUP_CONNECTION_TIMEOUT));
3104 } 3145 }
3105 delay = GNUNET_TIME_absolute_get_remaining(n->timeout); 3146 try_transmission_to_peer (n);
3147 send_keepalive (n);
3148 break;
3149
3150 case GNUNET_TRANSPORT_PS_DISCONNECT:
3151 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3152 "Cleaning up connection to `%s' after sending DISCONNECT\n",
3153 GNUNET_i2s (&n->id));
3154 free_neighbour (n);
3155 return;
3156
3157 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3158 /* how did we get here!? */
3159 GNUNET_assert (0);
3160 break;
3161
3162 default:
3163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3164 "Unhandled state `%s'\n",
3165 GNUNET_TRANSPORT_ps2s (n->state));
3166 GNUNET_break (0);
3167 break;
3168 }
3169 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
3106 if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || 3170 if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3107 (GNUNET_TRANSPORT_PS_CONNECTED == n->state)) 3171 (GNUNET_TRANSPORT_PS_CONNECTED == n->state))
3108 { 3172 {
3109 /* if we are *now* in one of the two states, we're sending 3173 /* if we are *now* in one of the two states, we're sending
3110 keep alive messages, so we need to consider the keepalive 3174 keep alive messages, so we need to consider the keepalive
3111 delay, not just the connection timeout */ 3175 delay, not just the connection timeout */
3112 delay = GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(n->keep_alive_time), 3176 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (
3113 delay); 3177 n->keep_alive_time),
3114 } 3178 delay);
3179 }
3115 if (NULL == n->task) 3180 if (NULL == n->task)
3116 n->task = GNUNET_SCHEDULER_add_delayed(delay, 3181 n->task = GNUNET_SCHEDULER_add_delayed (delay,
3117 &master_task, 3182 &master_task,
3118 n); 3183 n);
3119} 3184}
3120 3185
3121 3186
@@ -3126,23 +3191,23 @@ master_task(void *cls)
3126 * @param n neighbour to send the ACK to 3191 * @param n neighbour to send the ACK to
3127 */ 3192 */
3128static void 3193static void
3129send_session_ack_message(struct NeighbourMapEntry *n) 3194send_session_ack_message (struct NeighbourMapEntry *n)
3130{ 3195{
3131 struct GNUNET_MessageHeader msg; 3196 struct GNUNET_MessageHeader msg;
3132 3197
3133 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3198 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3134 "Sending ACK message to peer `%s'\n", 3199 "Sending ACK message to peer `%s'\n",
3135 GNUNET_i2s(&n->id)); 3200 GNUNET_i2s (&n->id));
3136 3201
3137 msg.size = htons(sizeof(struct GNUNET_MessageHeader)); 3202 msg.size = htons (sizeof(struct GNUNET_MessageHeader));
3138 msg.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 3203 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
3139 (void)send_with_session(n, 3204 (void) send_with_session (n,
3140 &msg, 3205 &msg,
3141 sizeof(struct GNUNET_MessageHeader), 3206 sizeof(struct GNUNET_MessageHeader),
3142 UINT32_MAX, 3207 UINT32_MAX,
3143 GNUNET_TIME_UNIT_FOREVER_REL, 3208 GNUNET_TIME_UNIT_FOREVER_REL,
3144 GNUNET_NO, 3209 GNUNET_NO,
3145 NULL, NULL); 3210 NULL, NULL);
3146} 3211}
3147 3212
3148 3213
@@ -3158,145 +3223,154 @@ send_session_ack_message(struct NeighbourMapEntry *n)
3158 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3223 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3159 */ 3224 */
3160int 3225int
3161GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message, 3226GST_neighbours_handle_session_syn_ack (const struct
3162 const struct GNUNET_HELLO_Address *address, 3227 GNUNET_MessageHeader *message,
3163 struct GNUNET_ATS_Session *session) 3228 const struct
3229 GNUNET_HELLO_Address *address,
3230 struct GNUNET_ATS_Session *session)
3164{ 3231{
3165 const struct TransportSynMessage *scm; 3232 const struct TransportSynMessage *scm;
3166 struct GNUNET_TIME_Absolute ts; 3233 struct GNUNET_TIME_Absolute ts;
3167 struct NeighbourMapEntry *n; 3234 struct NeighbourMapEntry *n;
3168 3235
3169 (void)session; 3236 (void) session;
3170 if (ntohs(message->size) != sizeof(struct TransportSynMessage)) 3237 if (ntohs (message->size) != sizeof(struct TransportSynMessage))
3171 { 3238 {
3172 GNUNET_break_op(0); 3239 GNUNET_break_op (0);
3173 return GNUNET_SYSERR; 3240 return GNUNET_SYSERR;
3174 } 3241 }
3175 GNUNET_STATISTICS_update(GST_stats, 3242 GNUNET_STATISTICS_update (GST_stats,
3176 gettext_noop 3243 gettext_noop
3177 ("# SYN_ACK messages received"), 3244 ("# SYN_ACK messages received"),
3178 1, GNUNET_NO); 3245 1, GNUNET_NO);
3179 scm = (const struct TransportSynMessage *)message; 3246 scm = (const struct TransportSynMessage *) message;
3180 GNUNET_break_op(ntohl(scm->reserved) == 0); 3247 GNUNET_break_op (ntohl (scm->reserved) == 0);
3181 if (NULL == (n = lookup_neighbour(&address->peer))) 3248 if (NULL == (n = lookup_neighbour (&address->peer)))
3182 { 3249 {
3183 GNUNET_STATISTICS_update(GST_stats, 3250 GNUNET_STATISTICS_update (GST_stats,
3184 gettext_noop 3251 gettext_noop
3185 ("# unexpected SYN_ACK messages (no peer)"), 3252 ("# unexpected SYN_ACK messages (no peer)"),
3186 1, GNUNET_NO); 3253 1, GNUNET_NO);
3187 return GNUNET_SYSERR; 3254 return GNUNET_SYSERR;
3188 } 3255 }
3189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3190 "Received SYN_ACK message from peer `%s' in state %s/%s\n", 3257 "Received SYN_ACK message from peer `%s' in state %s/%s\n",
3191 GNUNET_i2s(&address->peer), 3258 GNUNET_i2s (&address->peer),
3192 GNUNET_TRANSPORT_ps2s(n->state), 3259 GNUNET_TRANSPORT_ps2s (n->state),
3193 print_ack_state(n->ack_state)); 3260 print_ack_state (n->ack_state));
3194 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp); 3261 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
3195 switch (n->state) 3262 switch (n->state)
3196 { 3263 {
3197 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3264 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3198 GNUNET_break(0); 3265 GNUNET_break (0);
3199 free_neighbour(n); 3266 free_neighbour (n);
3200 return GNUNET_SYSERR; 3267 return GNUNET_SYSERR;
3201 3268
3202 case GNUNET_TRANSPORT_PS_INIT_ATS: 3269 case GNUNET_TRANSPORT_PS_INIT_ATS:
3203 GNUNET_STATISTICS_update(GST_stats, 3270 GNUNET_STATISTICS_update (GST_stats,
3204 gettext_noop("# unexpected SYN_ACK messages (not ready)"), 3271 gettext_noop (
3205 1, 3272 "# unexpected SYN_ACK messages (not ready)"),
3206 GNUNET_NO); 3273 1,
3207 break; 3274 GNUNET_NO);
3208 3275 break;
3209 case GNUNET_TRANSPORT_PS_SYN_SENT: 3276
3210 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) 3277 case GNUNET_TRANSPORT_PS_SYN_SENT:
3211 { 3278 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
3212 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3279 {
3213 "SYN_ACK ignored as the timestamp does not match our SYN request\n"); 3280 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3214 return GNUNET_OK; 3281 "SYN_ACK ignored as the timestamp does not match our SYN request\n");
3215 } 3282 return GNUNET_OK;
3216 set_state_and_timeout(n,
3217 GNUNET_TRANSPORT_PS_CONNECTED,
3218 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3219 set_primary_address(n,
3220 n->primary_address.address,
3221 n->primary_address.session,
3222 n->primary_address.bandwidth_in,
3223 n->primary_address.bandwidth_out);
3224 send_session_ack_message(n);
3225 break;
3226
3227 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3228 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3229 GNUNET_STATISTICS_update(GST_stats,
3230 gettext_noop("# unexpected SYN_ACK messages (not ready)"),
3231 1,
3232 GNUNET_NO);
3233 break;
3234
3235 case GNUNET_TRANSPORT_PS_CONNECTED:
3236 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3237 send_session_ack_message(n);
3238 break;
3239
3240 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3241 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3242 to give us a new address... */
3243 GNUNET_STATISTICS_update(GST_stats,
3244 gettext_noop("# unexpected SYN_ACK messages (waiting on ATS)"),
3245 1,
3246 GNUNET_NO);
3247 break;
3248
3249 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3250 /* Reconnecting with new address address worked; go back to connected! */
3251 set_state_and_timeout(n,
3252 GNUNET_TRANSPORT_PS_CONNECTED,
3253 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3254 send_session_ack_message(n);
3255 break;
3256
3257 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3258 /* new address worked; adopt it and go back to connected! */
3259 set_state_and_timeout(n,
3260 GNUNET_TRANSPORT_PS_CONNECTED,
3261 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3262 GNUNET_break(GNUNET_NO == n->alternative_address.ats_active);
3263
3264 /* Set primary addresses */
3265 set_primary_address(n,
3266 n->alternative_address.address,
3267 n->alternative_address.session,
3268 n->alternative_address.bandwidth_in,
3269 n->alternative_address.bandwidth_out);
3270 GNUNET_STATISTICS_update(GST_stats,
3271 gettext_noop("# Successful attempts to switch addresses"),
3272 1,
3273 GNUNET_NO);
3274
3275 GNUNET_HELLO_address_free(n->alternative_address.address);
3276 memset(&n->alternative_address,
3277 0,
3278 sizeof(n->alternative_address));
3279 send_session_ack_message(n);
3280 break;
3281
3282 case GNUNET_TRANSPORT_PS_DISCONNECT:
3283 GNUNET_STATISTICS_update(GST_stats,
3284 gettext_noop
3285 ("# unexpected SYN_ACK messages (disconnecting)"),
3286 1, GNUNET_NO);
3287 return GNUNET_SYSERR;
3288
3289 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3290 GNUNET_assert(0);
3291 break;
3292
3293 default:
3294 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3295 "Unhandled state `%s'\n",
3296 GNUNET_TRANSPORT_ps2s(n->state));
3297 GNUNET_break(0);
3298 return GNUNET_SYSERR;
3299 } 3283 }
3284 set_state_and_timeout (n,
3285 GNUNET_TRANSPORT_PS_CONNECTED,
3286 GNUNET_TIME_relative_to_absolute (
3287 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3288 set_primary_address (n,
3289 n->primary_address.address,
3290 n->primary_address.session,
3291 n->primary_address.bandwidth_in,
3292 n->primary_address.bandwidth_out);
3293 send_session_ack_message (n);
3294 break;
3295
3296 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3297 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3298 GNUNET_STATISTICS_update (GST_stats,
3299 gettext_noop (
3300 "# unexpected SYN_ACK messages (not ready)"),
3301 1,
3302 GNUNET_NO);
3303 break;
3304
3305 case GNUNET_TRANSPORT_PS_CONNECTED:
3306 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3307 send_session_ack_message (n);
3308 break;
3309
3310 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3311 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3312 to give us a new address... */
3313 GNUNET_STATISTICS_update (GST_stats,
3314 gettext_noop (
3315 "# unexpected SYN_ACK messages (waiting on ATS)"),
3316 1,
3317 GNUNET_NO);
3318 break;
3319
3320 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3321 /* Reconnecting with new address address worked; go back to connected! */
3322 set_state_and_timeout (n,
3323 GNUNET_TRANSPORT_PS_CONNECTED,
3324 GNUNET_TIME_relative_to_absolute (
3325 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3326 send_session_ack_message (n);
3327 break;
3328
3329 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3330 /* new address worked; adopt it and go back to connected! */
3331 set_state_and_timeout (n,
3332 GNUNET_TRANSPORT_PS_CONNECTED,
3333 GNUNET_TIME_relative_to_absolute (
3334 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3335 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
3336
3337 /* Set primary addresses */
3338 set_primary_address (n,
3339 n->alternative_address.address,
3340 n->alternative_address.session,
3341 n->alternative_address.bandwidth_in,
3342 n->alternative_address.bandwidth_out);
3343 GNUNET_STATISTICS_update (GST_stats,
3344 gettext_noop (
3345 "# Successful attempts to switch addresses"),
3346 1,
3347 GNUNET_NO);
3348
3349 GNUNET_HELLO_address_free (n->alternative_address.address);
3350 memset (&n->alternative_address,
3351 0,
3352 sizeof(n->alternative_address));
3353 send_session_ack_message (n);
3354 break;
3355
3356 case GNUNET_TRANSPORT_PS_DISCONNECT:
3357 GNUNET_STATISTICS_update (GST_stats,
3358 gettext_noop
3359 ("# unexpected SYN_ACK messages (disconnecting)"),
3360 1, GNUNET_NO);
3361 return GNUNET_SYSERR;
3362
3363 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3364 GNUNET_assert (0);
3365 break;
3366
3367 default:
3368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3369 "Unhandled state `%s'\n",
3370 GNUNET_TRANSPORT_ps2s (n->state));
3371 GNUNET_break (0);
3372 return GNUNET_SYSERR;
3373 }
3300 return GNUNET_OK; 3374 return GNUNET_OK;
3301} 3375}
3302 3376
@@ -3311,134 +3385,138 @@ GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message
3311 * this session was not in use 3385 * this session was not in use
3312 */ 3386 */
3313int 3387int
3314GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer, 3388GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3315 struct GNUNET_ATS_Session *session) 3389 struct GNUNET_ATS_Session *session)
3316{ 3390{
3317 struct NeighbourMapEntry *n; 3391 struct NeighbourMapEntry *n;
3318 3392
3319 if (NULL == (n = lookup_neighbour(peer))) 3393 if (NULL == (n = lookup_neighbour (peer)))
3320 return GNUNET_NO; /* can't affect us */ 3394 return GNUNET_NO; /* can't affect us */
3321 if (session != n->primary_address.session) 3395 if (session != n->primary_address.session)
3396 {
3397 /* Free alternative address */
3398 if (session == n->alternative_address.session)
3322 { 3399 {
3323 /* Free alternative address */ 3400 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3324 if (session == n->alternative_address.session) 3401 set_state_and_timeout (n,
3325 { 3402 GNUNET_TRANSPORT_PS_CONNECTED,
3326 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3403 n->timeout);
3327 set_state_and_timeout(n, 3404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3328 GNUNET_TRANSPORT_PS_CONNECTED, 3405 "Session died, cleaning up alternative address\n");
3329 n->timeout); 3406 free_address (&n->alternative_address);
3330 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3331 "Session died, cleaning up alternative address\n");
3332 free_address(&n->alternative_address);
3333 }
3334 return GNUNET_NO; /* doesn't affect us further */
3335 } 3407 }
3408 return GNUNET_NO; /* doesn't affect us further */
3409 }
3336 3410
3337 n->expect_latency_response = GNUNET_NO; 3411 n->expect_latency_response = GNUNET_NO;
3338 /* The session for neighbour's primary address died */ 3412 /* The session for neighbour's primary address died */
3339 switch (n->state) 3413 switch (n->state)
3340 { 3414 {
3341 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3415 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3342 GNUNET_break(0); 3416 GNUNET_break (0);
3343 free_neighbour(n); 3417 free_neighbour (n);
3344 return GNUNET_YES; 3418 return GNUNET_YES;
3345 3419
3346 case GNUNET_TRANSPORT_PS_INIT_ATS: 3420 case GNUNET_TRANSPORT_PS_INIT_ATS:
3347 GNUNET_break(0); 3421 GNUNET_break (0);
3348 free_neighbour(n); 3422 free_neighbour (n);
3349 return GNUNET_YES; 3423 return GNUNET_YES;
3350 3424
3351 case GNUNET_TRANSPORT_PS_SYN_SENT: 3425 case GNUNET_TRANSPORT_PS_SYN_SENT:
3352 /* The session used to send the SYN terminated: 3426 /* The session used to send the SYN terminated:
3353 * this implies a connect error*/ 3427 * this implies a connect error*/
3354 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3428 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3355 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n", 3429 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n",
3356 GST_plugins_a2s(n->primary_address.address), 3430 GST_plugins_a2s (n->primary_address.address),
3357 n->primary_address.session); 3431 n->primary_address.session);
3358 3432
3359 /* Destroy the address since it cannot be used */ 3433 /* Destroy the address since it cannot be used */
3360 unset_primary_address(n); 3434 unset_primary_address (n);
3361 set_state_and_timeout(n, 3435 set_state_and_timeout (n,
3362 GNUNET_TRANSPORT_PS_INIT_ATS, 3436 GNUNET_TRANSPORT_PS_INIT_ATS,
3363 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3437 GNUNET_TIME_relative_to_absolute (
3364 break; 3438 ATS_RESPONSE_TIMEOUT));
3365 3439 break;
3366 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 3440
3367 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3441 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3368 /* error on inbound session; free neighbour entirely */ 3442 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3369 free_neighbour(n); 3443 /* error on inbound session; free neighbour entirely */
3370 return GNUNET_YES; 3444 free_neighbour (n);
3371 3445 return GNUNET_YES;
3372 case GNUNET_TRANSPORT_PS_CONNECTED: 3446
3373 /* Our primary connection died, try a fast reconnect */ 3447 case GNUNET_TRANSPORT_PS_CONNECTED:
3374 unset_primary_address(n); 3448 /* Our primary connection died, try a fast reconnect */
3375 set_state_and_timeout(n, 3449 unset_primary_address (n);
3376 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3450 set_state_and_timeout (n,
3377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3451 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3378 break; 3452 GNUNET_TIME_relative_to_absolute (
3379 3453 ATS_RESPONSE_TIMEOUT));
3380 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3454 break;
3381 /* we don't have an address, how can it go down? */ 3455
3382 GNUNET_break(0); 3456 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3383 break; 3457 /* we don't have an address, how can it go down? */
3384 3458 GNUNET_break (0);
3385 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3459 break;
3386 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3460
3387 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n", 3461 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3388 GST_plugins_a2s(n->primary_address.address), 3462 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3389 n->primary_address.session); 3463 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n",
3390 /* Destroy the address since it cannot be used */ 3464 GST_plugins_a2s (n->primary_address.address),
3391 unset_primary_address(n); 3465 n->primary_address.session);
3392 set_state_and_timeout(n, 3466 /* Destroy the address since it cannot be used */
3393 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3467 unset_primary_address (n);
3394 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT)); 3468 set_state_and_timeout (n,
3395 break; 3469 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3396 3470 GNUNET_TIME_relative_to_absolute (
3397 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3471 ATS_RESPONSE_TIMEOUT));
3398 /* primary went down while we were waiting for SYN_ACK on secondary; 3472 break;
3399 secondary as primary */ 3473
3400 3474 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3475 /* primary went down while we were waiting for SYN_ACK on secondary;
3402 "Connection `%s' %p to peer `%s' was terminated while switching, " 3476 secondary as primary */
3403 "switching to alternative address `%s' %p\n", 3477
3404 GST_plugins_a2s(n->primary_address.address), 3478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3405 n->primary_address.session, 3479 "Connection `%s' %p to peer `%s' was terminated while switching, "
3406 GNUNET_i2s(peer), 3480 "switching to alternative address `%s' %p\n",
3407 GST_plugins_a2s(n->alternative_address.address), 3481 GST_plugins_a2s (n->primary_address.address),
3408 n->alternative_address.session); 3482 n->primary_address.session,
3409 3483 GNUNET_i2s (peer),
3410 /* Destroy the inbound address since it cannot be used */ 3484 GST_plugins_a2s (n->alternative_address.address),
3411 free_address(&n->primary_address); 3485 n->alternative_address.session);
3412 n->primary_address = n->alternative_address; 3486
3413 GNUNET_assert(GNUNET_YES == 3487 /* Destroy the inbound address since it cannot be used */
3414 GST_ats_is_known(n->primary_address.address, 3488 free_address (&n->primary_address);
3489 n->primary_address = n->alternative_address;
3490 GNUNET_assert (GNUNET_YES ==
3491 GST_ats_is_known (n->primary_address.address,
3415 n->primary_address.session)); 3492 n->primary_address.session));
3416 memset(&n->alternative_address, 3493 memset (&n->alternative_address,
3417 0, 3494 0,
3418 sizeof(struct NeighbourAddress)); 3495 sizeof(struct NeighbourAddress));
3419 set_state_and_timeout(n, 3496 set_state_and_timeout (n,
3420 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 3497 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
3421 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT)); 3498 GNUNET_TIME_relative_to_absolute (
3422 break; 3499 FAST_RECONNECT_TIMEOUT));
3423 3500 break;
3424 case GNUNET_TRANSPORT_PS_DISCONNECT: 3501
3425 unset_primary_address(n); 3502 case GNUNET_TRANSPORT_PS_DISCONNECT:
3426 break; 3503 unset_primary_address (n);
3427 3504 break;
3428 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3505
3429 /* neighbour was freed and plugins told to terminate session */ 3506 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3430 return GNUNET_NO; 3507 /* neighbour was freed and plugins told to terminate session */
3508 return GNUNET_NO;
3431 3509
3432 default: 3510 default:
3433 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3511 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3434 "Unhandled state `%s'\n", 3512 "Unhandled state `%s'\n",
3435 GNUNET_TRANSPORT_ps2s(n->state)); 3513 GNUNET_TRANSPORT_ps2s (n->state));
3436 GNUNET_break(0); 3514 GNUNET_break (0);
3437 break; 3515 break;
3438 } 3516 }
3439 if (NULL != n->task) 3517 if (NULL != n->task)
3440 GNUNET_SCHEDULER_cancel(n->task); 3518 GNUNET_SCHEDULER_cancel (n->task);
3441 n->task = GNUNET_SCHEDULER_add_now(&master_task, n); 3519 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
3442 return GNUNET_YES; 3520 return GNUNET_YES;
3443} 3521}
3444 3522
@@ -3454,32 +3532,32 @@ GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer,
3454 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3532 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3455 */ 3533 */
3456int 3534int
3457GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message, 3535GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3458 const struct GNUNET_HELLO_Address *address, 3536 const struct GNUNET_HELLO_Address *address,
3459 struct GNUNET_ATS_Session *session) 3537 struct GNUNET_ATS_Session *session)
3460{ 3538{
3461 struct NeighbourMapEntry *n; 3539 struct NeighbourMapEntry *n;
3462 3540
3463 (void)session; 3541 (void) session;
3464 if (ntohs(message->size) != sizeof(struct GNUNET_MessageHeader)) 3542 if (ntohs (message->size) != sizeof(struct GNUNET_MessageHeader))
3465 { 3543 {
3466 GNUNET_break_op(0); 3544 GNUNET_break_op (0);
3467 return GNUNET_SYSERR; 3545 return GNUNET_SYSERR;
3468 } 3546 }
3469 GNUNET_STATISTICS_update(GST_stats, 3547 GNUNET_STATISTICS_update (GST_stats,
3470 gettext_noop("# ACK messages received"), 3548 gettext_noop ("# ACK messages received"),
3471 1, 3549 1,
3472 GNUNET_NO); 3550 GNUNET_NO);
3473 if (NULL == (n = lookup_neighbour(&address->peer))) 3551 if (NULL == (n = lookup_neighbour (&address->peer)))
3474 { 3552 {
3475 GNUNET_break_op(0); 3553 GNUNET_break_op (0);
3476 return GNUNET_SYSERR; 3554 return GNUNET_SYSERR;
3477 } 3555 }
3478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3479 "Received ACK for peer `%s' in state %s/%s\n", 3557 "Received ACK for peer `%s' in state %s/%s\n",
3480 GNUNET_i2s(&address->peer), 3558 GNUNET_i2s (&address->peer),
3481 GNUNET_TRANSPORT_ps2s(n->state), 3559 GNUNET_TRANSPORT_ps2s (n->state),
3482 print_ack_state(n->ack_state)); 3560 print_ack_state (n->ack_state));
3483 3561
3484 /* Check if we are in a plausible state for having sent 3562 /* Check if we are in a plausible state for having sent
3485 a SYN_ACK. If not, return, otherwise break. 3563 a SYN_ACK. If not, return, otherwise break.
@@ -3495,46 +3573,47 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
3495 if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && 3573 if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) &&
3496 (ACK_SEND_ACK != n->ack_state)) || 3574 (ACK_SEND_ACK != n->ack_state)) ||
3497 (NULL == n->primary_address.address)) 3575 (NULL == n->primary_address.address))
3498 { 3576 {
3499 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3577 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3500 "Received unexpected ACK message from peer `%s' in state %s/%s\n", 3578 "Received unexpected ACK message from peer `%s' in state %s/%s\n",
3501 GNUNET_i2s(&address->peer), 3579 GNUNET_i2s (&address->peer),
3502 GNUNET_TRANSPORT_ps2s(n->state), 3580 GNUNET_TRANSPORT_ps2s (n->state),
3503 print_ack_state(n->ack_state)); 3581 print_ack_state (n->ack_state));
3504 3582
3505 GNUNET_STATISTICS_update(GST_stats, 3583 GNUNET_STATISTICS_update (GST_stats,
3506 gettext_noop("# unexpected ACK messages"), 3584 gettext_noop ("# unexpected ACK messages"),
3507 1, 3585 1,
3508 GNUNET_NO); 3586 GNUNET_NO);
3509 return GNUNET_OK; 3587 return GNUNET_OK;
3510 } 3588 }
3511 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3589 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3512 { 3590 {
3513 /* We tried to switch addresses while being connect. We explicitly wait 3591 /* We tried to switch addresses while being connect. We explicitly wait
3514 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED, 3592 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED,
3515 * so we do not want to set the address as in use! */ 3593 * so we do not want to set the address as in use! */
3516 return GNUNET_OK; 3594 return GNUNET_OK;
3517 } 3595 }
3518 set_state_and_timeout(n, 3596 set_state_and_timeout (n,
3519 GNUNET_TRANSPORT_PS_CONNECTED, 3597 GNUNET_TRANSPORT_PS_CONNECTED,
3520 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3598 GNUNET_TIME_relative_to_absolute (
3599 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3521 3600
3522 if (NULL == n->primary_address.address) 3601 if (NULL == n->primary_address.address)
3523 { 3602 {
3524 /* See issue #3693. 3603 /* See issue #3693.
3525 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which 3604 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which
3526 * really means we did try (and succeed) to send a SYN and are waiting for 3605 * really means we did try (and succeed) to send a SYN and are waiting for
3527 * an ACK. 3606 * an ACK.
3528 * That suggests that the primary_address used to be non-NULL, but maybe it 3607 * That suggests that the primary_address used to be non-NULL, but maybe it
3529 * got reset to NULL without the state being changed appropriately? 3608 * got reset to NULL without the state being changed appropriately?
3530 */ 3609 */
3531 GNUNET_break(0); 3610 GNUNET_break (0);
3532 return GNUNET_OK; 3611 return GNUNET_OK;
3533 } 3612 }
3534 3613
3535 /* Reset backoff for primary address */ 3614 /* Reset backoff for primary address */
3536 GST_ats_block_reset(n->primary_address.address, 3615 GST_ats_block_reset (n->primary_address.address,
3537 n->primary_address.session); 3616 n->primary_address.session);
3538 return GNUNET_OK; 3617 return GNUNET_OK;
3539} 3618}
3540 3619
@@ -3546,9 +3625,9 @@ GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
3546 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 3625 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
3547 */ 3626 */
3548int 3627int
3549GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target) 3628GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
3550{ 3629{
3551 return test_connected(lookup_neighbour(target)); 3630 return test_connected (lookup_neighbour (target));
3552} 3631}
3553 3632
3554 3633
@@ -3558,15 +3637,15 @@ GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target)
3558 * @param cls the `struct NeighbourMapEntry` to free 3637 * @param cls the `struct NeighbourMapEntry` to free
3559 */ 3638 */
3560static void 3639static void
3561delayed_disconnect(void *cls) 3640delayed_disconnect (void *cls)
3562{ 3641{
3563 struct NeighbourMapEntry *n = cls; 3642 struct NeighbourMapEntry *n = cls;
3564 3643
3565 n->delayed_disconnect_task = NULL; 3644 n->delayed_disconnect_task = NULL;
3566 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3645 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3567 "Disconnecting by request from peer %s\n", 3646 "Disconnecting by request from peer %s\n",
3568 GNUNET_i2s(&n->id)); 3647 GNUNET_i2s (&n->id));
3569 free_neighbour(n); 3648 free_neighbour (n);
3570} 3649}
3571 3650
3572 3651
@@ -3578,42 +3657,44 @@ delayed_disconnect(void *cls)
3578 * @param msg the quota message 3657 * @param msg the quota message
3579 */ 3658 */
3580void 3659void
3581GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer, 3660GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
3582 const struct GNUNET_MessageHeader *msg) 3661 const struct GNUNET_MessageHeader *msg)
3583{ 3662{
3584 struct NeighbourMapEntry *n; 3663 struct NeighbourMapEntry *n;
3585 const struct GNUNET_ATS_SessionQuotaMessage *sqm; 3664 const struct GNUNET_ATS_SessionQuotaMessage *sqm;
3586 struct GNUNET_BANDWIDTH_Value32NBO last; 3665 struct GNUNET_BANDWIDTH_Value32NBO last;
3587 3666
3588 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3589 "Received QUOTA message from peer `%s'\n", 3668 "Received QUOTA message from peer `%s'\n",
3590 GNUNET_i2s(peer)); 3669 GNUNET_i2s (peer));
3591 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage)) 3670 if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage))
3592 { 3671 {
3593 GNUNET_break_op(0); 3672 GNUNET_break_op (0);
3594 GNUNET_STATISTICS_update(GST_stats, 3673 GNUNET_STATISTICS_update (GST_stats,
3595 gettext_noop("# quota messages ignored (malformed)"), 3674 gettext_noop (
3596 1, 3675 "# quota messages ignored (malformed)"),
3597 GNUNET_NO); 3676 1,
3598 return; 3677 GNUNET_NO);
3599 } 3678 return;
3600 GNUNET_STATISTICS_update(GST_stats, 3679 }
3601 gettext_noop 3680 GNUNET_STATISTICS_update (GST_stats,
3602 ("# QUOTA messages received"), 3681 gettext_noop
3603 1, GNUNET_NO); 3682 ("# QUOTA messages received"),
3604 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *)msg; 3683 1, GNUNET_NO);
3605 if (NULL == (n = lookup_neighbour(peer))) 3684 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *) msg;
3606 { 3685 if (NULL == (n = lookup_neighbour (peer)))
3607 /* gone already */ 3686 {
3608 return; 3687 /* gone already */
3609 } 3688 return;
3610 last = GNUNET_BANDWIDTH_value_max(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 3689 }
3611 GNUNET_BANDWIDTH_value_init(ntohl(sqm->quota))); 3690 last = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
3691 GNUNET_BANDWIDTH_value_init (ntohl (
3692 sqm->quota)));
3612 if (last.value__ != n->neighbour_receive_quota.value__) 3693 if (last.value__ != n->neighbour_receive_quota.value__)
3613 { 3694 {
3614 n->neighbour_receive_quota = last; 3695 n->neighbour_receive_quota = last;
3615 send_outbound_quota_to_clients(n); 3696 send_outbound_quota_to_clients (n);
3616 } 3697 }
3617} 3698}
3618 3699
3619 3700
@@ -3625,85 +3706,91 @@ GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer,
3625 * @param msg the disconnect message 3706 * @param msg the disconnect message
3626 */ 3707 */
3627void 3708void
3628GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer, 3709GST_neighbours_handle_disconnect_message (const struct
3629 const struct GNUNET_MessageHeader *msg) 3710 GNUNET_PeerIdentity *peer,
3711 const struct
3712 GNUNET_MessageHeader *msg)
3630{ 3713{
3631 struct NeighbourMapEntry *n; 3714 struct NeighbourMapEntry *n;
3632 const struct GNUNET_ATS_SessionDisconnectMessage *sdm; 3715 const struct GNUNET_ATS_SessionDisconnectMessage *sdm;
3633 3716
3634 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3635 "Received DISCONNECT message from peer `%s'\n", 3718 "Received DISCONNECT message from peer `%s'\n",
3636 GNUNET_i2s(peer)); 3719 GNUNET_i2s (peer));
3637 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage)) 3720 if (ntohs (msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage))
3638 { 3721 {
3639 GNUNET_break_op(0); 3722 GNUNET_break_op (0);
3640 GNUNET_STATISTICS_update(GST_stats, 3723 GNUNET_STATISTICS_update (GST_stats,
3641 gettext_noop 3724 gettext_noop
3642 ("# disconnect messages ignored (malformed)"), 3725 ("# disconnect messages ignored (malformed)"),
3643 1, 3726 1,
3644 GNUNET_NO); 3727 GNUNET_NO);
3645 return; 3728 return;
3646 } 3729 }
3647 GNUNET_STATISTICS_update(GST_stats, 3730 GNUNET_STATISTICS_update (GST_stats,
3648 gettext_noop 3731 gettext_noop
3649 ("# DISCONNECT messages received"), 3732 ("# DISCONNECT messages received"),
3650 1, GNUNET_NO); 3733 1, GNUNET_NO);
3651 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *)msg; 3734 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *) msg;
3652 if (NULL == (n = lookup_neighbour(peer))) 3735 if (NULL == (n = lookup_neighbour (peer)))
3653 { 3736 {
3654 /* gone already */ 3737 /* gone already */
3655 return; 3738 return;
3656 } 3739 }
3657 if (GNUNET_TIME_absolute_ntoh(sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us) 3740 if (GNUNET_TIME_absolute_ntoh (sdm->timestamp).abs_value_us <=
3658 { 3741 n->connect_ack_timestamp.abs_value_us)
3659 GNUNET_STATISTICS_update(GST_stats, 3742 {
3660 gettext_noop("# disconnect messages ignored (timestamp)"), 3743 GNUNET_STATISTICS_update (GST_stats,
3661 1, 3744 gettext_noop (
3662 GNUNET_NO); 3745 "# disconnect messages ignored (timestamp)"),
3663 return; 3746 1,
3664 } 3747 GNUNET_NO);
3665 if (0 != memcmp(peer, 3748 return;
3666 &sdm->public_key, 3749 }
3667 sizeof(struct GNUNET_PeerIdentity))) 3750 if (0 != memcmp (peer,
3668 { 3751 &sdm->public_key,
3669 GNUNET_break_op(0); 3752 sizeof(struct GNUNET_PeerIdentity)))
3670 return; 3753 {
3671 } 3754 GNUNET_break_op (0);
3672 if (ntohl(sdm->purpose.size) != 3755 return;
3673 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 3756 }
3674 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) + 3757 if (ntohl (sdm->purpose.size) !=
3675 sizeof(struct GNUNET_TIME_AbsoluteNBO)) 3758 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
3676 { 3759 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
3677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3760 + sizeof(struct GNUNET_TIME_AbsoluteNBO))
3678 "DISCONNECT message from peer `%s' has invalid size\n", 3761 {
3679 GNUNET_i2s(peer)); 3762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3680 GNUNET_break_op(0); 3763 "DISCONNECT message from peer `%s' has invalid size\n",
3681 return; 3764 GNUNET_i2s (peer));
3682 } 3765 GNUNET_break_op (0);
3766 return;
3767 }
3683 if (GNUNET_OK != 3768 if (GNUNET_OK !=
3684 GNUNET_CRYPTO_eddsa_verify(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, 3769 GNUNET_CRYPTO_eddsa_verify (
3685 &sdm->purpose, 3770 GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT,
3686 &sdm->signature, 3771 &sdm->purpose,
3687 &sdm->public_key)) 3772 &sdm->signature,
3688 { 3773 &sdm->public_key))
3689 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3774 {
3690 "DISCONNECT message from peer `%s' cannot be verified \n", 3775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3691 GNUNET_i2s(peer)); 3776 "DISCONNECT message from peer `%s' cannot be verified \n",
3692 GNUNET_break_op(0); 3777 GNUNET_i2s (peer));
3693 return; 3778 GNUNET_break_op (0);
3694 } 3779 return;
3780 }
3695 if (NULL == n->delayed_disconnect_task) 3781 if (NULL == n->delayed_disconnect_task)
3696 { 3782 {
3697 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now(&delayed_disconnect, 3783 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect,
3698 n); 3784 n);
3699 } 3785 }
3700} 3786}
3701 3787
3702 3788
3703/** 3789/**
3704 * Closure for the #neighbours_iterate() function. 3790 * Closure for the #neighbours_iterate() function.
3705 */ 3791 */
3706struct IteratorContext { 3792struct IteratorContext
3793{
3707 /** 3794 /**
3708 * Function to call on each connected neighbour. 3795 * Function to call on each connected neighbour.
3709 */ 3796 */
@@ -3725,32 +3812,32 @@ struct IteratorContext {
3725 * @return #GNUNET_OK (continue to iterate) 3812 * @return #GNUNET_OK (continue to iterate)
3726 */ 3813 */
3727static int 3814static int
3728neighbours_iterate(void *cls, 3815neighbours_iterate (void *cls,
3729 const struct GNUNET_PeerIdentity *key, 3816 const struct GNUNET_PeerIdentity *key,
3730 void *value) 3817 void *value)
3731{ 3818{
3732 struct IteratorContext *ic = cls; 3819 struct IteratorContext *ic = cls;
3733 struct NeighbourMapEntry *n = value; 3820 struct NeighbourMapEntry *n = value;
3734 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 3821 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3735 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 3822 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3736 3823
3737 (void)key; 3824 (void) key;
3738 if (NULL != n->primary_address.address) 3825 if (NULL != n->primary_address.address)
3739 { 3826 {
3740 bandwidth_in = n->primary_address.bandwidth_in; 3827 bandwidth_in = n->primary_address.bandwidth_in;
3741 bandwidth_out = n->primary_address.bandwidth_out; 3828 bandwidth_out = n->primary_address.bandwidth_out;
3742 } 3829 }
3743 else 3830 else
3744 { 3831 {
3745 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3832 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3746 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3833 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3747 } 3834 }
3748 ic->cb(ic->cb_cls, 3835 ic->cb (ic->cb_cls,
3749 &n->id, 3836 &n->id,
3750 n->primary_address.address, 3837 n->primary_address.address,
3751 n->state, 3838 n->state,
3752 n->timeout, 3839 n->timeout,
3753 bandwidth_in, bandwidth_out); 3840 bandwidth_in, bandwidth_out);
3754 return GNUNET_OK; 3841 return GNUNET_OK;
3755} 3842}
3756 3843
@@ -3762,8 +3849,8 @@ neighbours_iterate(void *cls,
3762 * @param cb_cls closure for @a cb 3849 * @param cb_cls closure for @a cb
3763 */ 3850 */
3764void 3851void
3765GST_neighbours_iterate(GST_NeighbourIterator cb, 3852GST_neighbours_iterate (GST_NeighbourIterator cb,
3766 void *cb_cls) 3853 void *cb_cls)
3767{ 3854{
3768 struct IteratorContext ic; 3855 struct IteratorContext ic;
3769 3856
@@ -3771,9 +3858,9 @@ GST_neighbours_iterate(GST_NeighbourIterator cb,
3771 return; /* can happen during shutdown */ 3858 return; /* can happen during shutdown */
3772 ic.cb = cb; 3859 ic.cb = cb;
3773 ic.cb_cls = cb_cls; 3860 ic.cb_cls = cb_cls;
3774 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 3861 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3775 &neighbours_iterate, 3862 &neighbours_iterate,
3776 &ic); 3863 &ic);
3777} 3864}
3778 3865
3779 3866
@@ -3783,21 +3870,22 @@ GST_neighbours_iterate(GST_NeighbourIterator cb,
3783 * @param target peer to disconnect from 3870 * @param target peer to disconnect from
3784 */ 3871 */
3785void 3872void
3786GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target) 3873GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
3787{ 3874{
3788 struct NeighbourMapEntry *n; 3875 struct NeighbourMapEntry *n;
3789 3876
3790 if (NULL == (n = lookup_neighbour(target))) 3877 if (NULL == (n = lookup_neighbour (target)))
3791 return; /* not active */ 3878 return; /* not active */
3792 if (GNUNET_YES == test_connected(n)) 3879 if (GNUNET_YES == test_connected (n))
3793 GNUNET_STATISTICS_update(GST_stats, 3880 GNUNET_STATISTICS_update (GST_stats,
3794 gettext_noop("# disconnected from peer upon explicit request"), 3881 gettext_noop (
3795 1, 3882 "# disconnected from peer upon explicit request"),
3796 GNUNET_NO); 3883 1,
3797 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3884 GNUNET_NO);
3798 "Forced disconnect from peer %s\n", 3885 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3799 GNUNET_i2s(target)); 3886 "Forced disconnect from peer %s\n",
3800 disconnect_neighbour(n); 3887 GNUNET_i2s (target));
3888 disconnect_neighbour (n);
3801} 3889}
3802 3890
3803 3891
@@ -3808,11 +3896,11 @@ GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target)
3808 * @return address currently used 3896 * @return address currently used
3809 */ 3897 */
3810const struct GNUNET_HELLO_Address * 3898const struct GNUNET_HELLO_Address *
3811GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer) 3899GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
3812{ 3900{
3813 struct NeighbourMapEntry *n; 3901 struct NeighbourMapEntry *n;
3814 3902
3815 n = lookup_neighbour(peer); 3903 n = lookup_neighbour (peer);
3816 if (NULL == n) 3904 if (NULL == n)
3817 return NULL; 3905 return NULL;
3818 return n->primary_address.address; 3906 return n->primary_address.address;
@@ -3825,14 +3913,15 @@ GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer)
3825 * @param max_fds maximum number of fds to use 3913 * @param max_fds maximum number of fds to use
3826 */ 3914 */
3827void 3915void
3828GST_neighbours_start(unsigned int max_fds) 3916GST_neighbours_start (unsigned int max_fds)
3829{ 3917{
3830 (void)max_fds; 3918 (void) max_fds;
3831 neighbours = GNUNET_CONTAINER_multipeermap_create(NEIGHBOUR_TABLE_SIZE, 3919 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE,
3832 GNUNET_NO); 3920 GNUNET_NO);
3833 util_transmission_tk = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL, 3921 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (
3834 &utilization_transmission, 3922 UTIL_TRANSMISSION_INTERVAL,
3835 NULL); 3923 &utilization_transmission,
3924 NULL);
3836} 3925}
3837 3926
3838 3927
@@ -3845,18 +3934,18 @@ GST_neighbours_start(unsigned int max_fds)
3845 * @return #GNUNET_OK (continue to iterate) 3934 * @return #GNUNET_OK (continue to iterate)
3846 */ 3935 */
3847static int 3936static int
3848disconnect_all_neighbours(void *cls, 3937disconnect_all_neighbours (void *cls,
3849 const struct GNUNET_PeerIdentity *key, 3938 const struct GNUNET_PeerIdentity *key,
3850 void *value) 3939 void *value)
3851{ 3940{
3852 struct NeighbourMapEntry *n = value; 3941 struct NeighbourMapEntry *n = value;
3853 3942
3854 (void)cls; 3943 (void) cls;
3855 (void)key; 3944 (void) key;
3856 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3857 "Disconnecting peer `%4s' during shutdown\n", 3946 "Disconnecting peer `%4s' during shutdown\n",
3858 GNUNET_i2s(&n->id)); 3947 GNUNET_i2s (&n->id));
3859 free_neighbour(n); 3948 free_neighbour (n);
3860 return GNUNET_OK; 3949 return GNUNET_OK;
3861} 3950}
3862 3951
@@ -3865,19 +3954,19 @@ disconnect_all_neighbours(void *cls,
3865 * Cleanup the neighbours subsystem. 3954 * Cleanup the neighbours subsystem.
3866 */ 3955 */
3867void 3956void
3868GST_neighbours_stop() 3957GST_neighbours_stop ()
3869{ 3958{
3870 if (NULL == neighbours) 3959 if (NULL == neighbours)
3871 return; 3960 return;
3872 if (NULL != util_transmission_tk) 3961 if (NULL != util_transmission_tk)
3873 { 3962 {
3874 GNUNET_SCHEDULER_cancel(util_transmission_tk); 3963 GNUNET_SCHEDULER_cancel (util_transmission_tk);
3875 util_transmission_tk = NULL; 3964 util_transmission_tk = NULL;
3876 } 3965 }
3877 GNUNET_CONTAINER_multipeermap_iterate(neighbours, 3966 GNUNET_CONTAINER_multipeermap_iterate (neighbours,
3878 &disconnect_all_neighbours, 3967 &disconnect_all_neighbours,
3879 NULL); 3968 NULL);
3880 GNUNET_CONTAINER_multipeermap_destroy(neighbours); 3969 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
3881 neighbours = NULL; 3970 neighbours = NULL;
3882} 3971}
3883 3972