Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 8511a74

Browse files
authored
Fix MTU detection (Fix #303) (#304)
1 parent e8d15db commit 8511a74

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/src/senkusha.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static ChiakiErrorCode senkusha_run_mtu_in_test(ChiakiSenkusha *senkusha, uint32
363363

364364
uint32_t cur = max;
365365
uint32_t request_id = 0;
366-
while(max > min)
366+
while((max - min) > 1)
367367
{
368368
bool success = false;
369369
for(uint32_t attempt=0; attempt<retries; attempt++)
@@ -410,14 +410,14 @@ static ChiakiErrorCode senkusha_run_mtu_in_test(ChiakiSenkusha *senkusha, uint32
410410
}
411411

412412
if(success)
413-
min = cur + 1;
413+
min = cur;
414414
else
415-
max = cur - 1;
415+
max = cur;
416416
cur = min + (max - min) / 2;
417417
}
418418

419-
CHIAKI_LOGI(senkusha->log, "Senkusha determined inbound MTU %u", (unsigned int)max);
420-
*mtu = max;
419+
CHIAKI_LOGI(senkusha->log, "Senkusha determined inbound MTU %u", (unsigned int)min);
420+
*mtu = min;
421421

422422
return CHIAKI_ERR_SUCCESS;
423423
}
@@ -481,7 +481,7 @@ static ChiakiErrorCode senkusha_run_mtu_out_test(ChiakiSenkusha *senkusha, uint3
481481
err = CHIAKI_ERR_SUCCESS;
482482

483483
uint32_t cur = mtu_in;
484-
while(max > min)
484+
while((max - min) > 1)
485485
{
486486
bool success = false;
487487
for(uint32_t attempt=0; attempt<retries; attempt++)
@@ -520,10 +520,13 @@ static ChiakiErrorCode senkusha_run_mtu_out_test(ChiakiSenkusha *senkusha, uint3
520520
if(err != CHIAKI_ERR_SUCCESS)
521521
{
522522
CHIAKI_LOGE(senkusha->log, "Senkusha failed to send ping");
523-
goto beach;
523+
err = CHIAKI_ERR_TIMEOUT;
524+
}
525+
else
526+
{
527+
err = chiaki_cond_timedwait_pred(&senkusha->state_cond, &senkusha->state_mutex, timeout_ms, state_finished_cond_check, senkusha);
524528
}
525529

526-
err = chiaki_cond_timedwait_pred(&senkusha->state_cond, &senkusha->state_mutex, timeout_ms, state_finished_cond_check, senkusha);
527530
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
528531

529532
if(!senkusha->state_finished)
@@ -549,14 +552,14 @@ static ChiakiErrorCode senkusha_run_mtu_out_test(ChiakiSenkusha *senkusha, uint3
549552
}
550553

551554
if(success)
552-
min = cur + 1;
555+
min = cur;
553556
else
554-
max = cur - 1;
557+
max = cur;
555558
cur = min + (max - min) / 2;
556559
}
557560

558-
CHIAKI_LOGI(senkusha->log, "Senkusha determined outbound MTU %u", (unsigned int)max);
559-
*mtu = max;
561+
CHIAKI_LOGI(senkusha->log, "Senkusha determined outbound MTU %u", (unsigned int)min);
562+
*mtu = min;
560563

561564
CHIAKI_LOGI(senkusha->log, "Senkusha sending final Client MTU Command");
562565
client_mtu_cmd.id = 2;

0 commit comments

Comments
 (0)