diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-03-01 15:41:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-03-01 15:41:33 +0000 |
commit | 9d2cd5be986a0732b9e5a8fcdf5acd1c7225ef2f (patch) | |
tree | 00eeb028c2310a027be79684da454360b96936fb /src | |
parent | 629ff286ace0543d2d984319fba6bacf60408890 (diff) | |
download | gnunet-9d2cd5be986a0732b9e5a8fcdf5acd1c7225ef2f.tar.gz gnunet-9d2cd5be986a0732b9e5a8fcdf5acd1c7225ef2f.zip |
calc update
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 5048b029c..d654fcc8c 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -863,50 +863,26 @@ find_transport (const char *short_name) | |||
863 | 863 | ||
864 | /** | 864 | /** |
865 | * Update the quota values for the given neighbour now. | 865 | * Update the quota values for the given neighbour now. |
866 | * | ||
867 | * @param n neighbour to update | ||
868 | * @param force GNUNET_YES to force recalculation now | ||
866 | */ | 869 | */ |
867 | static void | 870 | static void |
868 | update_quota (struct NeighbourList *n) | 871 | update_quota (struct NeighbourList *n, |
872 | int force) | ||
869 | { | 873 | { |
870 | struct GNUNET_TIME_Relative delta; | ||
871 | uint64_t allowed; | ||
872 | uint64_t remaining; | ||
873 | |||
874 | #if 0 | ||
875 | struct GNUNET_TIME_Absolute now; | 874 | struct GNUNET_TIME_Absolute now; |
876 | unsigned long long delta; | 875 | unsigned long long delta; |
877 | unsigned long long total_allowed; | 876 | uint64_t allowed; |
878 | unsigned long long total_remaining; | 877 | uint64_t remaining; |
879 | 878 | ||
880 | now = GNUNET_TIME_absolute_get (); | 879 | now = GNUNET_TIME_absolute_get (); |
881 | delta = now.value - session->last_quota_update.value; | 880 | delta = now.value - n->last_quota_update.value; |
882 | if ((delta < MIN_QUOTA_REFRESH_TIME) && (!force)) | 881 | allowed = n->quota_in * delta; |
882 | if ( (delta < MIN_QUOTA_REFRESH_TIME) && | ||
883 | (!force) && | ||
884 | (allowed < 32 * 1024) ) | ||
883 | return; /* too early, not enough data */ | 885 | return; /* too early, not enough data */ |
884 | |||
885 | total_allowed = session->quota_in * delta; | ||
886 | if (total_allowed > session->last_received) | ||
887 | { | ||
888 | /* got less than acceptable */ | ||
889 | total_remaining = total_allowed - session->last_received; | ||
890 | session->last_received = 0; | ||
891 | delta = total_remaining / session->quota_in; /* bonus seconds */ | ||
892 | if (delta > MAX_BANDWIDTH_CARRY) | ||
893 | delta = MAX_BANDWIDTH_CARRY; /* limit amount of carry-over */ | ||
894 | } | ||
895 | else | ||
896 | { | ||
897 | /* got more than acceptable */ | ||
898 | session->last_received -= total_allowed; | ||
899 | delta = 0; | ||
900 | } | ||
901 | session->last_quota_update.value = now.value - delta; | ||
902 | #endif | ||
903 | |||
904 | |||
905 | delta = GNUNET_TIME_absolute_get_duration (n->last_quota_update); | ||
906 | if (delta.value < MIN_QUOTA_REFRESH_TIME) | ||
907 | return; /* not enough time passed for doing quota update */ | ||
908 | allowed = delta.value * n->quota_in; | ||
909 | |||
910 | if (n->last_received < allowed) | 886 | if (n->last_received < allowed) |
911 | { | 887 | { |
912 | remaining = allowed - n->last_received; | 888 | remaining = allowed - n->last_received; |
@@ -917,7 +893,7 @@ update_quota (struct NeighbourList *n) | |||
917 | if (remaining > MAX_BANDWIDTH_CARRY) | 893 | if (remaining > MAX_BANDWIDTH_CARRY) |
918 | remaining = MAX_BANDWIDTH_CARRY; | 894 | remaining = MAX_BANDWIDTH_CARRY; |
919 | n->last_received = 0; | 895 | n->last_received = 0; |
920 | n->last_quota_update = GNUNET_TIME_absolute_get (); | 896 | n->last_quota_update = now; |
921 | n->last_quota_update.value -= remaining; | 897 | n->last_quota_update.value -= remaining; |
922 | if (n->quota_violation_count > 0) | 898 | if (n->quota_violation_count > 0) |
923 | n->quota_violation_count--; | 899 | n->quota_violation_count--; |
@@ -925,10 +901,10 @@ update_quota (struct NeighbourList *n) | |||
925 | else | 901 | else |
926 | { | 902 | { |
927 | n->last_received -= allowed; | 903 | n->last_received -= allowed; |
928 | n->last_quota_update = GNUNET_TIME_absolute_get (); | 904 | n->last_quota_update = now; |
929 | if (n->last_received > allowed) | 905 | if (n->last_received > allowed) |
930 | { | 906 | { |
931 | /* more than twice the allowed rate! */ | 907 | /* much more than the allowed rate! */ |
932 | n->quota_violation_count += 10; | 908 | n->quota_violation_count += 10; |
933 | } | 909 | } |
934 | } | 910 | } |
@@ -2589,7 +2565,7 @@ calculate_throttle_delay (struct NeighbourList *n) | |||
2589 | del = now.value - n->last_quota_update.value; | 2565 | del = now.value - n->last_quota_update.value; |
2590 | if (del > MAX_BANDWIDTH_CARRY) | 2566 | if (del > MAX_BANDWIDTH_CARRY) |
2591 | { | 2567 | { |
2592 | update_quota (n /*, GNUNET_YES*/); | 2568 | update_quota (n, GNUNET_YES); |
2593 | del = now.value - n->last_quota_update.value; | 2569 | del = now.value - n->last_quota_update.value; |
2594 | GNUNET_assert (del <= MAX_BANDWIDTH_CARRY); | 2570 | GNUNET_assert (del <= MAX_BANDWIDTH_CARRY); |
2595 | } | 2571 | } |
@@ -2643,6 +2619,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2643 | n = find_neighbour (peer); | 2619 | n = find_neighbour (peer); |
2644 | if (n == NULL) | 2620 | if (n == NULL) |
2645 | n = setup_new_neighbour (peer); | 2621 | n = setup_new_neighbour (peer); |
2622 | update_quota (n, GNUNET_NO); | ||
2646 | service_context = n->plugins; | 2623 | service_context = n->plugins; |
2647 | while ((service_context != NULL) && (plugin != service_context->plugin)) | 2624 | while ((service_context != NULL) && (plugin != service_context->plugin)) |
2648 | service_context = service_context->next; | 2625 | service_context = service_context->next; |
@@ -2901,7 +2878,7 @@ handle_set_quota (void *cls, | |||
2901 | "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n", | 2878 | "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n", |
2902 | "SET_QUOTA", qin, n->quota_in, GNUNET_i2s (&qsm->peer)); | 2879 | "SET_QUOTA", qin, n->quota_in, GNUNET_i2s (&qsm->peer)); |
2903 | #endif | 2880 | #endif |
2904 | update_quota (n); | 2881 | update_quota (n, GNUNET_YES); |
2905 | if (n->quota_in < qin) | 2882 | if (n->quota_in < qin) |
2906 | n->last_quota_update = GNUNET_TIME_absolute_get (); | 2883 | n->last_quota_update = GNUNET_TIME_absolute_get (); |
2907 | n->quota_in = qin; | 2884 | n->quota_in = qin; |