]> git.mxchange.org Git - hub.git/commitdiff
Added DHT initialization task (see comments below):
authorRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 18:28:17 +0000 (18:28 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 18:28:17 +0000 (18:28 +0000)
- The DHT initialization task is for preparing the DHT (if not yet done) in a
  very early state ("virgin" state) and inserts/updates node's current data as
  the first entry. With this data the node "knowns" only itself, not even the
  upper nodes. They will be added later on.
- Renamed instance 'task' to 'task_handler' as it is always a task handler
  class
- Other minor improvements

20 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/distributable/class_Distributable.php
application/hub/interfaces/wrapper/class_NodeListWrapper.php
application/hub/main/commands/console/class_HubConsoleAptProxyCommand.php
application/hub/main/commands/console/class_HubConsoleChatCommand.php
application/hub/main/commands/console/class_HubConsoleCruncherCommand.php
application/hub/main/commands/console/class_HubConsoleMainCommand.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/filter/activation/node/class_NodeActivationAnnouncementFilter.php
application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php
application/hub/main/filter/task/apt-proxy/class_AptProxyTaskHandlerInitializerFilter.php
application/hub/main/filter/task/chat/class_ChatTaskHandlerInitializerFilter.php
application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php
application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php
application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php
application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php
application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php [new file with mode: 0644]
application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php
application/hub/main/tools/class_HubTools.php

index c45b21074a21b72349c947375e226cba0a78d268..3289146a10b9ba0d12bd87e88374d90af989e0e4 100644 (file)
@@ -636,6 +636,7 @@ application/hub/main/tasks/node/decoder/.htaccess -text svneol=unset#text/plain
 application/hub/main/tasks/node/decoder/class_NodePackageDecoderTask.php -text
 application/hub/main/tasks/node/dht/.htaccess -text svneol=unset#text/plain
 application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php svneol=native#text/plain
+application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php svneol=native#text/plain
 application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php svneol=native#text/plain
 application/hub/main/tasks/node/listener/.htaccess -text svneol=unset#text/plain
 application/hub/main/tasks/node/ping/.htaccess -text svneol=unset#text/plain
index 151722b01105cc505256c52f6de7a1118adaf6d8..2df9323551aa72944a11bf31c0e052b7113cd0f1 100644 (file)
@@ -498,6 +498,9 @@ $cfg->setConfigEntry('node_chunk_assembler_task_class', 'NodeChunkAssemblerTask'
 // CFG: NODE-PACKAGE-DECODER-TASK-CLASS
 $cfg->setConfigEntry('node_package_decoder_task_class', 'NodePackageDecoderTask');
 
+// CFG: NODE-DHT-INIT-TASK-CLASS
+$cfg->setConfigEntry('node_dht_init_task_class', 'NodeDhtInitializationTask');
+
 // CFG: NODE-DHT-BOOTSTRAP-TASK-CLASS
 $cfg->setConfigEntry('node_dht_bootstrap_task_class', 'NodeDhtBootstrapTask');
 
@@ -549,11 +552,20 @@ $cfg->setConfigEntry('task_chunk_assembler_interval_delay', 50);
 // CFG: TASK-CHUNK-ASSEMBLER-MAX-RUNS
 $cfg->setConfigEntry('task_chunk_assembler_max_runs', 0);
 
+// CFG: TASK-DHT-INIT-STATUP-DELAY
+$cfg->setConfigEntry('task_dht_init_startup_delay', 100);
+
+// CFG: TASK-DHT-INIT-INTERVAL-DELAY
+$cfg->setConfigEntry('task_dht_init_interval_delay', 86400000); // = 1 day (won't matter anyway)
+
+// CFG: TASK-DHT-INIT-MAX-RUNS
+$cfg->setConfigEntry('task_dht_init_max_runs', 1);
+
 // CFG: TASK-DHT-BOOTSTRAP-STATUP-DELAY
 $cfg->setConfigEntry('task_dht_bootstrap_startup_delay', 100);
 
 // CFG: TASK-DHT-BOOTSTRAP-INTERVAL-DELAY
-$cfg->setConfigEntry('task_dht_bootstrap_interval_delay', 3600000); // = 1 hour
+$cfg->setConfigEntry('task_dht_bootstrap_interval_delay', 3600000); // = 1 hour (won't matter anyway)
 
 // CFG: TASK-DHT-BOOTSTRAP-MAX-RUNS
 $cfg->setConfigEntry('task_dht_bootstrap_max_runs', 1);
index 8bbf595988ecb149fdeafd1d2f254ead220dbbc0..9ddba1f538bdff89485a30ef66c7b69b95742526 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface Distributable extends FrameworkInterface {
+       /**
+        * Initializes the distributable hash table (DHT)
+        *
+        * @return      void
+        */
+       function initDht();
 }
 
 // [EOF]
index c04669289bed5a00c6249c14bd1c77c1939e67b8..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,64 +1,3 @@
 <?php
-/**
- * An interface for node-list (database) wrapper
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface NodeListWrapper extends FrameworkInterface {
-       /**
-        * Resolves a session id into an ip:port combination
-        *
-        * @param       $sessionId      A valid session id
-        * @param       $protocol       Name of the protocol (TCP/UDP)
-        * @return      $recipient      Recipient as ip:port combination
-        */
-       function resolveIpPortBySessionId ($sessionId, $protocol);
-
-       /**
-        * Resolves a ip:port combination into a session id
-        *
-        * @param       $ipPort         Ip:port combination
-        * @param       $protocol       Name of the used protocol (TCP/UDP)
-        * @return      $sessionId      A valid session id
-        */
-       function resolveSessionIdByIpPort ($ipPort, $protocol);
-
-       /**
-        * Registeres a node by given message data.
-        *
-        * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a HandleableMessage class
-        * @return      void
-        */
-       function registerNodeByMessageData (array $messageData, Handleable $handlerInstance);
-
-       /**
-        * Updates an existing entry in node list
-        *
-        * @param       $messageData            An array of all message data
-        * @param       $handlerInstance        An instance of a HandleableMessage class
-        * @param       $searchInstance         An instance of LocalSearchCriteria class
-        * @return      void
-        */
-       function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance);
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
index f701dc74dee6050cb9c916dc073a06a7359c610b..475820c9f20bf02480cdaaa693fd325edd05541f 100644 (file)
@@ -78,7 +78,7 @@ class HubConsoleAptProxyCommand extends BaseCommand implements Commandable {
                $proxyInstance->addExtraAptProxyFilters();
 
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Debug message
                self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
index 5f5acd5b933ab9e6718cf7f1ce80fa77821e3c52..6b092478f790d3ffa31bf5eba90c46fad0651611 100644 (file)
@@ -78,7 +78,7 @@ class HubConsoleChatCommand extends BaseCommand implements Commandable {
                $chatInstance->addExtraChatFilters();
 
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Debug message
                self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
index d5fa52a93770552a45843c8f8a5d863785f6ca97..dd159a089ccd97b250064abf6204a0b8983825d0 100644 (file)
@@ -78,7 +78,7 @@ class HubConsoleCruncherCommand extends BaseCommand implements Commandable {
                $cruncherInstance->addExtraCruncherFilters();
 
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Debug message
                self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
index 45385ea7b6cdc2c3de8f4f7110421269603f2d25..581315540fc8d26a065316ebd4e66da6174237ce 100644 (file)
@@ -85,7 +85,7 @@ class HubConsoleMainCommand extends BaseCommand implements Commandable {
                $nodeInstance->activateNode($requestInstance, $responseInstance);
 
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Debug message
                self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
index 07ab7633d3669658adf2c528b49146d46acc8ace..5007c47f0ef041cf485e5da4db07ce2fecf58147 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class NodeDhtFacade extends BaseDht implements Distributable {
+class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
        /**
         * Protected constructor
         *
@@ -44,6 +44,16 @@ class NodeDhtFacade extends BaseDht implements Distributable {
                // Return the prepared instance
                return $dhtInstance;
        }
+
+       /**
+        * Initializes the distributable hash table (DHT)
+        *
+        * @return      void
+        * @todo        Please implement this method
+        */
+       public function initDht () {
+               $this->partialStub('Please implement this method.');
+       }
 }
 
 // [EOF]
index 564f85b54dfb4b9f674d70b88a43cc707b333d3a..37efab2cf3a357282b817a68e66356db8e0b41b3 100644 (file)
@@ -54,7 +54,7 @@ class NodeActivationAnnouncementFilter extends BaseNodeFilter implements Filtera
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Prepare a self-test task for the listeners
                $taskInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_task_class');
index 43b16b2ad69c2b06480f97c36138785f58110272..7c830b614296c011d41e6dbffcb3f60548d5f930 100644 (file)
@@ -56,7 +56,7 @@ class NodeShutdownTaskHandlerFilter extends BaseNodeFilter implements Filterable
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
                // Get task handler instance
-               $handlerInstance = Registry::getRegistry()->getInstance('task');
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
 
                // Shutdown the task manager and all its registered tasks
                $handlerInstance->doShutdown();
index 3c673e5d3a84a0f24c43a12a01f8ea26b7738997..e8b4aac73d3b5303b5d30e7db315a91d8bf907f1 100644 (file)
@@ -70,7 +70,7 @@ class AptProxyTaskHandlerInitializerFilter extends BaseAptProxyFilter implements
                $handlerInstance->registerTask('apt_proxy_listener', $taskInstance);
 
                // Put the task handler in registry
-               Registry::getRegistry()->addInstance('task', $handlerInstance);
+               Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
        }
 }
 
index bd9fda316409b449718473cf356e635e24058a8c..4ba2fb6007c43feb239f590be194a48876d7bd51 100644 (file)
@@ -70,7 +70,7 @@ class ChatTaskHandlerInitializerFilter extends BaseChatFilter implements Filtera
                $handlerInstance->registerTask('chat_telnet_listener', $taskInstance);
 
                // Put the task handler in registry
-               Registry::getRegistry()->addInstance('task', $handlerInstance);
+               Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
        }
 }
 
index b4ef8b4e00a62f77355514e274e4fcdf2f7da8b5..099978b7be98ab6a6c23c549023235af2ac8213d 100644 (file)
@@ -84,7 +84,7 @@ class CruncherTaskHandlerInitializerFilter extends BaseCruncherFilter implements
                $handlerInstance->registerTask('cruncher_key_producer', $taskInstance);
 
                // Put the task handler in registry
-               Registry::getRegistry()->addInstance('task', $handlerInstance);
+               Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
        }
 }
 
