Skip to content

Commit

Permalink
Require MTU size to be at least 400 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed May 2, 2019
1 parent 9df7dbc commit fc1ccc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/server/OfflineMessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use raklib\protocol\UnconnectedPing;
use raklib\protocol\UnconnectedPong;
use raklib\utils\InternetAddress;
use function abs;
use function min;

class OfflineMessageHandler{
Expand Down Expand Up @@ -67,7 +66,11 @@ public function handle(OfflineMessage $packet, InternetAddress $address) : bool{
/** @var OpenConnectionRequest2 $packet */

if($packet->serverAddress->port === $this->sessionManager->getPort() or !$this->sessionManager->portChecking){
$mtuSize = min(abs($packet->mtuSize), $this->sessionManager->getMaxMtuSize()); //Max size, do not allow creating large buffers to fill server memory
if($packet->mtuSize < Session::MIN_MTU_SIZE){
$this->sessionManager->getLogger()->debug("Not creating session for $address due to bad MTU size $packet->mtuSize");
return true;
}
$mtuSize = min($packet->mtuSize, $this->sessionManager->getMaxMtuSize()); //Max size, do not allow creating large buffers to fill server memory
$pk = new OpenConnectionReply2();
$pk->mtuSize = $mtuSize;
$pk->serverID = $this->sessionManager->getID();
Expand Down
5 changes: 5 additions & 0 deletions src/server/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Session{
public const STATE_DISCONNECTING = 2;
public const STATE_DISCONNECTED = 3;

public const MIN_MTU_SIZE = 400;

private const MAX_SPLIT_SIZE = 128;
private const MAX_SPLIT_COUNT = 4;

Expand Down Expand Up @@ -136,6 +138,9 @@ class Session{
private $lastPingMeasure = 1;

public function __construct(SessionManager $sessionManager, InternetAddress $address, int $clientId, int $mtuSize){
if($mtuSize < self::MIN_MTU_SIZE){
throw new \InvalidArgumentException("MTU size must be at least " . self::MIN_MTU_SIZE . ", got $mtuSize");
}
$this->sessionManager = $sessionManager;
$this->address = $address;
$this->id = $clientId;
Expand Down

0 comments on commit fc1ccc8

Please sign in to comment.