]> git.mxchange.org Git - hub.git/commitdiff
Added 'booting' DHT state
authorRoland Häder <roland@mxchange.org>
Fri, 22 Feb 2013 04:01:07 +0000 (04:01 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 22 Feb 2013 04:01:07 +0000 (04:01 +0000)
.gitattributes
application/hub/config.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/filter/class_BaseHubFilter.php
application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php
application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php
application/hub/main/states/dht/booting/.htaccess [new file with mode: 0644]
application/hub/main/states/dht/booting/class_DhtBootingState.php [new file with mode: 0644]
application/hub/main/states/dht/virgin/class_DhtVirginState.php

index e366d7bf87b2448acdffecc6a897bd8425ba1578..22ac4bde955902f377e4771be3005e9044f13b5b 100644 (file)
@@ -592,6 +592,8 @@ application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php svneol
 application/hub/main/states/dht/.htaccess -text svneol=unset#text/plain
 application/hub/main/states/dht/active/.htaccess -text svneol=unset#text/plain
 application/hub/main/states/dht/active/class_DhtActiveState.php svneol=native#text/plain
+application/hub/main/states/dht/booting/.htaccess -text svneol=unset#text/plain
+application/hub/main/states/dht/booting/class_DhtBootingState.php svneol=native#text/plain
 application/hub/main/states/dht/class_ svneol=native#text/plain
 application/hub/main/states/dht/class_BaseDhtState.php svneol=native#text/plain
 application/hub/main/states/dht/init/.htaccess -text svneol=unset#text/plain
index ce328572f65bcfde07198823527fb55a6c11eb54..dbeb8affb03975e8d702cdbd9cc4cff31421a977 100644 (file)
@@ -621,33 +621,6 @@ $cfg->setConfigEntry('local_query_class', 'LocalQuery');
 // CFG: WEB-TEMPLATE-CLASS @OVERRIDE
 $cfg->setConfigEntry('web_template_class', 'ConsoleTemplateEngine');
 
-// CFG: NODE-INIT-STATE-CLASS
-$cfg->setConfigEntry('node_init_state_class', 'NodeInitState');
-
-// CFG: NODE-VIRGIN-STATE-CLASS
-$cfg->setConfigEntry('node_virgin_state_class', 'NodeVirginState');
-
-// CFG: NODE-ACTIVE-STATE-CLASS
-$cfg->setConfigEntry('node_active_state_class', 'NodeActiveState');
-
-// CFG: NODE-ANNOUNCED-STATE-CLASS
-$cfg->setConfigEntry('node_announced_state_class', 'NodeAnnouncedState');
-
-// CFG: NODE-REACHABLE-STATE-CLASS
-$cfg->setConfigEntry('node_reachable_state_class', 'NodeReachableState');
-
-// CFG: NODE-ANNOUNCEMENT-COMPLETED-STATE-CLASS
-$cfg->setConfigEntry('node_announcement_completed_state_class', 'NodeAnnouncementCompletedState');
-
-// CFG: DHT-INIT-STATE-CLASS
-$cfg->setConfigEntry('dht_init_state_class', 'DhtInitState');
-
-// CFG: DHT-VIRGIN-STATE-CLASS
-$cfg->setConfigEntry('dht_virgin_state_class', 'DhtVirginState');
-
-// CFG: DHT-ACTIVE-STATE-CLASS
-$cfg->setConfigEntry('dht_active_state_class', 'DhtActiveState');
-
 // CFG: NETWORK-PACKAGE-CLASS
 $cfg->setConfigEntry('network_package_class', 'NetworkPackage');
 
@@ -764,6 +737,28 @@ $cfg->setConfigEntry('package_recipient_max_count', 3);
 // CFG: NODE-DHT-CLASS
 $cfg->setConfigEntry('node_dht_class', 'NodeDhtFacade');
 
+///////////////////////////////////////////////////////////////////////////////
+//                              Node states
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: NODE-INIT-STATE-CLASS
+$cfg->setConfigEntry('node_init_state_class', 'NodeInitState');
+
+// CFG: NODE-VIRGIN-STATE-CLASS
+$cfg->setConfigEntry('node_virgin_state_class', 'NodeVirginState');
+
+// CFG: NODE-ACTIVE-STATE-CLASS
+$cfg->setConfigEntry('node_active_state_class', 'NodeActiveState');
+
+// CFG: NODE-ANNOUNCED-STATE-CLASS
+$cfg->setConfigEntry('node_announced_state_class', 'NodeAnnouncedState');
+
+// CFG: NODE-REACHABLE-STATE-CLASS
+$cfg->setConfigEntry('node_reachable_state_class', 'NodeReachableState');
+
+// CFG: NODE-ANNOUNCEMENT-COMPLETED-STATE-CLASS
+$cfg->setConfigEntry('node_announcement_completed_state_class', 'NodeAnnouncementCompletedState');
+
 ///////////////////////////////////////////////////////////////////////////////
 //                              Peer states
 ///////////////////////////////////////////////////////////////////////////////
@@ -792,6 +787,22 @@ $cfg->setConfigEntry('peer_operation_already_progress_state_class', 'OperationAl
 // CFG: PEER-NO-ROUTE-TO-HOST-STATE-CLASS
 $cfg->setConfigEntry('peer_no_route_to_host_state_class', 'NoRouteToHostPeerState');
 
+///////////////////////////////////////////////////////////////////////////////
+//                               DHT states
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: DHT-INIT-STATE-CLASS
+$cfg->setConfigEntry('dht_init_state_class', 'DhtInitState');
+
+// CFG: DHT-VIRGIN-STATE-CLASS
+$cfg->setConfigEntry('dht_virgin_state_class', 'DhtVirginState');
+
+// CFG: DHT-BOOTING-STATE-CLASS
+$cfg->setConfigEntry('dht_booting_state_class', 'DhtBootingState');
+
+// CFG: DHT-ACTIVE-STATE-CLASS
+$cfg->setConfigEntry('dht_active_state_class', 'DhtActiveState');
+
 ///////////////////////////////////////////////////////////////////////////////
 //                       Message answer-status handler
 ///////////////////////////////////////////////////////////////////////////////
index 804eb93d841667c90cd01e820407ab52639ab354..903e49b66e2e9730668c92f342840b61de9521eb 100644 (file)
@@ -142,12 +142,12 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: messageData=' . print_r($messageData, true));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, true) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
 
                // Search for the node's session id and external IP/hostname + TCP/UDP listen port
                foreach ($handlerInstance->getSearchData() as $key) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADEmessageData[' . $key . ']=' . $messageData[$key]);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
 
                        // Is it there?
                        assert(isset($messageData[$key]));
@@ -198,7 +198,7 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADEmessageData=' . print_r($messageData, true));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, true));
 
                // Get a search criteria class
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
@@ -206,7 +206,7 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Add all keys
                foreach (explode($separator, $messageData[$andKey]) as $criteria) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: andKey=' . $andKey . ',criteria=' . $criteria);
 
                        // Add it and leave any 'my-' prefix out
                        $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria);
@@ -224,6 +224,9 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Get node list
                $nodeList = array();
                while ($resultInstance->next()) {
+                       // Debug message
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: current()=' . $resultinstance->current());
+
                        // Add this entry
                        array_push($nodeList, $resultInstance->current());
                } // END - while
@@ -242,12 +245,13 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
         *
         * @param       $nodeList       An array from an earlier database result instance
         * @return      void
+        * @todo        ~10% done
         */
        public function insertNodeList (array $nodeList) {
-               // If no node is in the list (array), skip the rest of this method silently
+               // If no node is in the list (array), skip the rest of this method
                if (count($nodeList) == 0) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: No node record has been returned.');
+                       self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: No node record has been returned.');
 
                        // Abort here
                        return;
index 3653afbd9aecd3ed86cf59d8ccbe6a501015c1f3..9cf41bbb20286da179cd950506cb75f3298b45a3 100644 (file)
@@ -88,7 +88,7 @@ class BaseHubFilter extends BaseFilter {
                        } // END - if
 
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value);
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(str_replace('_', '-', strtoupper($messageType)) . '-TAG: key=' . $key . ',value=' . $value);
 
                        // Set it now
                        $this->dataXmlNodes[$key] = $value;
index e95ba474ca5259257645937c3d0ecb4eac9d34bb..30c65ac259f83c8356c84d43f9cae50063290076 100644 (file)
@@ -31,6 +31,11 @@ class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements
                // Call parent constructor
                parent::__construct(__CLASS__);
 
+               // Init array
+               $this->searchData = array(
+                       XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+               );
+
                // Set handler name
                $this->setHandlerName('request_node_list_answer_okay');
        }
