Skip to content

Commit 669eb4d

Browse files
committed
ReceiveReliabilityLayer: avoid impure calls resetting types
1 parent 6d6e63f commit 669eb4d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/generic/ReceiveReliabilityLayer.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,30 @@ private function handleEncapsulatedPacket(EncapsulatedPacket $packet) : void{
185185
$this->receiveSequencedHighestIndex[$packet->orderChannel] = $packet->sequenceIndex + 1;
186186
$this->handleEncapsulatedPacketRoute($packet);
187187
}elseif(PacketReliability::isOrdered($packet->reliability)){
188-
assert($packet->orderChannel !== null, 'This should have been set during decode');
189-
if($packet->orderIndex === $this->receiveOrderedIndex[$packet->orderChannel]){
188+
$orderChannel = $packet->orderChannel;
189+
assert($orderChannel !== null, 'This should have been set during decode');
190+
if($packet->orderIndex === $this->receiveOrderedIndex[$orderChannel]){
190191
//this is the packet we expected to get next
191192
//Any ordered packet resets the sequence index to zero, so that sequenced packets older than this ordered
192193
//one get discarded. Sequenced packets also include (but don't increment) the order index, so a sequenced
193194
//packet with an order index less than this will get discarded
194-
$this->receiveSequencedHighestIndex[$packet->orderChannel] = 0;
195-
$this->receiveOrderedIndex[$packet->orderChannel] = $packet->orderIndex + 1;
195+
$this->receiveSequencedHighestIndex[$orderChannel] = 0;
196+
$this->receiveOrderedIndex[$orderChannel] = $packet->orderIndex + 1;
196197

197198
$this->handleEncapsulatedPacketRoute($packet);
198-
$i = $this->receiveOrderedIndex[$packet->orderChannel];
199-
for(; isset($this->receiveOrderedPackets[$packet->orderChannel][$i]); ++$i){
200-
$this->handleEncapsulatedPacketRoute($this->receiveOrderedPackets[$packet->orderChannel][$i]);
201-
unset($this->receiveOrderedPackets[$packet->orderChannel][$i]);
199+
$i = $this->receiveOrderedIndex[$orderChannel];
200+
for(; isset($this->receiveOrderedPackets[$orderChannel][$i]); ++$i){
201+
$this->handleEncapsulatedPacketRoute($this->receiveOrderedPackets[$orderChannel][$i]);
202+
unset($this->receiveOrderedPackets[$orderChannel][$i]);
202203
}
203204

204-
$this->receiveOrderedIndex[$packet->orderChannel] = $i;
205-
}elseif($packet->orderIndex > $this->receiveOrderedIndex[$packet->orderChannel]){
206-
if(count($this->receiveOrderedPackets[$packet->orderChannel]) >= self::$WINDOW_SIZE){
205+
$this->receiveOrderedIndex[$orderChannel] = $i;
206+
}elseif($packet->orderIndex > $this->receiveOrderedIndex[$orderChannel]){
207+
if(count($this->receiveOrderedPackets[$orderChannel]) >= self::$WINDOW_SIZE){
207208
//queue overflow for this channel - we should probably disconnect the peer at this point
208209
return;
209210
}
210-
$this->receiveOrderedPackets[$packet->orderChannel][$packet->orderIndex] = $packet;
211+
$this->receiveOrderedPackets[$orderChannel][$packet->orderIndex] = $packet;
211212
}else{
212213
//duplicate/already received packet
213214
}

0 commit comments

Comments
 (0)