aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-17 19:34:43 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-17 19:34:43 +0000
commitfc91cb864ded72b193682d15667cc0ccfa8afc81 (patch)
treec64787eafbd36ff0bf0080176e95e2c48ad6b7fb /src/transport/gnunet-service-transport_neighbours.c
parentfc1ffe11b0c5949509067d3a126a56800e2b9ef8 (diff)
downloadgnunet-fc91cb864ded72b193682d15667cc0ccfa8afc81.tar.gz
gnunet-fc91cb864ded72b193682d15667cc0ccfa8afc81.zip
-be harsher about transport service sending messages out of line, also at the same time check in transport service to only transmit messages if in the right state
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c109
1 files changed, 44 insertions, 65 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 7b8a9a327..ad2947418 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -559,28 +559,32 @@ print_ack_state (enum GST_ACK_State s)
559/** 559/**
560 * Notify our clients that another peer connected to us. 560 * Notify our clients that another peer connected to us.
561 * 561 *
562 * @param peer the peer that connected 562 * @param n the peer that connected
563 * @param bandwidth_in inbound bandwidth in NBO
564 * @param bandwidth_out outbound bandwidth in NBO
565 */ 563 */
566static void 564static void
567neighbours_connect_notification (const struct GNUNET_PeerIdentity *peer, 565neighbours_connect_notification (struct NeighbourMapEntry *n)
568 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
569 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
570{ 566{
571 size_t len = sizeof(struct ConnectInfoMessage); 567 size_t len = sizeof(struct ConnectInfoMessage);
572 char buf[len] GNUNET_ALIGN; 568 char buf[len] GNUNET_ALIGN;
573 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; 569 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
570 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
574 571
572#if IGNORE_INBOUND_QUOTA
573 bandwidth_min = n->primary_address.bandwidth_out;
574#else
575 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
576 n->neighbour_receive_quota);
577#endif
575 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 578 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
576 "We are now connected to peer `%s'\n", 579 "We are now connected to peer `%s'\n",
577 GNUNET_i2s (peer)); 580 GNUNET_i2s (&n->id));
578 connect_msg->header.size = htons (sizeof(buf)); 581 connect_msg->header.size = htons (sizeof(buf));
579 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 582 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
580 connect_msg->id = *peer; 583 connect_msg->id = n->id;
581 connect_msg->quota_in = bandwidth_in; 584 connect_msg->quota_in = n->primary_address.bandwidth_in;
582 connect_msg->quota_out = bandwidth_out; 585 connect_msg->quota_out = bandwidth_min;
583 GST_clients_broadcast (&connect_msg->header, GNUNET_NO); 586 GST_clients_broadcast (&connect_msg->header,
587 GNUNET_NO);
584} 588}
585 589
586 590
@@ -588,21 +592,21 @@ neighbours_connect_notification (const struct GNUNET_PeerIdentity *peer,
588 * Notify our clients (and manipulation) that a peer disconnected from 592 * Notify our clients (and manipulation) that a peer disconnected from
589 * us. 593 * us.
590 * 594 *
591 * @param peer the peer that disconnected 595 * @param n the peer that disconnected
592 */ 596 */
593static void 597static void
594neighbours_disconnect_notification (const struct GNUNET_PeerIdentity *peer) 598neighbours_disconnect_notification (struct NeighbourMapEntry *n)
595{ 599{
596 struct DisconnectInfoMessage disconnect_msg; 600 struct DisconnectInfoMessage disconnect_msg;
597 601
598 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 602 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
599 "Peer `%s' disconnected\n", 603 "Peer `%s' disconnected\n",
600 GNUNET_i2s (peer)); 604 GNUNET_i2s (&n->id));
601 GST_manipulation_peer_disconnect (peer); 605 GST_manipulation_peer_disconnect (&n->id);
602 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage)); 606 disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage));
603 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 607 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
604 disconnect_msg.reserved = htonl (0); 608 disconnect_msg.reserved = htonl (0);
605 disconnect_msg.peer = *peer; 609 disconnect_msg.peer = n->id;
606 GST_clients_broadcast (&disconnect_msg.header, 610 GST_clients_broadcast (&disconnect_msg.header,
607 GNUNET_NO); 611 GNUNET_NO);
608} 612}
@@ -676,23 +680,31 @@ test_connected (struct NeighbourMapEntry *n)
676 * Note that the outbound quota is enforced client-side (i.e. 680 * Note that the outbound quota is enforced client-side (i.e.
677 * in libgnunettransport). 681 * in libgnunettransport).
678 * 682 *
679 * @param target affected peer 683 * @param n affected peer
680 * @param quota new quota
681 */ 684 */
682static void 685static void
683send_outbound_quota_to_clients (const struct GNUNET_PeerIdentity *target, 686send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
684 struct GNUNET_BANDWIDTH_Value32NBO quota)
685{ 687{
686 struct QuotaSetMessage q_msg; 688 struct QuotaSetMessage q_msg;
689 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
690
691 if (! GNUNET_TRANSPORT_is_connected (n->state))
692 return;
693#if IGNORE_INBOUND_QUOTA
694 bandwidth_min = n->primary_address.bandwidth_out;
695#else
696 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
697 n->neighbour_receive_quota);
698#endif
687 699
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
689 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 701 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
690 ntohl (quota.value__), 702 ntohl (bandwidth_min.value__),
691 GNUNET_i2s (target)); 703 GNUNET_i2s (&n->id));
692 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 704 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
693 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 705 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
694 q_msg.quota = quota; 706 q_msg.quota = bandwidth_min;
695 q_msg.peer = (*target); 707 q_msg.peer = n->id;
696 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 708 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
697} 709}
698 710
@@ -753,9 +765,7 @@ set_state_and_timeout (struct NeighbourMapEntry *n,
753 if (GNUNET_TRANSPORT_is_connected (s) && 765 if (GNUNET_TRANSPORT_is_connected (s) &&
754 ! GNUNET_TRANSPORT_is_connected (n->state) ) 766 ! GNUNET_TRANSPORT_is_connected (n->state) )
755 { 767 {
756 neighbours_connect_notification (&n->id, 768 neighbours_connect_notification (n);
757 n->primary_address.bandwidth_in,
758 n->primary_address.bandwidth_out);
759 GNUNET_STATISTICS_set (GST_stats, 769 GNUNET_STATISTICS_set (GST_stats,
760 gettext_noop ("# peers connected"), 770 gettext_noop ("# peers connected"),
761 ++neighbours_connected, 771 ++neighbours_connected,
@@ -768,7 +778,7 @@ set_state_and_timeout (struct NeighbourMapEntry *n,
768 gettext_noop ("# peers connected"), 778 gettext_noop ("# peers connected"),
769 --neighbours_connected, 779 --neighbours_connected,
770 GNUNET_NO); 780 GNUNET_NO);
771 neighbours_disconnect_notification (&n->id); 781 neighbours_disconnect_notification (n);
772 } 782 }
773 n->state = s; 783 n->state = s;
774 if ( (timeout.abs_value_us < n->timeout.abs_value_us) && 784 if ( (timeout.abs_value_us < n->timeout.abs_value_us) &&
@@ -1229,8 +1239,6 @@ set_primary_address (struct NeighbourMapEntry *n,
1229 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1239 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1230 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1240 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1231{ 1241{
1232 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
1233
1234 if (session == n->primary_address.session) 1242 if (session == n->primary_address.session)
1235 { 1243 {
1236 GST_validation_set_address_use (n->primary_address.address, 1244 GST_validation_set_address_use (n->primary_address.address,
@@ -1244,14 +1252,7 @@ set_primary_address (struct NeighbourMapEntry *n,
1244 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 1252 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1245 { 1253 {
1246 n->primary_address.bandwidth_out = bandwidth_out; 1254 n->primary_address.bandwidth_out = bandwidth_out;
1247#if IGNORE_INBOUND_QUOTA 1255 send_outbound_quota_to_clients (n);
1248 bandwidth_min = bandwidth_out;
1249#else
1250 bandwidth_min = GNUNET_BANDWIDTH_value_min (bandwidth_out,
1251 n->neighbour_receive_quota);
1252#endif
1253 send_outbound_quota_to_clients (&address->peer,
1254 bandwidth_min);
1255 } 1256 }
1256 return; 1257 return;
1257 } 1258 }
@@ -1288,14 +1289,7 @@ set_primary_address (struct NeighbourMapEntry *n,
1288 GNUNET_YES); 1289 GNUNET_YES);
1289 set_incoming_quota (n, 1290 set_incoming_quota (n,
1290 bandwidth_in); 1291 bandwidth_in);
1291#if IGNORE_INBOUND_QUOTA 1292 send_outbound_quota_to_clients (n);
1292 bandwidth_min = bandwidth_out;
1293#else
1294 bandwidth_min = GNUNET_BANDWIDTH_value_min (bandwidth_out,
1295 n->neighbour_receive_quota);
1296#endif
1297 send_outbound_quota_to_clients (&address->peer,
1298 bandwidth_min);
1299 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1293 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1300 "Neighbour `%s' switched to address `%s'\n", 1294 "Neighbour `%s' switched to address `%s'\n",
1301 GNUNET_i2s (&n->id), 1295 GNUNET_i2s (&n->id),
@@ -2215,7 +2209,8 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2215 GNUNET_TIME_UNIT_FOREVER_ABS); 2209 GNUNET_TIME_UNIT_FOREVER_ABS);
2216 GNUNET_assert (GNUNET_OK == 2210 GNUNET_assert (GNUNET_OK ==
2217 GNUNET_CONTAINER_multipeermap_put (neighbours, 2211 GNUNET_CONTAINER_multipeermap_put (neighbours,
2218 &n->id, n, 2212 &n->id,
2213 n,
2219 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2214 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2220 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, 2215 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect,
2221 peer); 2216 peer);
@@ -2544,7 +2539,6 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2544 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2539 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2545{ 2540{
2546 struct NeighbourMapEntry *n; 2541 struct NeighbourMapEntry *n;
2547 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
2548 2542
2549 n = lookup_neighbour (&address->peer); 2543 n = lookup_neighbour (&address->peer);
2550 if ( (NULL == n) || 2544 if ( (NULL == n) ||
@@ -2572,14 +2566,7 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2572 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 2566 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
2573 { 2567 {
2574 n->primary_address.bandwidth_out = bandwidth_out; 2568 n->primary_address.bandwidth_out = bandwidth_out;
2575#if IGNORE_INBOUND_QUOTA 2569 send_outbound_quota_to_clients (n);
2576 bandwidth_min = bandwidth_out;
2577#else
2578 bandwidth_min = GNUNET_BANDWIDTH_value_min (bandwidth_out,
2579 n->neighbour_receive_quota);
2580#endif
2581 send_outbound_quota_to_clients (&address->peer,
2582 bandwidth_min);
2583 } 2570 }
2584 return GNUNET_OK; 2571 return GNUNET_OK;
2585} 2572}
@@ -3687,7 +3674,6 @@ GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
3687{ 3674{
3688 struct NeighbourMapEntry *n; 3675 struct NeighbourMapEntry *n;
3689 const struct SessionQuotaMessage *sqm; 3676 const struct SessionQuotaMessage *sqm;
3690 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
3691 3677
3692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3693 "Received QUOTA message from peer `%s'\n", 3679 "Received QUOTA message from peer `%s'\n",
@@ -3714,14 +3700,7 @@ GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
3714 n->neighbour_receive_quota 3700 n->neighbour_receive_quota
3715 = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 3701 = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
3716 GNUNET_BANDWIDTH_value_init (ntohl (sqm->quota))); 3702 GNUNET_BANDWIDTH_value_init (ntohl (sqm->quota)));
3717#if IGNORE_INBOUND_QUOTA 3703 send_outbound_quota_to_clients (n);
3718 bandwidth_min = n->primary_address.bandwidth_out;
3719#else
3720 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out,
3721 n->neighbour_receive_quota);
3722#endif
3723 send_outbound_quota_to_clients (peer,
3724 bandwidth_min);
3725} 3704}
3726 3705
3727 3706