diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-27 12:09:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-27 12:09:08 +0000 |
commit | a72e9c845490ca348f4abf24863c2e2e0a7f13d5 (patch) | |
tree | a9ec5b9155d2f7d9e96732049c6f5bcabe6c103a /src/core | |
parent | ea6fd392e46097097812e08a526c629998da26b8 (diff) | |
download | gnunet-a72e9c845490ca348f4abf24863c2e2e0a7f13d5.tar.gz gnunet-a72e9c845490ca348f4abf24863c2e2e0a7f13d5.zip |
fix quota calculation
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core.h | 2 | ||||
-rw-r--r-- | src/core/gnunet-service-core.c | 34 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/core/core.h b/src/core/core.h index 701078ee5..d74ee06f6 100644 --- a/src/core/core.h +++ b/src/core/core.h | |||
@@ -29,7 +29,7 @@ | |||
29 | /** | 29 | /** |
30 | * General core debugging. | 30 | * General core debugging. |
31 | */ | 31 | */ |
32 | #define DEBUG_CORE GNUNET_NO | 32 | #define DEBUG_CORE GNUNET_YES |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Debugging interaction core-clients. | 35 | * Debugging interaction core-clients. |
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2cd4039fe..81a168b7f 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -43,6 +43,8 @@ | |||
43 | 43 | ||
44 | #define DEBUG_HANDSHAKE GNUNET_NO | 44 | #define DEBUG_HANDSHAKE GNUNET_NO |
45 | 45 | ||
46 | #define DEBUG_CORE_QUOTA GNUNET_YES | ||
47 | |||
46 | /** | 48 | /** |
47 | * Receive and send buffer windows grow over time. For | 49 | * Receive and send buffer windows grow over time. For |
48 | * how long can 'unused' bandwidth accumulate before we | 50 | * how long can 'unused' bandwidth accumulate before we |
@@ -1242,14 +1244,13 @@ notify_encrypted_transmit_ready (void *cls, size_t size, void *buf) | |||
1242 | memcpy (cbuf, &m[1], m->size); | 1244 | memcpy (cbuf, &m[1], m->size); |
1243 | ret = m->size; | 1245 | ret = m->size; |
1244 | n->available_send_window -= m->size; | 1246 | n->available_send_window -= m->size; |
1245 | process_encrypted_neighbour_queue (n); | ||
1246 | |||
1247 | #if DEBUG_CORE | 1247 | #if DEBUG_CORE |
1248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1249 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", | 1249 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", |
1250 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), | 1250 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), |
1251 | ret, GNUNET_i2s (&n->peer)); | 1251 | ret, GNUNET_i2s (&n->peer)); |
1252 | #endif | 1252 | #endif |
1253 | process_encrypted_neighbour_queue (n); | ||
1253 | } | 1254 | } |
1254 | else | 1255 | else |
1255 | { | 1256 | { |
@@ -1444,6 +1445,7 @@ select_messages (struct Neighbour *n, | |||
1444 | unsigned long long slack; /* how long could we wait before missing deadlines? */ | 1445 | unsigned long long slack; /* how long could we wait before missing deadlines? */ |
1445 | size_t off; | 1446 | size_t off; |
1446 | int discard_low_prio; | 1447 | int discard_low_prio; |
1448 | unsigned int queue_size; | ||
1447 | 1449 | ||
1448 | GNUNET_assert (NULL != n->messages); | 1450 | GNUNET_assert (NULL != n->messages); |
1449 | now = GNUNET_TIME_absolute_get (); | 1451 | now = GNUNET_TIME_absolute_get (); |
@@ -1452,6 +1454,13 @@ select_messages (struct Neighbour *n, | |||
1452 | /* should we remove the entry with the lowest | 1454 | /* should we remove the entry with the lowest |
1453 | priority from consideration for scheduling at the | 1455 | priority from consideration for scheduling at the |
1454 | end of the loop? */ | 1456 | end of the loop? */ |
1457 | queue_size = 0; | ||
1458 | pos = n->messages; | ||
1459 | while (pos != NULL) | ||
1460 | { | ||
1461 | queue_size++; | ||
1462 | pos = pos->next; | ||
1463 | } | ||
1455 | discard_low_prio = GNUNET_YES; | 1464 | discard_low_prio = GNUNET_YES; |
1456 | while (GNUNET_YES == discard_low_prio) | 1465 | while (GNUNET_YES == discard_low_prio) |
1457 | { | 1466 | { |
@@ -1477,7 +1486,7 @@ select_messages (struct Neighbour *n, | |||
1477 | sense since new message might be scheduled in the | 1486 | sense since new message might be scheduled in the |
1478 | meantime... */ | 1487 | meantime... */ |
1479 | while ((pos != NULL) && (off < size * 2)) | 1488 | while ((pos != NULL) && (off < size * 2)) |
1480 | { | 1489 | { |
1481 | if (pos->do_transmit == GNUNET_YES) | 1490 | if (pos->do_transmit == GNUNET_YES) |
1482 | { | 1491 | { |
1483 | /* already removed from consideration */ | 1492 | /* already removed from consideration */ |
@@ -1537,7 +1546,9 @@ select_messages (struct Neighbour *n, | |||
1537 | } | 1546 | } |
1538 | /* guard against sending "tiny" messages with large headers without | 1547 | /* guard against sending "tiny" messages with large headers without |
1539 | urgent deadlines */ | 1548 | urgent deadlines */ |
1540 | if ( (slack > 1000) && (size > 4 * off) ) | 1549 | if ( (slack > 1000) && |
1550 | (size > 4 * off) && | ||
1551 | (queue_size < MAX_PEER_QUEUE_SIZE / 2) ) | ||
1541 | { | 1552 | { |
1542 | /* less than 25% of message would be filled with deadlines still | 1553 | /* less than 25% of message would be filled with deadlines still |
1543 | being met if we delay by one second or more; so just wait for | 1554 | being met if we delay by one second or more; so just wait for |
@@ -1552,7 +1563,9 @@ select_messages (struct Neighbour *n, | |||
1552 | } | 1563 | } |
1553 | #if DEBUG_CORE | 1564 | #if DEBUG_CORE |
1554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1555 | "Deferring transmission for 1s due to underfull message buffer size\n"); | 1566 | "Deferring transmission for 1s due to underfull message buffer size (%u/%u)\n", |
1567 | (unsigned int) off, | ||
1568 | (unsigned int) size); | ||
1556 | #endif | 1569 | #endif |
1557 | return 0; | 1570 | return 0; |
1558 | } | 1571 | } |
@@ -2076,7 +2089,11 @@ handle_client_send (void *cls, | |||
2076 | /* discard new entry */ | 2089 | /* discard new entry */ |
2077 | #if DEBUG_CORE | 2090 | #if DEBUG_CORE |
2078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2079 | "Queue full, discarding new request\n"); | 2092 | "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", |
2093 | queue_size, | ||
2094 | MAX_PEER_QUEUE_SIZE, | ||
2095 | msize, | ||
2096 | ntohs (message->type)); | ||
2080 | #endif | 2097 | #endif |
2081 | if (client != NULL) | 2098 | if (client != NULL) |
2082 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2099 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -3242,6 +3259,8 @@ neighbour_quota_update (void *cls, | |||
3242 | double pref_rel; | 3259 | double pref_rel; |
3243 | double share; | 3260 | double share; |
3244 | unsigned long long distributable; | 3261 | unsigned long long distributable; |
3262 | uint32_t qin_ms; | ||
3263 | uint32_t qout_ms; | ||
3245 | 3264 | ||
3246 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; | 3265 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; |
3247 | /* calculate relative preference among all neighbours; | 3266 | /* calculate relative preference among all neighbours; |
@@ -3286,6 +3305,9 @@ neighbour_quota_update (void *cls, | |||
3286 | (n->bpm_in - MIN_BPM_CHANGE > q_in) ) | 3305 | (n->bpm_in - MIN_BPM_CHANGE > q_in) ) |
3287 | { | 3306 | { |
3288 | n->bpm_in = q_in; | 3307 | n->bpm_in = q_in; |
3308 | /* need to convert to bytes / ms, rounding up! */ | ||
3309 | qin_ms = (q_in == 0) ? 0 : 1 + q_in / 60000; | ||
3310 | qout_ms = (n->bpm_out == 0) ? 0 : 1 + n->bpm_out / 60000; | ||
3289 | GNUNET_TRANSPORT_set_quota (transport, | 3311 | GNUNET_TRANSPORT_set_quota (transport, |
3290 | &n->peer, | 3312 | &n->peer, |
3291 | n->bpm_in, | 3313 | n->bpm_in, |