3 namespace Org\Shipsimu\Hub\Handler\Answer\Okay\NodeList;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory;
7 use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
8 use Org\Shipsimu\Hub\Network\Receive\Receivable;
9 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Request\NodeList\XmlRequestNodeListAnswerTemplateEngine;
11 // Import framework stuff
12 use Org\Mxchange\CoreFramework\Registry\Registerable;
15 * A RequestNodeListAnswerOkay handler
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class RequestNodeListAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->searchData = array(
48 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
52 $this->setHandlerName('request_node_list_answer_okay');
56 * Creates an instance of this class
58 * @return $handlerInstance An instance of a HandleableMessage class
60 public final static function createRequestNodeListAnswerOkayHandler () {
62 $handlerInstance = new RequestNodeListAnswerOkayHandler();
64 // Return the prepared instance
65 return $handlerInstance;
69 * Handles given message data array
71 * @param $messageData An array of message data
72 * @param $packageInstance An instance of a Receivable class
74 * @throws NodeSessionIdVerficationException If the provided session id is not matching
75 * @todo Do some more here: Handle karma, et cetera?
77 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
78 // Make sure node-list is found in array
79 assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
82 $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
84 // Make sure it is completely decoded
85 assert(is_array($nodeList));
87 // ... and remove it as it should not be included now
88 unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
90 // Write node list to DHT
91 DhtObjectFactory::createDhtInstance('node')->insertNodeList($nodeList);
94 * Query DHT and force update (which will throw an exception if the
97 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
99 // Prepare next message ("hello" message to all returned nodes)
100 //$this->prepareNextMessage($messageData, $packageInstance);
104 * Initializes configuration data from given message data array
106 * The following array is being handled over:
108 * session-id => aaabbbcccdddeeefff123456789
109 * node-list => aabb:ccdd:eeff
110 * answer-status => OKAY
111 * message_type => request_node_list_answer
113 * @param $messageData An array with all message data
117 protected function initMessageConfigurationData (array $messageData) {
118 $this->partialStub('Please implement this method.');
122 * Removes configuration data with given message data array from global
123 * configuration. For content of $messageData see method comment above.
125 * @param $messageData An array with all message data
129 protected function removeMessageConfigurationData (array $messageData) {
130 $this->partialStub('Please implement this method.');