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