index c28671577009b6a43759e803433d11e8b581cc81..3ea39ee32a4a5ca55408468e7127c097f7428fdd 100644 (file)
@@ -92,10 +92,10 @@ class NodeTaskHandlerInitializerFilter extends BaseNodeFilter implements Filtera
                $handlerInstance->registerTask('package_decoder', $taskInstance);
 
                // Generate DHT initialization task
-               $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+               $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_init_task_class');
 
                // Register it as well
-               $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
+               $handlerInstance->registerTask('dht_init', $taskInstance);
 
                // Generate DHT query task
                $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_query_task_class');
@@ -125,7 +125,7 @@ class NodeTaskHandlerInitializerFilter extends BaseNodeFilter implements Filtera
                $handlerInstance->registerTask('ping', $taskInstance);
 
                // Put the task handler in registry
-               Registry::getRegistry()->addInstance('task', $handlerInstance);
+               Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
        }
 }
 
index e0f708e4fa2d8743e2af3b73c4ea5a6d5c5ed66a..39e792ed2f5c190af77f3d270ffb3cca3d33bf22 100644 (file)
@@ -82,6 +82,15 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha
                        throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
                } // END - if
 
+               // Get handler instance
+               $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+               // Generate DHT bootstrap task
+               $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+
+               // Register it as well
+               $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
+
                // Update node data (include status code)
                $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
 
