Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Mar 7, 2024
1 parent 6922c29 commit 08ae740
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions ProxyServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@
use function getenv;
use function ord;
use function socket_read;
use function spl_object_id;
use function strlen;
use function substr;
use function zstd_uncompress;

class ProxyServer
{
public const PING_SYNC_INTERVAL = 2;

/** @var PthreadsChannelReader */
private PthreadsChannelReader $mainToThreadReader;
/** @var SnoozeAwarePthreadsChannelWriter */
Expand All @@ -68,10 +65,6 @@ class ProxyServer

/** @var array<int, QueueWriter> */
private array $streamWriters = [];
/** @var array<int, int> */
private array $connectionIdByStreamId = [];
/** @var array<int, QuicheConnection> */
private array $connections = [];
/** @var array<int, BiDirectionalQuicheStream> */
private array $streams = [];

Expand Down Expand Up @@ -113,7 +106,6 @@ private function createServerSocket(SocketAddress $socketAddress, Socket $notify
$peerAddress = $connection->getPeerAddress();

$this->streamWriters[$streamIdentifier] = $stream->setupWriter();
$this->connectionIdByStreamId[$streamIdentifier] = spl_object_id($connection);
$this->streams[$streamIdentifier] = $stream;

$pk = new LoginPacket();
Expand All @@ -132,16 +124,10 @@ private function createServerSocket(SocketAddress $socketAddress, Socket $notify
});

$stream->setOnDataArrival(function (string $data) use ($streamIdentifier): void {
$this->onDataReceive($streamIdentifier, $data);
});
} else if ($stream === null) {
$this->connections[$connectionId = spl_object_id($connection)] = $connection;

$connection->setPeerCloseCallback(function () use ($connectionId): void {
unset($this->connections[$connectionId]);
if (isset($this->streams[$streamIdentifier])) {
$this->onDataReceive($streamIdentifier, $data);
}
});
} else {
throw new \RuntimeException('Invalid stream type');
}
});

Expand Down Expand Up @@ -182,7 +168,6 @@ private function onStreamShutdown(int $streamIdentifier): void
{
unset(
$this->streamWriters[$streamIdentifier],
$this->connectionIdByStreamId[$streamIdentifier],
$this->streams[$streamIdentifier],
$this->gamePacketLimiter[$streamIdentifier],
$this->batchPacketLimiter[$streamIdentifier],
Expand Down Expand Up @@ -220,9 +205,6 @@ private function shutdownStream(int $streamIdentifier, string $reason, bool $fro
}

if (($stream = $this->streams[$streamIdentifier] ?? null) !== null) {
if ($stream->isReadable()) {
$stream->shutdownReading();
}
if ($stream->isWritable()) {
$stream->gracefulShutdownWriting();
}
Expand Down

0 comments on commit 08ae740

Please sign in to comment.