PrepareEncryptionTask: remove cyclic dependency on NetworkSession

This commit is contained in:
Dylan K. Taylor
2020-04-18 11:25:29 +01:00
parent e86c243db5
commit 3d3a487422
2 changed files with 29 additions and 20 deletions

View File

@@ -530,25 +530,23 @@ class NetworkSession{
if($this->manager->kickDuplicates($this)){
if(NetworkCipher::$ENABLED){
$this->server->getAsyncPool()->submitTask(new PrepareEncryptionTask($this, $clientPubKey));
$this->server->getAsyncPool()->submitTask(new PrepareEncryptionTask($clientPubKey, function(string $encryptionKey, string $handshakeJwt) : void{
if(!$this->connected){
return;
}
$this->sendDataPacket(ServerToClientHandshakePacket::create($handshakeJwt), true); //make sure this gets sent before encryption is enabled
$this->cipher = new NetworkCipher($encryptionKey);
$this->setHandler(new HandshakePacketHandler($this));
$this->logger->debug("Enabled encryption");
}));
}else{
$this->onLoginSuccess();
}
}
}
public function enableEncryption(string $encryptionKey, string $handshakeJwt) : void{
if(!$this->connected){
return;
}
$this->sendDataPacket(ServerToClientHandshakePacket::create($handshakeJwt), true); //make sure this gets sent before encryption is enabled
$this->cipher = new NetworkCipher($encryptionKey);
$this->setHandler(new HandshakePacketHandler($this));
$this->logger->debug("Enabled encryption");
}
public function onLoginSuccess() : void{
$this->loggedIn = true;