index b5a556d2e156284fa167c0dd09fb303be6a4e02f..5ee47c68444e6bd7c3d6584f8379fbf7dd387cac 100644 (file)
@@ -69,7 +69,8 @@ class NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable {
         * @todo        0% done
         */
        public function executeTask () {
-               $this->partialStub('Unimplemented task.');
+               // "Cache" the DHT instance
+               $dhtInstance = $this->getDhtInstance();
        }
 }
 
diff --git a/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php b/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php
new file mode 100644 (file)
index 0000000..fabd032
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/**
+ * A DhtInitialization node-task
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+class NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $taskInstance   An instance of a Visitable class
+        */
+       public final static function createNodeDhtInitializationTask () {
+               // Get new instance
+               $taskInstance = new NodeDhtInitializationTask();
+
+               // Get a DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+
+               // Set the DHT instance here
+               $taskInstance->setDhtInstance($dhtInstance);
+
+               // Return the prepared instance
+               return $taskInstance;
+       }
+
+       /**
+        * Accepts the visitor to process the visitor
+        *
+        * @param       $visitorInstance        An instance of a Visitor class
+        * @return      void
+        */
+       public function accept (Visitor $visitorInstance) {
+               // Visit this task
+               $visitorInstance->visitTask($this);
+       }
+
+       /**
+        * Executes the task
+        *
+        * @return      void
+        */
+       public function executeTask () {
+               // Intiailize the DHT
+               $this->getDhtInstance()->initDht();
+       }
+}
+
+// [EOF]
+?>
index f281d9eba1706b368e5658a78d511b22bc10072d..44bbced0a561beaf877dd3b82eddfe10fd2138f9 100644 (file)
@@ -69,7 +69,8 @@ class NodeDhtQueryTask extends BaseTask implements Taskable, Visitable {
         * @todo        0% done
         */
        public function executeTask () {
-               $this->partialStub('Unimplemented task.');
+               // "Cache" the DHT instance
+               $dhtInstance = $this->getDhtInstance();
        }
 }
 