@@ -79,12 +84,6 @@ class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements
                 */
                $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
 
-               // Get the node instance
-               $nodeInstance = Registry::getRegistry()->getInstance('node');
-
-               // Change state
-               $nodeInstance->getStateInstance()->nodeRequestNodeListSuccessful();
-
                // Prepare next message ("hello" message to all returned nodes)
                $this->prepareNextMessage($messageData, $packageInstance);
        }
index 0eaed3b517b3b4a09eb3140a1d8a883cf0c3a4f3..fd35c7e136bdbb0f36ba539e39e9adf1c7efb992 100644 (file)
@@ -107,12 +107,12 @@ class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler impleme
                parent::addArrayToDataSet($dataSetInstance, $messageData);
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, true));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, true));
 
                // Add all ements
                foreach ($this->messageDataElements as $key) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
 
                        // Is it there?
                        assert(isset($messageData[$key]));
diff --git a/application/hub/main/states/dht/booting/.htaccess b/application/hub/main/states/dht/booting/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/states/dht/booting/class_DhtBootingState.php b/application/hub/main/states/dht/booting/class_DhtBootingState.php
new file mode 100644 (file)
index 0000000..602c7ff
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * A Booting dht state class
+ *
+ * @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 DhtBootingState extends BaseDhtState implements Stateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('booting');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @param       $dhtInstance    An instance of a Distributable class
+        * @return      $stateInstance  An instance of a Stateable class
+        */
+       public final static function createDhtBootingState (Distributable $dhtInstance) {
+               // Get new instance
+               $stateInstance = new DhtBootingState();
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-STATE: Has changed from ' . $dhtInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+               // Set the dht instance
+               $stateInstance->setDhtInstance($dhtInstance);
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
index 2042ac4f1723011d84175aaeb222c76d7dfcba72..9bf1a15090bf6f647380de8bb7890952e1d0e23d 100644 (file)
@@ -58,13 +58,13 @@ class DhtVirginState extends BaseDhtState implements Stateable {
        /**
         * Called when the DHT has booted. This means that the bootstrap message
         * has been sent out to other nodes. This will changed the DHT's state
-        * to 'active'.
+        * to 'booting'.
         *
         * @return      void
         */
        public function dhtHasBooted () {
                // Get new instance and set it
-               DhtStateFactory::createDhtStateInstanceByName('active', $this->getDhtInstance());
+               DhtStateFactory::createDhtStateInstanceByName('booting', $this->getDhtInstance());
        }
 }