From ed68027883fd0cc0db19c62649d295e345ae436c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 10 Feb 2013 04:11:16 +0000 Subject: [PATCH] Use set DHT instance to shortcut a little --- .../message-types/class_BaseMessageHandler.php | 6 ++++++ application/hub/main/tools/class_HubTools.php | 16 ++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 8c347b407..98f79e778 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -32,6 +32,12 @@ abstract class BaseMessageHandler extends BaseDataHandler { protected function __construct ($className) { // Call parent constructor parent::__construct($className); + + // Get a DHT instance + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); + + // Set it here + $this->setDhtInstance($dhtInstance); } /** diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index f0ba8becc..07cd8f7a5 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -50,6 +50,12 @@ class HubTools extends BaseHubSystem { // Call parent constructor parent::__construct(__CLASS__); + // Get a DHT instance + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); + + // Set it here + $this->setDhtInstance($dhtInstance); + // Init salt length $this->sessionIdLength = 32 + $this->getConfigInstance()->getConfigEntry('salt_length'); } @@ -87,11 +93,8 @@ class HubTools extends BaseHubSystem { * @return $recipient Recipient as ip:port combination */ protected function resolveIpPortBySessionId ($sessionId) { - // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); - // And ask it for ip:port by given session id - $recipient = $dhtInstance->findNodeBySessionId($sessionId); + $recipient = $this->getDhtInstance()->findNodeBySessionId($sessionId); // Is the recipient invalid? if ((!isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT])) || ($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT] == 'invalid:invalid')) { @@ -125,11 +128,8 @@ class HubTools extends BaseHubSystem { * @return $sessionId Valid session id */ public static function resolveSessionIdByIpPort ($ipPort) { - // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); - // And ask it for session id by given ip:port - $recipient = $dhtInstance->findNodeByIpPort($ipPort); + $recipient = $this->getDhtInstance()->findNodeByIpPort($ipPort); die(__METHOD__.':recipient=
'.print_r($recipient, true).'
' . PHP_EOL); // Return result -- 2.39.5