aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-05-21 15:50:13 +0200
committerChristian Grothoff <christian@grothoff.org>2019-05-21 15:50:13 +0200
commit49227270d760cf72978eeec8d0684b855deea526 (patch)
treeba7640f4e269a55fd383cfa99051ea373c89d38a
parent426317707f34282830e5595193fcf2546c7d5b49 (diff)
downloadgnunet-49227270d760cf72978eeec8d0684b855deea526.tar.gz
gnunet-49227270d760cf72978eeec8d0684b855deea526.zip
use bytes, not kilobytes
-rw-r--r--src/transport/gnunet-service-tng.c138
1 files changed, 67 insertions, 71 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 20285f94a..2af699dc1 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -28,20 +28,20 @@
28 * communicators do not offer flow control). 28 * communicators do not offer flow control).
29 * We do transmit FC window sizes now. Left: 29 * We do transmit FC window sizes now. Left:
30 * for SENDING) 30 * for SENDING)
31 * - Increment "outbound_fc_window_size_used_kb" on transmission 31 * - Increment "outbound_fc_window_size_used" on transmission
32 * - Throttle sending if "outbound_fc_window_size_used_kb" reaches limit 32 * - Throttle sending if "outbound_fc_window_size_used" reaches limit
33 * - Send *new* challenge when we get close to the limit (including 33 * - Send *new* challenge when we get close to the limit (including
34 * at the beginning when the limit is zero!) 34 * at the beginning when the limit is zero!)
35 * - Retransmit challenge if it goes unanswered! 35 * - Retransmit challenge if it goes unanswered!
36 * 36 *
37 * for RECEIVING) 37 * for RECEIVING)
38 * - increment incoming_fc_window_size_ram_kb when receiving 38 * - increment incoming_fc_window_size_ram when receiving
39 * incoming packets! 39 * incoming packets!
40 * - OR drop if incoming_fc_window_size_ram goes 40 * - OR drop if incoming_fc_window_size_ram goes
41 * (significantly?) beyond available_fc_window_size_kb 41 * (significantly?) beyond available_fc_window_size
42 * - decrement incoming_fc_window_size_ram_kb when CORE is done 42 * - decrement incoming_fc_window_size_ram when CORE is done
43 * with incoming packets! 43 * with incoming packets!
44 * - increment incoming_fc_window_size_used_kb when CORE is done 44 * - increment incoming_fc_window_size_used when CORE is done
45 * with incoming packets! 45 * with incoming packets!
46 * 46 *
47 * for DV) 47 * for DV)
@@ -85,9 +85,9 @@
85 * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH] 85 * AcknowledgementUUIDP altogether, as they won't be acked! [BANDWIDTH]
86 * (-> have 2nd type of acknowledgment message; low priority, as we 86 * (-> have 2nd type of acknowledgment message; low priority, as we
87 * do not have an MTU-limited *reliable* communicator) 87 * do not have an MTU-limited *reliable* communicator)
88 * - Adapt available_fc_window_size_kb, using larger values for high-bandwidth 88 * - Adapt available_fc_window_size, using larger values for high-bandwidth
89 * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls] 89 * and high-latency links *if* we have the RAM [GOODPUT / utilization / stalls]
90 * - Set last_window_consum_limit_kb promise properly based on 90 * - Set last_window_consum_limit promise properly based on
91 * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls] 91 * latency and bandwidth of the respective connection [GOODPUT / utilization / stalls]
92 * - re-sending challenge response without a challenge when we have 92 * - re-sending challenge response without a challenge when we have
93 * significantly increased the FC window (upon CORE being done with messages) 93 * significantly increased the FC window (upon CORE being done with messages)
@@ -149,9 +149,9 @@
149 149
150/** 150/**
151 * How big is the flow control window size by default; 151 * How big is the flow control window size by default;
152 * limits per-neighbour RAM utilization (in kilobytes). 152 * limits per-neighbour RAM utilization.
153 */ 153 */
154#define DEFAULT_WINDOW_SIZE_KB 128 154#define DEFAULT_WINDOW_SIZE (128 * 1024)
155 155
156/** 156/**
157 * For how many incoming connections do we try to create a 157 * For how many incoming connections do we try to create a
@@ -844,11 +844,11 @@ struct TransportValidationChallengeMessage
844 struct GNUNET_MessageHeader header; 844 struct GNUNET_MessageHeader header;
845 845
846 /** 846 /**
847 * Maximum number of kilobytes of the flow control window of 847 * Maximum number of bytes of the flow control window of
848 * the previous challenge that the sender may consume. 848 * the previous challenge that the sender may consume.
849 * After sending this message (with a new challenge), 849 * After sending this message (with a new challenge),
850 * the sender promises to never use more than this number 850 * the sender promises to never use more than this number
851 * of kilobytes of the flow control window of a previous 851 * of bytes of the flow control window of a previous
852 * handshake. Note that the number set here might be larger 852 * handshake. Note that the number set here might be larger
853 * than the actual number the sender will use: to avoid 853 * than the actual number the sender will use: to avoid
854 * a stall, the sender would estimate how long it would 854 * a stall, the sender would estimate how long it would
@@ -860,7 +860,7 @@ struct TransportValidationChallengeMessage
860 * If this is the first challenge (initial connection 860 * If this is the first challenge (initial connection
861 * establishment), this value must be zero. 861 * establishment), this value must be zero.
862 */ 862 */
863 uint32_t last_window_consum_limit_kb GNUNET_PACKED; 863 uint32_t last_window_consum_limit GNUNET_PACKED;
864 864
865 /** 865 /**
866 * Challenge to be signed by the receiving peer. 866 * Challenge to be signed by the receiving peer.
@@ -913,11 +913,11 @@ struct TransportValidationResponseMessage
913 struct GNUNET_MessageHeader header; 913 struct GNUNET_MessageHeader header;
914 914
915 /** 915 /**
916 * Flow control window size in kilobytes (1024 b), in NBO. 916 * Flow control window size in bytes, in NBO.
917 * The receiver can now send this many kilobytes as per 917 * The receiver can now send this many bytes as per
918 * the @e challenge "account". 918 * the @e challenge "account".
919 */ 919 */
920 uint32_t fc_window_size_kb GNUNET_PACKED; 920 uint32_t fc_window_size GNUNET_PACKED;
921 921
922 /** 922 /**
923 * The peer's signature matching the 923 * The peer's signature matching the
@@ -1228,7 +1228,7 @@ struct VirtualLink
1228 1228
1229 /** 1229 /**
1230 * Last challenge we received from @a n, for which we created the 1230 * Last challenge we received from @a n, for which we created the
1231 * flow control window given in @e fc_window_size_kb. 1231 * flow control window given in @e fc_window_size.
1232 */ 1232 */
1233 struct ChallengeNonceP n_challenge; 1233 struct ChallengeNonceP n_challenge;
1234 1234
@@ -1244,9 +1244,9 @@ struct VirtualLink
1244 * we are willing to allocate to this virtual link. OPTIMIZE-ME: 1244 * we are willing to allocate to this virtual link. OPTIMIZE-ME:
1245 * Can be adapted to dedicate more RAM to links that need it, while 1245 * Can be adapted to dedicate more RAM to links that need it, while
1246 * sticking to some overall RAM limit. For now, set to 1246 * sticking to some overall RAM limit. For now, set to
1247 * #DEFAULT_WINDOW_SIZE_KB. 1247 * #DEFAULT_WINDOW_SIZE.
1248 */ 1248 */
1249 uint32_t available_fc_window_size_kb; 1249 uint32_t available_fc_window_size;
1250 1250
1251 /** 1251 /**
1252 * Memory actually used to buffer packets on this virtual link. 1252 * Memory actually used to buffer packets on this virtual link.
@@ -1254,45 +1254,45 @@ struct VirtualLink
1254 * Note that once CORE is done with a packet, we decrement the value 1254 * Note that once CORE is done with a packet, we decrement the value
1255 * here. 1255 * here.
1256 */ 1256 */
1257 uint32_t incoming_fc_window_size_ram_kb; 1257 uint32_t incoming_fc_window_size_ram;
1258 1258
1259 /** 1259 /**
1260 * Last flow control window size we provided to the other peer, in 1260 * Last flow control window size we provided to the other peer, in
1261 * kilobytes (1024 b). We are allowing the other peer to send this 1261 * bytes. We are allowing the other peer to send this
1262 * many kilobytes as per its last @e n_challenge "account". 1262 * many bytes as per its last @e n_challenge "account".
1263 */ 1263 */
1264 uint32_t incoming_fc_window_size_kb; 1264 uint32_t incoming_fc_window_size;
1265 1265
1266 /** 1266 /**
1267 * How many bytes could we still get from the previous flow control 1267 * How many bytes could we still get from the previous flow control
1268 * window, in kilobytes (1024 b). We need to consider this value 1268 * window, in bytes. We need to consider this value
1269 * when calculating what we allow for the current window due to 1269 * when calculating what we allow for the current window due to
1270 * the possibility of out-of-order challenges. 1270 * the possibility of out-of-order challenges.
1271 */ 1271 */
1272 uint32_t last_fc_window_size_remaining_kb; 1272 uint32_t last_fc_window_size_remaining;
1273 1273
1274 /** 1274 /**
1275 * How much of the window did the other peer successfully use (and 1275 * How much of the window did the other peer successfully use (and
1276 * we already passed it on to CORE)? Must be below @e 1276 * we already passed it on to CORE)? Must be below @e
1277 * incoming_fc_window_size_kb. We should effectively signal the 1277 * incoming_fc_window_size. We should effectively signal the
1278 * other peer that the window is this much bigger at the next 1278 * other peer that the window is this much bigger at the next
1279 * opportunity / challenge. 1279 * opportunity / challenge.
1280 */ 1280 */
1281 uint32_t incoming_fc_window_size_used_kb; 1281 uint32_t incoming_fc_window_size_used;
1282 1282
1283 /** 1283 /**
1284 * Our current flow control window size in kilobytes (1024 b). We 1284 * Our current flow control window size in bytes. We
1285 * are allowed to transmit this many kilobytes to @a n as per 1285 * are allowed to transmit this many bytes to @a n as per
1286 * our @e my_challenge "account". 1286 * our @e my_challenge "account".
1287 */ 1287 */
1288 uint32_t outbound_fc_window_size_kb; 1288 uint32_t outbound_fc_window_size;
1289 1289
1290 /** 1290 /**
1291 * How much of our current flow control window size have we 1291 * How much of our current flow control window size have we
1292 * used (in kilobytes (1024 b)). Must be below 1292 * used (in bytes). Must be below
1293 * @e outbound_fc_window_size_kb. 1293 * @e outbound_fc_window_size.
1294 */ 1294 */
1295 uint32_t outbound_fc_window_size_used_kb; 1295 uint32_t outbound_fc_window_size_used;
1296 1296
1297 /** 1297 /**
1298 * How many more messages can we send to CORE before we exhaust 1298 * How many more messages can we send to CORE before we exhaust
@@ -2461,7 +2461,7 @@ struct ValidationState
2461 * if we never used data from the previous window or are establishing the 2461 * if we never used data from the previous window or are establishing the
2462 * connection for the first time). 2462 * connection for the first time).
2463 */ 2463 */
2464 uint32_t last_window_consum_limit_kb; 2464 uint32_t last_window_consum_limit;
2465 2465
2466 /** 2466 /**
2467 * We are technically ready to send the challenge, but we are waiting for 2467 * We are technically ready to send the challenge, but we are waiting for
@@ -5828,7 +5828,7 @@ activate_core_visible_dv_path (struct DistanceVectorHop *hop)
5828 vl->dv = dv; 5828 vl->dv = dv;
5829 dv->vl = vl; 5829 dv->vl = vl;
5830 vl->core_recv_window = RECV_WINDOW_SIZE; 5830 vl->core_recv_window = RECV_WINDOW_SIZE;
5831 vl->available_fc_window_size_kb = DEFAULT_WINDOW_SIZE_KB; 5831 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
5832 vl->visibility_task = 5832 vl->visibility_task =
5833 GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); 5833 GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl);
5834 GNUNET_break (GNUNET_YES == 5834 GNUNET_break (GNUNET_YES ==
@@ -7199,42 +7199,39 @@ check_incoming_msg (void *cls,
7199 * @param vl virtual link 7199 * @param vl virtual link
7200 * @param challenge the challenge we received 7200 * @param challenge the challenge we received
7201 * @param sender_time when did the peer send the message? 7201 * @param sender_time when did the peer send the message?
7202 * @param last_window_consum_limit_kb maximum number of kb the sender 7202 * @param last_window_consum_limit maximum number of kb the sender
7203 * promises to use of the previous window (if any) 7203 * promises to use of the previous window (if any)
7204 */ 7204 */
7205static void 7205static void
7206update_fc_window (struct VirtualLink *vl, 7206update_fc_window (struct VirtualLink *vl,
7207 const struct ChallengeNonceP *challenge, 7207 const struct ChallengeNonceP *challenge,
7208 struct GNUNET_TIME_Absolute sender_time, 7208 struct GNUNET_TIME_Absolute sender_time,
7209 uint32_t last_window_consum_limit_kb) 7209 uint32_t last_window_consum_limit)
7210{ 7210{
7211 if (0 == GNUNET_memcmp (challenge, &vl->n_challenge)) 7211 if (0 == GNUNET_memcmp (challenge, &vl->n_challenge))
7212 { 7212 {
7213 uint32_t avail; 7213 uint32_t avail;
7214 7214
7215 /* Challenge identical to last one, update 7215 /* Challenge identical to last one, update
7216 @a last_window_consum_limit_kb (to minimum) */ 7216 @a last_window_consum_limit (to minimum) */
7217 vl->last_fc_window_size_remaining_kb = 7217 vl->last_fc_window_size_remaining =
7218 GNUNET_MIN (last_window_consum_limit_kb, 7218 GNUNET_MIN (last_window_consum_limit, vl->last_fc_window_size_remaining);
7219 vl->last_fc_window_size_remaining_kb);
7220 /* window could have shrunk! */ 7219 /* window could have shrunk! */
7221 if (vl->available_fc_window_size_kb > vl->last_fc_window_size_remaining_kb) 7220 if (vl->available_fc_window_size > vl->last_fc_window_size_remaining)
7222 avail = 7221 avail = vl->available_fc_window_size - vl->last_fc_window_size_remaining;
7223 vl->available_fc_window_size_kb - vl->last_fc_window_size_remaining_kb;
7224 else 7222 else
7225 avail = 0; 7223 avail = 0;
7226 /* guard against integer overflow */ 7224 /* guard against integer overflow */
7227 if (vl->incoming_fc_window_size_used_kb + avail >= 7225 if (vl->incoming_fc_window_size_used + avail >=
7228 vl->incoming_fc_window_size_used_kb) 7226 vl->incoming_fc_window_size_used)
7229 vl->incoming_fc_window_size_kb = 7227 vl->incoming_fc_window_size = vl->incoming_fc_window_size_used + avail;
7230 vl->incoming_fc_window_size_used_kb + avail;
7231 else 7228 else
7232 vl->incoming_fc_window_size_kb = UINT32_MAX; 7229 vl->incoming_fc_window_size = UINT32_MAX;
7233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7234 "Updated window to %u/%u kb (%u used) for virtual link to %s!\n", 7231 "Updated window to %u/%u kb (%u used) for virtual link to %s!\n",
7235 vl->incoming_fc_window_size_kb, 7232 vl->incoming_fc_window_size,
7236 vl->available_fc_window_size_kb, 7233 vl->available_fc_window_size,
7237 vl->incoming_fc_window_size_used_kb, 7234 vl->incoming_fc_window_size_used,
7238 GNUNET_i2s (&vl->target)); 7235 GNUNET_i2s (&vl->target));
7239 return; 7236 return;
7240 } 7237 }
@@ -7247,31 +7244,31 @@ update_fc_window (struct VirtualLink *vl,
7247 return; 7244 return;
7248 } 7245 }
7249 /* new challenge! */ 7246 /* new challenge! */
7250 if (vl->incoming_fc_window_size_used_kb > last_window_consum_limit_kb) 7247 if (vl->incoming_fc_window_size_used > last_window_consum_limit)
7251 { 7248 {
7252 /* lying peer: it already used more than it promised it would ever use! */ 7249 /* lying peer: it already used more than it promised it would ever use! */
7253 GNUNET_break_op (0); 7250 GNUNET_break_op (0);
7254 last_window_consum_limit_kb = vl->incoming_fc_window_size_used_kb; 7251 last_window_consum_limit = vl->incoming_fc_window_size_used;
7255 } 7252 }
7256 /* What remains is at most the difference between what we already processed 7253 /* What remains is at most the difference between what we already processed
7257 and what the sender promises to limit itself to. */ 7254 and what the sender promises to limit itself to. */
7258 vl->last_fc_window_size_remaining_kb = 7255 vl->last_fc_window_size_remaining =
7259 last_window_consum_limit_kb - vl->incoming_fc_window_size_used_kb; 7256 last_window_consum_limit - vl->incoming_fc_window_size_used;
7260 vl->n_challenge = *challenge; 7257 vl->n_challenge = *challenge;
7261 vl->n_challenge_time = sender_time; 7258 vl->n_challenge_time = sender_time;
7262 vl->incoming_fc_window_size_used_kb = 0; 7259 vl->incoming_fc_window_size_used = 0;
7263 /* window could have shrunk! */ 7260 /* window could have shrunk! */
7264 if (vl->available_fc_window_size_kb > vl->last_fc_window_size_remaining_kb) 7261 if (vl->available_fc_window_size > vl->last_fc_window_size_remaining)
7265 vl->incoming_fc_window_size_kb = 7262 vl->incoming_fc_window_size =
7266 vl->available_fc_window_size_kb - vl->last_fc_window_size_remaining_kb; 7263 vl->available_fc_window_size - vl->last_fc_window_size_remaining;
7267 else 7264 else
7268 vl->incoming_fc_window_size_kb = 0; 7265 vl->incoming_fc_window_size = 0;
7269 GNUNET_log ( 7266 GNUNET_log (
7270 GNUNET_ERROR_TYPE_DEBUG, 7267 GNUNET_ERROR_TYPE_DEBUG,
7271 "New window at %u/%u kb (%u left on previous) for virtual link to %s!\n", 7268 "New window at %u/%u kb (%u left on previous) for virtual link to %s!\n",
7272 vl->incoming_fc_window_size_kb, 7269 vl->incoming_fc_window_size,
7273 vl->available_fc_window_size_kb, 7270 vl->available_fc_window_size,
7274 vl->last_fc_window_size_remaining_kb, 7271 vl->last_fc_window_size_remaining,
7275 GNUNET_i2s (&vl->target)); 7272 GNUNET_i2s (&vl->target));
7276} 7273}
7277 7274
@@ -7495,12 +7492,11 @@ handle_validation_challenge (
7495 update_fc_window (vl, 7492 update_fc_window (vl,
7496 &tvc->challenge, 7493 &tvc->challenge,
7497 GNUNET_TIME_absolute_ntoh (tvc->sender_time), 7494 GNUNET_TIME_absolute_ntoh (tvc->sender_time),
7498 ntohl (tvc->last_window_consum_limit_kb)); 7495 ntohl (tvc->last_window_consum_limit));
7499 tvr.header.type = 7496 tvr.header.type =
7500 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 7497 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
7501 tvr.header.size = htons (sizeof (tvr)); 7498 tvr.header.size = htons (sizeof (tvr));
7502 tvr.fc_window_size_kb = 7499 tvr.fc_window_size = htonl ((NULL == vl) ? 0 : vl->incoming_fc_window_size);
7503 htonl ((NULL == vl) ? 0 : vl->incoming_fc_window_size_kb);
7504 tvr.challenge = tvc->challenge; 7500 tvr.challenge = tvc->challenge;
7505 tvr.origin_time = tvc->sender_time; 7501 tvr.origin_time = tvc->sender_time;
7506 tvr.validity_duration = validity_duration; 7502 tvr.validity_duration = validity_duration;
@@ -7786,7 +7782,7 @@ handle_validation_response (
7786 if (0 == GNUNET_memcmp (&vl->my_challenge, &tvr->challenge)) 7782 if (0 == GNUNET_memcmp (&vl->my_challenge, &tvr->challenge))
7787 { 7783 {
7788 /* Update window size if the challenge matches */ 7784 /* Update window size if the challenge matches */
7789 vl->outbound_fc_window_size_kb = ntohl (tvr->fc_window_size_kb); 7785 vl->outbound_fc_window_size = ntohl (tvr->fc_window_size);
7790 } 7786 }
7791 return; 7787 return;
7792 } 7788 }
@@ -7798,8 +7794,8 @@ handle_validation_response (
7798 vl->n = n; 7794 vl->n = n;
7799 n->vl = vl; 7795 n->vl = vl;
7800 vl->core_recv_window = RECV_WINDOW_SIZE; 7796 vl->core_recv_window = RECV_WINDOW_SIZE;
7801 vl->available_fc_window_size_kb = DEFAULT_WINDOW_SIZE_KB; 7797 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
7802 vl->outbound_fc_window_size_kb = ntohl (tvr->fc_window_size_kb); 7798 vl->outbound_fc_window_size = ntohl (tvr->fc_window_size);
7803 vl->my_challenge = tvr->challenge; 7799 vl->my_challenge = tvr->challenge;
7804 vl->visibility_task = 7800 vl->visibility_task =
7805 GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); 7801 GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl);
@@ -8797,7 +8793,7 @@ validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
8797 tvc.header.type = 8793 tvc.header.type =
8798 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 8794 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
8799 tvc.header.size = htons (sizeof (tvc)); 8795 tvc.header.size = htons (sizeof (tvc));
8800 tvc.last_window_consum_limit_kb = htonl (vs->last_window_consum_limit_kb); 8796 tvc.last_window_consum_limit = htonl (vs->last_window_consum_limit);
8801 tvc.challenge = vs->challenge; 8797 tvc.challenge = vs->challenge;
8802 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); 8798 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use);
8803 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 8799 GNUNET_log (GNUNET_ERROR_TYPE_INFO,