diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-17 12:54:23 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-06-17 12:54:23 +0000 |
commit | 7199d671c2a1003f5d96a25cd91530ab519f200b (patch) | |
tree | 23d99cf7a83592f7fb707b90032c52aa1284b39f /src/stream/stream_api.c | |
parent | 685d9d7c3791b897cf7b0ec1366a062b26f05a21 (diff) | |
download | gnunet-7199d671c2a1003f5d96a25cd91530ab519f200b.tar.gz gnunet-7199d671c2a1003f5d96a25cd91530ab519f200b.zip |
-testcase for sequence wrap around effect and sequence handling fixes in ack handling
Diffstat (limited to 'src/stream/stream_api.c')
-rw-r--r-- | src/stream/stream_api.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 8c25965f1..214ac4e41 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -1384,10 +1384,14 @@ generate_hello_ack_msg (struct GNUNET_STREAM_Socket *socket) | |||
1384 | struct GNUNET_STREAM_HelloAckMessage *msg; | 1384 | struct GNUNET_STREAM_HelloAckMessage *msg; |
1385 | 1385 | ||
1386 | /* Get the random sequence number */ | 1386 | /* Get the random sequence number */ |
1387 | socket->write_sequence_number = | 1387 | if (GNUNET_YES == socket->testing_active) |
1388 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 1388 | socket->write_sequence_number = |
1389 | socket->testing_set_write_sequence_number_value; | ||
1390 | else | ||
1391 | socket->write_sequence_number = | ||
1392 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | ||
1389 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1393 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1390 | "%s: Generated write sequence number %u\n", | 1394 | "%s: write sequence number %u\n", |
1391 | GNUNET_i2s (&socket->other_peer), | 1395 | GNUNET_i2s (&socket->other_peer), |
1392 | (unsigned int) socket->write_sequence_number); | 1396 | (unsigned int) socket->write_sequence_number); |
1393 | 1397 | ||
@@ -2356,8 +2360,8 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2356 | { | 2360 | { |
2357 | unsigned int packet; | 2361 | unsigned int packet; |
2358 | int need_retransmission; | 2362 | int need_retransmission; |
2363 | uint32_t sequence_difference; | ||
2359 | 2364 | ||
2360 | |||
2361 | if (0 != memcmp (sender, | 2365 | if (0 != memcmp (sender, |
2362 | &socket->other_peer, | 2366 | &socket->other_peer, |
2363 | sizeof (struct GNUNET_PeerIdentity))) | 2367 | sizeof (struct GNUNET_PeerIdentity))) |
@@ -2367,7 +2371,6 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2367 | GNUNET_i2s (&socket->other_peer)); | 2371 | GNUNET_i2s (&socket->other_peer)); |
2368 | return GNUNET_YES; | 2372 | return GNUNET_YES; |
2369 | } | 2373 | } |
2370 | |||
2371 | switch (socket->state) | 2374 | switch (socket->state) |
2372 | { | 2375 | { |
2373 | case (STATE_ESTABLISHED): | 2376 | case (STATE_ESTABLISHED): |
@@ -2397,7 +2400,6 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2397 | } | 2400 | } |
2398 | /* FIXME: include the case when write_handle is cancelled - ignore the | 2401 | /* FIXME: include the case when write_handle is cancelled - ignore the |
2399 | acks */ | 2402 | acks */ |
2400 | |||
2401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2403 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2402 | "%s: Received DATA_ACK from %s\n", | 2404 | "%s: Received DATA_ACK from %s\n", |
2403 | GNUNET_i2s (&socket->other_peer), | 2405 | GNUNET_i2s (&socket->other_peer), |
@@ -2410,31 +2412,34 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2410 | socket->retransmission_timeout_task_id = | 2412 | socket->retransmission_timeout_task_id = |
2411 | GNUNET_SCHEDULER_NO_TASK; | 2413 | GNUNET_SCHEDULER_NO_TASK; |
2412 | } | 2414 | } |
2413 | |||
2414 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) | 2415 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) |
2415 | { | 2416 | { |
2416 | if (NULL == socket->write_handle->messages[packet]) break; | 2417 | if (NULL == socket->write_handle->messages[packet]) break; |
2417 | if (ntohl (ack->base_sequence_number) | 2418 | /* BS: Base sequence from ack; PS: sequence num of current packet */ |
2418 | >= ntohl (socket->write_handle->messages[packet]->sequence_number)) | 2419 | sequence_difference = ntohl (ack->base_sequence_number) |
2419 | ackbitmap_modify_bit (&socket->write_handle->ack_bitmap, | 2420 | - ntohl (socket->write_handle->messages[packet]->sequence_number); |
2420 | packet, | 2421 | /* case where BS = PS + GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH */ |
2422 | if ((sequence_difference == GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) | ||
2423 | || ((sequence_difference < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) | ||
2424 | && (0 != sequence_difference))) /* case: BS > PS and BS != PS*/ | ||
2425 | { | ||
2426 | ackbitmap_modify_bit (&socket->write_handle->ack_bitmap, packet, | ||
2421 | GNUNET_YES); | 2427 | GNUNET_YES); |
2422 | else | 2428 | continue; |
2423 | if (GNUNET_YES == | 2429 | } |
2424 | ackbitmap_is_bit_set (&socket->write_handle->ack_bitmap, | 2430 | if (GNUNET_YES == |
2425 | ntohl (socket->write_handle->messages[packet]->sequence_number) | 2431 | ackbitmap_is_bit_set (&socket->write_handle->ack_bitmap, |
2426 | - ntohl (ack->base_sequence_number))) | 2432 | -sequence_difference))/*inversion as PS >= BS */ |
2427 | ackbitmap_modify_bit (&socket->write_handle->ack_bitmap, | 2433 | { |
2428 | packet, | 2434 | ackbitmap_modify_bit (&socket->write_handle->ack_bitmap, packet, |
2429 | GNUNET_YES); | 2435 | GNUNET_YES); |
2436 | } | ||
2430 | } | 2437 | } |
2431 | |||
2432 | /* Update the receive window remaining | 2438 | /* Update the receive window remaining |
2433 | FIXME : Should update with the value from a data ack with greater | 2439 | FIXME : Should update with the value from a data ack with greater |
2434 | sequence number */ | 2440 | sequence number */ |
2435 | socket->receiver_window_available = | 2441 | socket->receiver_window_available = |
2436 | ntohl (ack->receive_window_remaining); | 2442 | ntohl (ack->receive_window_remaining); |
2437 | |||
2438 | /* Check if we have received all acknowledgements */ | 2443 | /* Check if we have received all acknowledgements */ |
2439 | need_retransmission = GNUNET_NO; | 2444 | need_retransmission = GNUNET_NO; |
2440 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) | 2445 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) |