Skip to content

Commit be2783b

Browse files
committed
SendReliabilityLayer: make retransmit timeout less insane
this hardcoded timeout really needs to be replaced by a calculation based on RTT, but that's a job for another time.
1 parent ebd8b6c commit be2783b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/generic/SendReliabilityLayer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@
2626
use function array_push;
2727
use function assert;
2828
use function count;
29+
use function microtime;
2930
use function str_split;
3031
use function strlen;
31-
use function time;
3232

3333
final class SendReliabilityLayer{
3434
private const DATAGRAM_MTU_OVERHEAD = 36 + Datagram::HEADER_SIZE; //IP header (20 bytes) + UDP header (8 bytes) + RakNet weird (8 bytes) = 36
3535
private const MIN_POSSIBLE_PACKET_SIZE_LIMIT = Session::MIN_MTU_SIZE - self::DATAGRAM_MTU_OVERHEAD;
36+
/**
37+
* Delay in seconds before an unacked packet is retransmitted.
38+
* TODO: Replace this with dynamic calculation based on roundtrip times (that's a complex task for another time)
39+
*/
40+
private const UNACKED_RETRANSMIT_DELAY = 2.0;
3641

3742
/** @var EncapsulatedPacket[] */
3843
private array $sendQueue = [];
@@ -255,8 +260,9 @@ public function needsUpdate() : bool{
255260
}
256261

257262
public function update() : void{
263+
$retransmitOlderThan = microtime(true) - self::UNACKED_RETRANSMIT_DELAY;
258264
foreach($this->reliableCache as $seq => $pk){
259-
if($pk->getTimestamp() < (time() - 8)){
265+
if($pk->getTimestamp() < $retransmitOlderThan){
260266
//behave as if a NACK was received
261267
array_push($this->resendQueue, ...$pk->getPackets());
262268
unset($this->reliableCache[$seq]);

0 commit comments

Comments
 (0)