diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-11 05:16:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-11 05:16:19 +0000 |
commit | 28bb4d6295b3db88677c6a75767252f1aaaf8d2d (patch) | |
tree | ebafc1541a48f264c9de8baf0c574e09e974fddb /src | |
parent | d69f6f4b6394ea1ee30fcb17ef4031ed620cb3a3 (diff) | |
download | gnunet-28bb4d6295b3db88677c6a75767252f1aaaf8d2d.tar.gz gnunet-28bb4d6295b3db88677c6a75767252f1aaaf8d2d.zip |
adding bandwidth management
Diffstat (limited to 'src')
-rw-r--r-- | src/core/gnunet-service-core.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 8cb31b82e..6d022a3d6 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -27,7 +27,6 @@ | |||
27 | * - topology management: | 27 | * - topology management: |
28 | * + bootstrapping (transport offer hello, plugins) | 28 | * + bootstrapping (transport offer hello, plugins) |
29 | * + internal neighbour selection | 29 | * + internal neighbour selection |
30 | * + update (and use!) bandwidth usage statistics | ||
31 | * | 30 | * |
32 | * Considerations for later: | 31 | * Considerations for later: |
33 | * - check that hostkey used by transport (for HELLOs) is the | 32 | * - check that hostkey used by transport (for HELLOs) is the |
@@ -446,7 +445,7 @@ struct Neighbour | |||
446 | * bandwidth-hogs are sampled at a frequency of about 78s!); | 445 | * bandwidth-hogs are sampled at a frequency of about 78s!); |
447 | * may get negative if we have VERY high priority content. | 446 | * may get negative if we have VERY high priority content. |
448 | */ | 447 | */ |
449 | long long available_send_window; // USE! | 448 | long long available_send_window; |
450 | 449 | ||
451 | /** | 450 | /** |
452 | * How much downstream capacity of this peer has been reserved for | 451 | * How much downstream capacity of this peer has been reserved for |
@@ -455,7 +454,7 @@ struct Neighbour | |||
455 | * make sure that this reserved amount of bandwidth is actually | 454 | * make sure that this reserved amount of bandwidth is actually |
456 | * available). | 455 | * available). |
457 | */ | 456 | */ |
458 | long long available_recv_window; // USE! | 457 | long long available_recv_window; |
459 | 458 | ||
460 | /** | 459 | /** |
461 | * How valueable were the messages of this peer recently? | 460 | * How valueable were the messages of this peer recently? |
@@ -699,19 +698,22 @@ update_preference_sum (unsigned long long inc) | |||
699 | * Recalculate the number of bytes we expect to | 698 | * Recalculate the number of bytes we expect to |
700 | * receive or transmit in a given window. | 699 | * receive or transmit in a given window. |
701 | * | 700 | * |
701 | * @param force force an update now (even if not much time has passed) | ||
702 | * @param window pointer to the byte counter (updated) | 702 | * @param window pointer to the byte counter (updated) |
703 | * @param ts pointer to the timestamp (updated) | 703 | * @param ts pointer to the timestamp (updated) |
704 | * @param bpm number of bytes per minute that should | 704 | * @param bpm number of bytes per minute that should |
705 | * be added to the window. | 705 | * be added to the window. |
706 | */ | 706 | */ |
707 | static void | 707 | static void |
708 | update_window (long long *window, | 708 | update_window (int force, |
709 | long long *window, | ||
709 | struct GNUNET_TIME_Absolute *ts, unsigned int bpm) | 710 | struct GNUNET_TIME_Absolute *ts, unsigned int bpm) |
710 | { | 711 | { |
711 | struct GNUNET_TIME_Relative since; | 712 | struct GNUNET_TIME_Relative since; |
712 | 713 | ||
713 | since = GNUNET_TIME_absolute_get_duration (*ts); | 714 | since = GNUNET_TIME_absolute_get_duration (*ts); |
714 | if (since.value < 60 * 1000) | 715 | if ( (force == GNUNET_NO) && |
716 | (since.value < 60 * 1000) ) | ||
715 | return; /* not even a minute has passed */ | 717 | return; /* not even a minute has passed */ |
716 | *ts = GNUNET_TIME_absolute_get (); | 718 | *ts = GNUNET_TIME_absolute_get (); |
717 | *window += (bpm * since.value) / 60 / 1000; | 719 | *window += (bpm * since.value) / 60 / 1000; |
@@ -1065,6 +1067,10 @@ handle_client_request_configure (void *cls, | |||
1065 | memset (&cim, 0, sizeof (cim)); | 1067 | memset (&cim, 0, sizeof (cim)); |
1066 | if ((n != NULL) && (n->status == PEER_STATE_KEY_CONFIRMED)) | 1068 | if ((n != NULL) && (n->status == PEER_STATE_KEY_CONFIRMED)) |
1067 | { | 1069 | { |
1070 | update_window (GNUNET_YES, | ||
1071 | &n->available_send_window, | ||
1072 | &n->last_asw_update, | ||
1073 | n->bpm_out); | ||
1068 | n->bpm_out_internal_limit = ntohl (rcm->limit_outbound_bpm); | 1074 | n->bpm_out_internal_limit = ntohl (rcm->limit_outbound_bpm); |
1069 | n->bpm_out = GNUNET_MAX (n->bpm_out_internal_limit, | 1075 | n->bpm_out = GNUNET_MAX (n->bpm_out_internal_limit, |
1070 | n->bpm_out_external_limit); | 1076 | n->bpm_out_external_limit); |
@@ -1075,7 +1081,8 @@ handle_client_request_configure (void *cls, | |||
1075 | } | 1081 | } |
1076 | else if (reserv > 0) | 1082 | else if (reserv > 0) |
1077 | { | 1083 | { |
1078 | update_window (&n->available_recv_window, | 1084 | update_window (GNUNET_NO, |
1085 | &n->available_recv_window, | ||
1079 | &n->last_arw_update, n->bpm_in); | 1086 | &n->last_arw_update, n->bpm_in); |
1080 | if (n->available_recv_window < reserv) | 1087 | if (n->available_recv_window < reserv) |
1081 | reserv = n->available_recv_window; | 1088 | reserv = n->available_recv_window; |
@@ -1151,6 +1158,7 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf) | |||
1151 | GNUNET_assert (size >= m->size); | 1158 | GNUNET_assert (size >= m->size); |
1152 | memcpy (cbuf, &m[1], m->size); | 1159 | memcpy (cbuf, &m[1], m->size); |
1153 | ret = m->size; | 1160 | ret = m->size; |
1161 | n->available_send_window -= m->size; | ||
1154 | process_encrypted_neighbour_queue (n); | 1162 | process_encrypted_neighbour_queue (n); |
1155 | #if DEBUG_CORE | 1163 | #if DEBUG_CORE |
1156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1364,7 +1372,11 @@ select_messages (struct Neighbour *n, | |||
1364 | min = NULL; | 1372 | min = NULL; |
1365 | min_prio = -1; | 1373 | min_prio = -1; |
1366 | discard_low_prio = GNUNET_NO; | 1374 | discard_low_prio = GNUNET_NO; |
1367 | /* number of bytes available for transmission at time "t" */ | 1375 | /* calculate number of bytes available for transmission at time "t" */ |
1376 | update_window (GNUNET_NO, | ||
1377 | &n->available_send_window, | ||
1378 | &n->last_asw_update, | ||
1379 | n->bpm_out); | ||
1368 | avail = n->available_send_window; | 1380 | avail = n->available_send_window; |
1369 | t = n->last_asw_update; | 1381 | t = n->last_asw_update; |
1370 | /* how many bytes have we (hypothetically) scheduled so far */ | 1382 | /* how many bytes have we (hypothetically) scheduled so far */ |
@@ -2660,7 +2672,7 @@ handle_encrypted_message (struct Neighbour *n, | |||
2660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2661 | "Core service receives `%s' request from `%4s'.\n", | 2673 | "Core service receives `%s' request from `%4s'.\n", |
2662 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); | 2674 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); |
2663 | #endif | 2675 | #endif |
2664 | /* decrypt */ | 2676 | /* decrypt */ |
2665 | if (GNUNET_OK != | 2677 | if (GNUNET_OK != |
2666 | do_decrypt (n, | 2678 | do_decrypt (n, |
@@ -2728,6 +2740,10 @@ handle_encrypted_message (struct Neighbour *n, | |||
2728 | } | 2740 | } |
2729 | 2741 | ||
2730 | /* process decrypted message(s) */ | 2742 | /* process decrypted message(s) */ |
2743 | update_window (GNUNET_YES, | ||
2744 | &n->available_send_window, | ||
2745 | &n->last_asw_update, | ||
2746 | n->bpm_out); | ||
2731 | n->bpm_out_external_limit = ntohl (pt->inbound_bpm_limit); | 2747 | n->bpm_out_external_limit = ntohl (pt->inbound_bpm_limit); |
2732 | n->bpm_out = GNUNET_MAX (n->bpm_out_external_limit, | 2748 | n->bpm_out = GNUNET_MAX (n->bpm_out_external_limit, |
2733 | n->bpm_out_internal_limit); | 2749 | n->bpm_out_internal_limit); |