diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index d89aa2f32..c10d6ccfd 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -92,6 +92,11 @@ | |||
92 | */ | 92 | */ |
93 | #define BLACKLIST_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) | 93 | #define BLACKLIST_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) |
94 | 94 | ||
95 | /** | ||
96 | * Interval to send utilization data | ||
97 | */ | ||
98 | #define UTIL_TRANSMISSION_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
99 | |||
95 | #define DEBUG_MALLOC GNUNET_NO | 100 | #define DEBUG_MALLOC GNUNET_NO |
96 | 101 | ||
97 | #if DEBUG_MALLOC | 102 | #if DEBUG_MALLOC |
@@ -704,6 +709,21 @@ struct NeighbourMapEntry | |||
704 | */ | 709 | */ |
705 | int send_connect_ack; | 710 | int send_connect_ack; |
706 | 711 | ||
712 | /** | ||
713 | * Tracking utilization of outbound bandwidth | ||
714 | */ | ||
715 | unsigned int util_bytes_sent; | ||
716 | |||
717 | /** | ||
718 | * Tracking utilization of inbound bandwidth | ||
719 | */ | ||
720 | unsigned int util_bytes_recv; | ||
721 | |||
722 | |||
723 | /** | ||
724 | * Date of last utilization transmission | ||
725 | */ | ||
726 | struct GNUNET_TIME_Absolute last_util_transmission; | ||
707 | }; | 727 | }; |
708 | 728 | ||
709 | 729 | ||
@@ -783,6 +803,11 @@ static unsigned int neighbours_connected; | |||
783 | */ | 803 | */ |
784 | static unsigned long long bytes_in_send_queue; | 804 | static unsigned long long bytes_in_send_queue; |
785 | 805 | ||
806 | /** | ||
807 | * Task transmitting utilization data | ||
808 | */ | ||
809 | static GNUNET_SCHEDULER_TaskIdentifier util_transmission_tk; | ||
810 | |||
786 | 811 | ||
787 | /** | 812 | /** |
788 | * Lookup a neighbour entry in the neighbours hash map. | 813 | * Lookup a neighbour entry in the neighbours hash map. |
@@ -1346,10 +1371,13 @@ transmit_send_continuation (void *cls, | |||
1346 | ("# bytes in message queue for other peers"), | 1371 | ("# bytes in message queue for other peers"), |
1347 | bytes_in_send_queue, GNUNET_NO); | 1372 | bytes_in_send_queue, GNUNET_NO); |
1348 | if (GNUNET_OK == success) | 1373 | if (GNUNET_OK == success) |
1374 | { | ||
1375 | n->util_bytes_sent += size_payload; | ||
1349 | GNUNET_STATISTICS_update (GST_stats, | 1376 | GNUNET_STATISTICS_update (GST_stats, |
1350 | gettext_noop | 1377 | gettext_noop |
1351 | ("# messages transmitted to other peers"), | 1378 | ("# messages transmitted to other peers"), |
1352 | 1, GNUNET_NO); | 1379 | 1, GNUNET_NO); |
1380 | } | ||
1353 | else | 1381 | else |
1354 | GNUNET_STATISTICS_update (GST_stats, | 1382 | GNUNET_STATISTICS_update (GST_stats, |
1355 | gettext_noop | 1383 | gettext_noop |
@@ -1794,6 +1822,9 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
1794 | n->id = *peer; | 1822 | n->id = *peer; |
1795 | n->state = S_NOT_CONNECTED; | 1823 | n->state = S_NOT_CONNECTED; |
1796 | n->latency = GNUNET_TIME_UNIT_FOREVER_REL; | 1824 | n->latency = GNUNET_TIME_UNIT_FOREVER_REL; |
1825 | n->last_util_transmission = GNUNET_TIME_absolute_get(); | ||
1826 | n->util_bytes_recv = 0; | ||
1827 | n->util_bytes_sent = 0; | ||
1797 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, | 1828 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, |
1798 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | 1829 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, |
1799 | MAX_BANDWIDTH_CARRY_S); | 1830 | MAX_BANDWIDTH_CARRY_S); |
@@ -2512,6 +2543,74 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
2512 | } | 2543 | } |
2513 | } | 2544 | } |
2514 | 2545 | ||
2546 | static int | ||
2547 | util_it (void *cls, | ||
2548 | const struct GNUNET_PeerIdentity *key, | ||
2549 | void *value) | ||
2550 | { | ||
2551 | struct NeighbourMapEntry *n = value; | ||
2552 | struct GNUNET_ATS_Information atsi[2]; | ||
2553 | uint32_t bps_in; | ||
2554 | uint32_t bps_out; | ||
2555 | struct GNUNET_TIME_Relative delta; | ||
2556 | |||
2557 | delta = GNUNET_TIME_absolute_get_difference(n->last_util_transmission, GNUNET_TIME_absolute_get()); | ||
2558 | bps_in = 0; | ||
2559 | if (0 != n->util_bytes_recv) | ||
2560 | bps_in = ((1000 * 1000) * n->util_bytes_recv) / (delta.rel_value_us); | ||
2561 | bps_out = 0; | ||
2562 | if (0 != n->util_bytes_sent) | ||
2563 | bps_out = ((1000 * 1000) * n->util_bytes_sent) / (delta.rel_value_us); | ||
2564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': Bytes sent: %u recv %u in %llu sec.\n", | ||
2565 | GNUNET_i2s (key), bps_out, bps_in, delta.rel_value_us / (1000 * 1000)); | ||
2566 | atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP); | ||
2567 | atsi[0].value = htonl (bps_out); | ||
2568 | atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN); | ||
2569 | atsi[1].value = htonl (bps_in); | ||
2570 | GNUNET_ATS_address_update (GST_ats, n->primary_address.address, | ||
2571 | n->primary_address.session, atsi, 2); | ||
2572 | n->util_bytes_recv = 0; | ||
2573 | n->util_bytes_sent = 0; | ||
2574 | n->last_util_transmission = GNUNET_TIME_absolute_get(); | ||
2575 | return GNUNET_OK; | ||
2576 | } | ||
2577 | |||
2578 | /** | ||
2579 | * Task transmitting utilization in a regular interval | ||
2580 | * | ||
2581 | * @param cls the 'struct NeighbourMapEntry' for which we are running | ||
2582 | * @param tc scheduler context (unused) | ||
2583 | */ | ||
2584 | static void | ||
2585 | utilization_transmission (void *cls, | ||
2586 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2587 | { | ||
2588 | util_transmission_tk = GNUNET_SCHEDULER_NO_TASK; | ||
2589 | |||
2590 | if (0 < GNUNET_CONTAINER_multipeermap_size (neighbours)) | ||
2591 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, util_it, NULL); | ||
2592 | |||
2593 | util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, | ||
2594 | utilization_transmission, NULL); | ||
2595 | |||
2596 | } | ||
2597 | |||
2598 | void | ||
2599 | GST_neighbours_notify_payload (const struct GNUNET_PeerIdentity *peer, | ||
2600 | const struct GNUNET_HELLO_Address *address, | ||
2601 | struct Session *session, | ||
2602 | const struct GNUNET_MessageHeader *message) | ||
2603 | { | ||
2604 | struct NeighbourMapEntry *n; | ||
2605 | n = lookup_neighbour (peer); | ||
2606 | if (NULL == n) | ||
2607 | { | ||
2608 | GNUNET_break (0); | ||
2609 | return; | ||
2610 | } | ||
2611 | n->util_bytes_recv += ntohs(message->size); | ||
2612 | } | ||
2613 | |||
2515 | 2614 | ||
2516 | /** | 2615 | /** |
2517 | * Master task run for every neighbour. Performs all of the time-related | 2616 | * Master task run for every neighbour. Performs all of the time-related |
@@ -3376,6 +3475,8 @@ GST_neighbours_start (void *cls, | |||
3376 | disconnect_notify_cb = disconnect_cb; | 3475 | disconnect_notify_cb = disconnect_cb; |
3377 | address_change_cb = peer_address_cb; | 3476 | address_change_cb = peer_address_cb; |
3378 | neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); | 3477 | neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); |
3478 | util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, | ||
3479 | utilization_transmission, NULL); | ||
3379 | } | 3480 | } |
3380 | 3481 | ||
3381 | 3482 | ||
@@ -3411,6 +3512,12 @@ GST_neighbours_stop () | |||
3411 | { | 3512 | { |
3412 | if (NULL == neighbours) | 3513 | if (NULL == neighbours) |
3413 | return; | 3514 | return; |
3515 | if (GNUNET_SCHEDULER_NO_TASK != util_transmission_tk) | ||
3516 | { | ||
3517 | GNUNET_SCHEDULER_cancel (util_transmission_tk); | ||
3518 | util_transmission_tk = GNUNET_SCHEDULER_NO_TASK; | ||
3519 | } | ||
3520 | |||
3414 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | 3521 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, |
3415 | &disconnect_all_neighbours, | 3522 | &disconnect_all_neighbours, |
3416 | NULL); | 3523 | NULL); |