From: Roland Häder Date: Fri, 22 Feb 2013 04:01:07 +0000 (+0000) Subject: Added 'booting' DHT state X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d3a8f731bcdf6f76e8ed30c1a2a9c6bda10e8fee;p=hub.git Added 'booting' DHT state --- diff --git a/.gitattributes b/.gitattributes index e366d7bf8..22ac4bde9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/application/hub/config.php b/application/hub/config.php index ce328572f..dbeb8affb 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -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 /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 804eb93d8..903e49b66 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -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-FACADE: messageData[' . $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-FACADE: messageData=' . 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; diff --git a/application/hub/main/filter/class_BaseHubFilter.php b/application/hub/main/filter/class_BaseHubFilter.php index 3653afbd9..9cf41bbb2 100644 --- a/application/hub/main/filter/class_BaseHubFilter.php +++ b/application/hub/main/filter/class_BaseHubFilter.php @@ -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; diff --git a/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php b/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php index e95ba474c..30c65ac25 100644 --- a/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php @@ -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); } diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php index 0eaed3b51..fd35c7e13 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/dht/booting/.htaccess @@ -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 index 000000000..602c7ff50 --- /dev/null +++ b/application/hub/main/states/dht/booting/class_DhtBootingState.php @@ -0,0 +1,60 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/states/dht/virgin/class_DhtVirginState.php b/application/hub/main/states/dht/virgin/class_DhtVirginState.php index 2042ac4f1..9bf1a1509 100644 --- a/application/hub/main/states/dht/virgin/class_DhtVirginState.php +++ b/application/hub/main/states/dht/virgin/class_DhtVirginState.php @@ -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()); } }