Skip to content

Commit

Permalink
Merge pull request #13 from Cube-Solutions/master
Browse files Browse the repository at this point in the history
Handle case when session is null on receiving a message
  • Loading branch information
mbonneau authored Jun 2, 2022
2 parents 096d401 + 85ca1ca commit 9547ecd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Thruway;

use React\EventLoop\LoopInterface;
use React\Socket\ConnectorInterface;
use Thruway\Message\AuthenticateMessage;
use Thruway\Message\ChallengeMessage;
use Thruway\Peer\Client;
Expand Down Expand Up @@ -46,12 +47,12 @@ class Connection implements EventEmitterInterface
* @param \React\EventLoop\LoopInterface $loop
* @throws \Exception
*/
public function __construct(Array $options, LoopInterface $loop = null)
public function __construct(Array $options, LoopInterface $loop = null, ConnectorInterface $connector = null)
{
$this->options = $options;
$this->client = new Client($options['realm'], $loop);
$url = isset($options['url']) ? $options['url'] : null;
$pawlTransport = new PawlTransportProvider($url);
$pawlTransport = new PawlTransportProvider($url, $connector);

$this->client->addTransportProvider($pawlTransport);
$this->client->setReconnectOptions($options);
Expand Down
5 changes: 5 additions & 0 deletions src/Peer/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public function onMessage(TransportInterface $transport, Message $msg)

$session = $this->session;

if($session === null) {
Logger::warning($this, "Message discarded, no session: {$msg}");
return;
}

if ($msg instanceof WelcomeMessage):
$this->processWelcome($session, $msg);
elseif ($msg instanceof AbortMessage):
Expand Down

0 comments on commit 9547ecd

Please sign in to comment.