From: Roland Häder Date: Thu, 18 May 2017 23:51:58 +0000 (+0200) Subject: Next wave: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dc3a01de6601d45aa675db4e2a167c2de81edaf3;p=hub.git Next wave: - imported [Node|Dht]ObjectFactory - created namespaces Signed-off-by: Roland Häder --- diff --git a/application/hub/classes/commands/console/class_HubConsoleMainCommand.php b/application/hub/classes/commands/console/class_HubConsoleMainCommand.php index ccebfc281..db9deed0e 100644 --- a/application/hub/classes/commands/console/class_HubConsoleMainCommand.php +++ b/application/hub/classes/commands/console/class_HubConsoleMainCommand.php @@ -2,6 +2,9 @@ // Own namespace namespace Hub\Command; +// Import application-specific stuff +use Hub\Factory\Node\NodeObjectFactory; + // Import framework stuff use CoreFramework\Command\BaseCommand; use CoreFramework\Command\Commandable; diff --git a/application/hub/classes/cruncher/class_BaseHubCruncher.php b/application/hub/classes/cruncher/class_BaseHubCruncher.php index db94a79bc..ea6e6c100 100644 --- a/application/hub/classes/cruncher/class_BaseHubCruncher.php +++ b/application/hub/classes/cruncher/class_BaseHubCruncher.php @@ -6,6 +6,7 @@ namespace Hub\Cruncher; use Hub\Generic\BaseHubSystem; // Import framework stuff +use CoreFramework\Factory\ObjectFactory; use CoreFramework\Object\BaseFrameworkSystem; /** diff --git a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php index 71862c67a..7e074d925 100644 --- a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -1,4 +1,10 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.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 AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Init array - $this->searchData = array( - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, - ); - - // Set handler name - $this->setHandlerName('announcement_answer_okay'); - } - - /** - * Creates an instance of this class - * - * @return $handlerInstance An instance of a HandleableMessage class - */ - public final static function createAnnouncementAnswerOkayHandler () { - // Get new instance - $handlerInstance = new AnnouncementAnswerOkayHandler(); - - // Return the prepared instance - return $handlerInstance; - } - - /** - * Handles given message data array - * - * @param $messageData An array of message data - * @param $packageInstance An instance of a Receivable class - * @return void - * @todo Do some more here: Handle karma, et cetera? - */ - public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { - /* - * Query DHT and force update (which will throw an exception if the - * node is not found). - */ - $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE); - - // Get handler instance - $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); - - // Generate DHT bootstrap task - $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class'); - - // Register it as well - $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance); - - // Get the node instance - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Change state - $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); - - // Prepare next message - $this->prepareNextMessage($messageData, $packageInstance); - } - - /** - * Initializes configuration data from given message data array - * - * The following array is being handled over: - * - * my-external-address => 1.2.3.4 - * my-internal-address => 5.6.7.8 - * my-status => reachable - * my-node-id => aaabbbcccdddeeefff123456789 - * my-session-id => aaabbbcccdddeeefff123456789 - * my-tcp-port => 9060 - * my-udp-port => 9060 - * answer-status => OKAY - * message_type => announcement_answer - * - * @param $messageData An array with all message data - * @return void - */ - protected function initMessageConfigurationData (array $messageData) { - // Get node instance - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Get an array of all accepted object types - $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); - - // Add missing (temporary) configuration 'accepted_object_types' - $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); - } - - /** - * Removes configuration data with given message data array from global - * configuration. For content of $messageData see method comment above. - * - * @param $messageData An array with all message data - * @return void - */ - protected function removeMessageConfigurationData (array $messageData) { - // Remove temporay configuration - $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS); - } -} - -// [EOF] -?> diff --git a/application/hub/classes/handler/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php b/application/hub/classes/handler/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php new file mode 100644 index 000000000..c797e7026 --- /dev/null +++ b/application/hub/classes/handler/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php @@ -0,0 +1,140 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Init array + $this->searchData = array( + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, + ); + + // Set handler name + $this->setHandlerName('announcement_answer_okay'); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a HandleableMessage class + */ + public final static function createNodeAnnouncementAnswerOkayHandler () { + // Get new instance + $handlerInstance = new NodeAnnouncementAnswerOkayHandler(); + + // Return the prepared instance + return $handlerInstance; + } + + /** + * Handles given message data array + * + * @param $messageData An array of message data + * @param $packageInstance An instance of a Receivable class + * @return void + * @todo Do some more here: Handle karma, et cetera? + */ + public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { + /* + * Query DHT and force update (which will throw an exception if the + * node is not found). + */ + $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE); + + // Get handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); + + // Generate DHT bootstrap task + $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class'); + + // Register it as well + $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance); + + // Get the node instance + $nodeInstance = NodeObjectFactory::createNodeInstance(); + + // Change state + $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); + + // Prepare next message + $this->prepareNextMessage($messageData, $packageInstance); + } + + /** + * Initializes configuration data from given message data array + * + * The following array is being handled over: + * + * my-external-address => 1.2.3.4 + * my-internal-address => 5.6.7.8 + * my-status => reachable + * my-node-id => aaabbbcccdddeeefff123456789 + * my-session-id => aaabbbcccdddeeefff123456789 + * my-tcp-port => 9060 + * my-udp-port => 9060 + * answer-status => OKAY + * message_type => announcement_answer + * + * @param $messageData An array with all message data + * @return void + */ + protected function initMessageConfigurationData (array $messageData) { + // Get node instance + $nodeInstance = NodeObjectFactory::createNodeInstance(); + + // Get an array of all accepted object types + $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); + + // Add missing (temporary) configuration 'accepted_object_types' + $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); + } + + /** + * Removes configuration data with given message data array from global + * configuration. For content of $messageData see method comment above. + * + * @param $messageData An array with all message data + * @return void + */ + protected function removeMessageConfigurationData (array $messageData) { + // Remove temporay configuration + $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS); + } +} + +// [EOF] +?> diff --git a/application/hub/classes/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/classes/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php index 5f14fc1e0..8dba472f9 100644 --- a/application/hub/classes/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/classes/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -2,7 +2,8 @@ // Own namespace namespace Hub\Handler\Node\Message\Announcement; -// Import hub-specific stuff +// Import application-specific stuff +use Hub\Factory\Node\NodeObjectFactory; use Hub\Generic\BaseHubSystem; /** diff --git a/application/hub/classes/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/classes/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index 6ccd1619b..0b5a64b61 100644 --- a/application/hub/classes/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/classes/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -1,4 +1,10 @@ setConfigEntry('dht_active_state_class', 'DhtActiveState'); /////////////////////////////////////////////////////////////////////////////// // CFG: ANNOUNCEMENT-ANSWER-STATUS-OKAY-HANDLER-CLASS -$cfg->setConfigEntry('announcement_answer_status_okay_handler_class', 'AnnouncementAnswerOkayHandler'); +$cfg->setConfigEntry('announcement_answer_status_okay_handler_class', 'Hub\Handler\Node\Announcement\Answer\NodeAnnouncementAnswerOkayHandler'); // CFG: REQUEST-NODE-LIST-ANSWER-STATUS-OKAY-HANDLER-CLASS $cfg->setConfigEntry('request_node_list_answer_status_okay_handler_class', 'RequestNodeListAnswerOkayHandler'); diff --git a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php index 474d86e2b..7f44a8fb9 100644 --- a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php +++ b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php @@ -1,4 +1,10 @@