]> git.mxchange.org Git - hub.git/commitdiff
Use set DHT instance to shortcut a little
authorRoland Häder <roland@mxchange.org>
Sun, 10 Feb 2013 04:11:16 +0000 (04:11 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 10 Feb 2013 04:11:16 +0000 (04:11 +0000)
application/hub/main/handler/message-types/class_BaseMessageHandler.php
application/hub/main/tools/class_HubTools.php

index 8c347b407567c4fa9fffe54c45d7fa3a847eabcc..98f79e7780fbf2cef5b0c2c8a8c20b7d84dd2123 100644 (file)
@@ -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);
        }
 
        /**
index f0ba8beccbc5497fa3f6b5eeecb2d9678f7efd70..07cd8f7a5f6d3cef48bcc852053be790cbe89eeb 100644 (file)
@@ -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=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
 
                // Return result