index f0d1baf55ffacc0d2f857e6f91a340585fd397ca..b81939b7621968ee1c4f4288056d5aac145fdb52 100644 (file)
@@ -80,19 +80,20 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a session id into an ip:port combination
+        * Resolves a session id into an ip:port combination. The opposite method
+        * is resolveSessionIdByIpPort()
         *
         * @param       $sessionId      A valid session id
         * @param       $protocol       Name of the used protocol: TCP/UDP
         * @return      $recipient      Recipient as ip:port combination
-        * @todo        Rewrite this to use DHT
         */
        protected function resolveIpPortBySessionId ($sessionId, $protocol) {
-               // Get a wrapper instance
-               $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+               // Get a DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
 
-               // And ask it for the session id
-               $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId, $protocol);
+               // And ask it for ip:port by given session id
+               $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol);
+               die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
 
                // Is the recipient invalid?
                if ($recipient == 'invalid:invalid') {
@@ -111,19 +112,20 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a ip:port combination into a session id
+        * Resolves a ip:port combination into a session id. The "opposite" method
+        * is resolveIpPortBySessionId().
         *
         * @param       $ipPort         Ip:port combination
         * @param       $protocol       Name of used protocol (TCP/UDP)
         * @return      $sessionId      Valid session id
-        * @todo        Rewrite this to use DHT
         */
        public static function resolveSessionIdByIpPort ($ipPort, $protocol) {
-               // Get a wrapper instance
-               $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+               // Get a DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
 
-               // And ask it for the session id
-               $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort, $protocol);
+               // And ask it for session id by given ip:port
+               $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol);
+               die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
 
                // Return result
                return $sessionId;