X-Git-Url: https://git.mxchange.org/?p=hub.git;a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fhandler%2Fanswer-status%2Fannouncement%2Fclass_AnnouncementAnswerOkayHandler.php;h=64425d5b70158b8e88ff7742c2e0a6c849617c72;hp=1b1b12b830c87b50b0f4617acd6c9011b654c795;hb=73aff29b9bc78031853b0b8c0fe0a8e04f66ac29;hpb=4a4fbfb80267fd344b37cef2b173f666ecb44646 diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 1b1b12b83..64425d5b7 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -2,11 +2,11 @@ /** * A AnnouncementAnswerOkay handler * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org + * @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 @@ -31,6 +31,12 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha // 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'); } @@ -54,48 +60,26 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha * @param $messageData An array of message data * @param $packageInstance An instance of a Receivable class * @return void - * @throws NodeSessionIdVerficationException If the provided session id is not matching * @todo Do some more here: Handle karma, et cetera? - * @todo Rewrite this to use DHT */ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { - // Get a database wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class'); - - // Get also a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Lookup external session id/external IP/port - $searchInstance->addCriteria('node_session_id' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]); - $searchInstance->addCriteria('node_external_ip', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP]); - $searchInstance->addCriteria('node_listen_port', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT]); - - // Only one entry is fine - $searchInstance->setLimit(1); - - // Run the query - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); - - // Is there an try? - if (!$resultInstance->next()) { - // This is fatal, caused by "stolen" session id and/or not matching IP number/port combination - throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING); - } // END - if + /* + * 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_bootstrap_task_class'); + $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class'); // Register it as well - $handlerInstance->registerTask('dht_bootstrap', $taskInstance); - - // Update node data (include status code) - $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance); + $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance); // Get the node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Change state $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful(); @@ -109,27 +93,28 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha * * The following array is being handled over: * - * my-external-ip => 1.2.3.4 - * my-internal-ip => 5.6.7.8 - * my-status => reachable - * my-session-id => aaabbbcccdddeeefff123456789 - * my-tcp-port => 9060 - * my-udp-port => 9060 - * answer-status => OKAY - * message_type => announcement_answer + * 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 = Registry::getRegistry()->getInstance('node'); + $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get an array of all accepted object types $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); // Add missing (temporary) configuration 'accepted_object_types' - $this->getConfigInstance()->setConfigEntry('accepted_object_types', implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); + $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); } /** @@ -141,7 +126,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha */ protected function removeMessageConfigurationData (array $messageData) { // Remove temporay configuration - $this->getConfigInstance()->unsetConfigEntry('accepted_object_types'); + $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS); } }