Refactored EPP for high load

This commit is contained in:
Pinga 2023-12-02 12:31:10 +02:00
parent eebf61ca56
commit 54c84943a0
2 changed files with 425 additions and 401 deletions

View file

@ -1,6 +1,6 @@
<?php
require_once '../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
@ -135,21 +135,21 @@ function generateSvTRID() {
return $svTRID;
}
function getRegistrarClid(PDO $db, $id) {
function getRegistrarClid(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT clid FROM registrar WHERE id = :id");
$stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['clid'] ?? null; // Return the clid if found, otherwise return null
}
function getContactIdentifier(PDO $db, $id) {
function getContactIdentifier(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT identifier FROM contact WHERE id = :id");
$stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
return $result['identifier'] ?? null; // Return the identifier if found, otherwise return null
}
function getHost(PDO $db, $id) {
function getHost(Swoole\Database\PDOProxy $db, $id) {
$stmt = $db->prepare("SELECT name FROM host WHERE id = :id");
$stmt->execute([':id' => $id]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
@ -320,7 +320,7 @@ function updateTransaction($db, $cmd, $obj_type, $obj_id, $code, $msg, $svTRID,
return true;
}
function getClid(PDO $db, string $clid): ?int {
function getClid(Swoole\Database\PDOProxy $db, string $clid): ?int {
$stmt = $db->prepare("SELECT id FROM registrar WHERE clid = :clid LIMIT 1");
$stmt->bindParam(':clid', $clid, PDO::PARAM_STR);
$stmt->execute();

View file

@ -25,9 +25,17 @@ $table->column('clid', Table::TYPE_STRING, 64);
$table->column('logged_in', Table::TYPE_INT, 1);
$table->create();
$dsn = "{$c['db_type']}:host={$c['db_host']};dbname={$c['db_database']};port={$c['db_port']}";
$db = new PDO($dsn, $c['db_username'], $c['db_password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Initialize the PDO connection pool
$pool = new Swoole\Database\PDOPool(
(new Swoole\Database\PDOConfig())
->withDriver($c['db_type'])
->withHost($c['db_host'])
->withPort($c['db_port'])
->withDbName($c['db_database'])
->withUsername($c['db_username'])
->withPassword($c['db_password'])
->withCharset('utf8mb4')
);
Swoole\Runtime::enableCoroutine();
$server = new Server($c['epp_host'], $c['epp_port']);
@ -51,18 +59,21 @@ $server->set([
'ssl_protocols' => SWOOLE_SSL_TLSv1_2 | SWOOLE_SSL_TLSv1_3,
'ssl_ciphers' => 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES256-GCM-SHA384',
]);
$log->info('server started.');
$log->info('Namingo EPP server started');
$server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$server->handle(function (Connection $conn) use ($table, $pool, $c, $log) {
$log->info('new client connected');
sendGreeting($conn);
while (true) {
try {
// Get a PDO connection from the pool
$pdo = $pool->get();
$data = $conn->recv();
$connId = spl_object_id($conn);
if ($data === false || strlen($data) < 4) {
sendEppError($conn, $db, 2100, 'Data reception error');
sendEppError($conn, $pdo, 2000, 'Data reception error');
break;
}
@ -83,7 +94,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$xml->registerXPathNamespace('secDNS', 'urn:ietf:params:xml:ns:secDNS-1.1');
if ($xml === false) {
sendEppError($conn, $db, 2001, 'Invalid XML');
sendEppError($conn, $pdo, 2001, 'Invalid XML');
break;
}
@ -97,11 +108,11 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$clID = (string) $xml->command->login->clID;
$pw = (string) $xml->command->login->pw;
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $clID);
$clid = getClid($pdo, $clID);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (checkLogin($db, $clID, $pw)) {
if (checkLogin($pdo, $clID, $pw)) {
if (isset($xml->command->login->newPW)) {
$newPW = (string) $xml->command->login->newPW;
$options = [
@ -111,12 +122,12 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
];
$hashedPassword = password_hash($newPW, PASSWORD_ARGON2ID, $options);
try {
$stmt = $db->prepare("UPDATE registrar SET pw = :newPW WHERE clid = :clID");
$stmt = $pdo->prepare("UPDATE registrar SET pw = :newPW WHERE clid = :clID");
$stmt->bindParam(':newPW', $hashedPassword);
$stmt->bindParam(':clID', $clID);
$stmt->execute();
} catch (PDOException $e) {
sendEppError($conn, $db, 2400, 'Password could not be changed', $clTRID);
sendEppError($conn, $pdo, 2400, 'Password could not be changed', $clTRID);
}
$svTRID = generateSvTRID();
@ -131,7 +142,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
updateTransaction($db, 'login', null, null, 1000, 'Password changed successfully. Session will be terminated', $svTRID, $xml, $trans);
updateTransaction($pdo, 'login', null, null, 1000, 'Password changed successfully. Session will be terminated', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml);
$conn->close();
break;
@ -149,10 +160,10 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
updateTransaction($db, 'login', null, null, 1000, 'Command completed successfully', $svTRID, $xml, $trans);
updateTransaction($pdo, 'login', null, null, 1000, 'Command completed successfully', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml);
} else {
sendEppError($conn, $db, 2200, 'Authentication error', $clTRID);
sendEppError($conn, $pdo, 2200, 'Authentication error', $clTRID);
}
break;
}
@ -160,11 +171,11 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
case isset($xml->command->logout):
{
$data = $table->get($connId);
$clid = getClid($db, $clID);
$clid = getClid($pdo, $clID);
$table->del($connId);
$clTRID = (string) $xml->command->clTRID;
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
$svTRID = generateSvTRID();
$response = [
'command' => 'logout',
@ -176,7 +187,7 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
$epp = new EPP\EppWriter();
$xml = $epp->epp_writer($response);
updateTransaction($db, 'logout', null, null, 1500, 'Command completed successfully; ending session', $svTRID, $xml, $trans);
updateTransaction($pdo, 'logout', null, null, 1500, 'Command completed successfully; ending session', $svTRID, $xml, $trans);
sendEppResponse($conn, $xml);
$conn->close();
break;
@ -192,14 +203,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processPoll($conn, $db, $xml, $data['clid'], $trans);
processPoll($conn, $pdo, $xml, $data['clid'], $trans);
break;
}
@ -207,14 +218,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactCheck($conn, $db, $xml, $trans);
processContactCheck($conn, $pdo, $xml, $trans);
break;
}
@ -222,14 +233,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processContactCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -237,14 +248,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactInfo($conn, $db, $xml, $trans);
processContactInfo($conn, $pdo, $xml, $trans);
break;
}
@ -252,14 +263,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processContactUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -267,14 +278,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processContactDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -282,14 +293,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processContactTransfer($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processContactTransfer($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -297,14 +308,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainCheck($conn, $db, $xml, $trans);
processDomainCheck($conn, $pdo, $xml, $trans);
break;
}
@ -312,14 +323,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainInfo($conn, $db, $xml, $trans);
processDomainInfo($conn, $pdo, $xml, $trans);
break;
}
@ -327,14 +338,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processDomainUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -342,14 +353,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processDomainCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -357,14 +368,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processDomainDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -372,14 +383,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainTransfer($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processDomainTransfer($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -387,14 +398,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processHostCheck($conn, $db, $xml, $trans);
processHostCheck($conn, $pdo, $xml, $trans);
break;
}
@ -402,14 +413,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processHostCreate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processHostCreate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -417,14 +428,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processHostInfo($conn, $db, $xml, $trans);
processHostInfo($conn, $pdo, $xml, $trans);
break;
}
@ -432,14 +443,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processHostUpdate($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processHostUpdate($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -447,14 +458,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processHostDelete($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processHostDelete($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
@ -462,14 +473,14 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processFundsInfo($conn, $db, $xml, $data['clid'], $trans);
processFundsInfo($conn, $pdo, $xml, $data['clid'], $trans);
break;
}
@ -477,31 +488,44 @@ $server->handle(function (Connection $conn) use ($table, $db, $c, $log) {
{
$data = $table->get($connId);
$clTRID = (string) $xml->command->clTRID;
$clid = getClid($db, $data['clid']);
$clid = getClid($pdo, $data['clid']);
$xmlString = $xml->asXML();
$trans = createTransaction($db, $clid, $clTRID, $xmlString);
$trans = createTransaction($pdo, $clid, $clTRID, $xmlString);
if (!$data || $data['logged_in'] !== 1) {
sendEppError($conn, $db, 2202, 'Authorization error', $clTRID);
sendEppError($conn, $pdo, 2202, 'Authorization error', $clTRID);
$conn->close();
}
processDomainRenew($conn, $db, $xml, $data['clid'], $c['db_type'], $trans);
processDomainRenew($conn, $pdo, $xml, $data['clid'], $c['db_type'], $trans);
break;
}
default:
{
sendEppError($conn, $db, 2102, 'Unrecognized command');
sendEppError($conn, $pdo, 2000, 'Unrecognized command');
break;
}
}
} catch (PDOException $e) {
// Handle database exceptions
$log->error('Database error: ' . $e->getMessage());
sendEppError($conn, $pdo, 2500, 'Error connecting to the EPP database');
$conn->close();
} catch (Throwable $e) {
// Catch any other exceptions or errors
$log->error('Error: ' . $e->getMessage());
sendEppError($conn, $pdo, 2500, 'General error');
$conn->close();
} finally {
// Return the connection to the pool
$pool->put($pdo);
}
}
sendEppError($conn, $db, 2100, 'Unknown command');
sendEppError($conn, $pdo, 2000, 'Unrecognized command');
$log->info('client disconnected');
$conn->close();
});
$log->info('Namingo EPP server started');
Swoole\Coroutine::create(function () use ($server) {
$server->start();
});