X-Git-Url: https://git.mxchange.org/?p=hub.git;a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fhandler%2Fanswer-status%2Frequests%2Fclass_RequestNodeListAnswerOkayHandler.php;h=128dbc3004265ef052fc8a310c147ff43b1ec3f9;hp=cca50dab4946c2ef0af09c4fb966053169228376;hb=73aff29b9bc78031853b0b8c0fe0a8e04f66ac29;hpb=ad45b22b26e0788c4b53451efca9065ea1a26805 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 cca50dab4..128dbc300 100644 --- a/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php @@ -2,11 +2,11 @@ /** * A RequestNodeListAnswerOkay 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,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'); } @@ -56,38 +61,31 @@ class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements * @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('session_id' , $messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID]); + // Make sure node-list is found in array + assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST])); - // Only one entry is fine - $searchInstance->setLimit(1); + // Save node list + $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST])); - // Run the query - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + // Make sure it is completely decoded + assert(is_array($nodeList)); - // 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 + // ... and remove it as it should not be included now + unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]); - // Get the node instance - $nodeInstance = Registry::getRegistry()->getInstance('node'); + // Write node list to DHT + $this->getDhtInstance()->insertNodeList($nodeList); - // Change state - $nodeInstance->getStateInstance()->nodeRequestNodeListSuccessful(); + /* + * Query DHT and force update (which will throw an exception if the + * node is not found). + */ + $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE); // Prepare next message ("hello" message to all returned nodes) - $this->prepareNextMessage($messageData, $packageInstance); + //$this->prepareNextMessage($messageData, $packageInstance); } /**