3 namespace Hub\Handler\Answer\Okay\NodeList;
5 // Import application-specific stuff
6 use Hub\Factory\Dht\DhtObjectFactory;
7 use Hub\Network\Receive\Receivable;
9 // Import framework stuff
10 use CoreFramework\Registry\Registerable;
13 * A RequestNodeListAnswerOkay handler
15 * @author Roland Haeder <webmaster@shipsimu.org>
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
18 * @license GNU GPL 3.0 or any newer version
19 * @link http://www.shipsimu.org
21 * This program is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation, either version 3 of the License, or
24 * (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
36 * Protected constructor
40 protected function __construct () {
41 // Call parent constructor
42 parent::__construct(__CLASS__);
45 $this->searchData = array(
46 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
50 $this->setHandlerName('request_node_list_answer_okay');
54 * Creates an instance of this class
56 * @return $handlerInstance An instance of a HandleableMessage class
58 public final static function createRequestNodeListAnswerOkayHandler () {
60 $handlerInstance = new RequestNodeListAnswerOkayHandler();
62 // Return the prepared instance
63 return $handlerInstance;
67 * Handles given message data array
69 * @param $messageData An array of message data
70 * @param $packageInstance An instance of a Receivable class
72 * @throws NodeSessionIdVerficationException If the provided session id is not matching
73 * @todo Do some more here: Handle karma, et cetera?
75 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
76 // Make sure node-list is found in array
77 assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
80 $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
82 // Make sure it is completely decoded
83 assert(is_array($nodeList));
85 // ... and remove it as it should not be included now
86 unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
88 // Write node list to DHT
89 DhtObjectFactory::createDhtInstance('node')->insertNodeList($nodeList);
92 * Query DHT and force update (which will throw an exception if the
95 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
97 // Prepare next message ("hello" message to all returned nodes)
98 //$this->prepareNextMessage($messageData, $packageInstance);
102 * Initializes configuration data from given message data array
104 * The following array is being handled over:
106 * session-id => aaabbbcccdddeeefff123456789
107 * node-list => aabb:ccdd:eeff
108 * answer-status => OKAY
109 * message_type => request_node_list_answer
111 * @param $messageData An array with all message data
115 protected function initMessageConfigurationData (array $messageData) {
116 $this->partialStub('Please implement this method.');
120 * Removes configuration data with given message data array from global
121 * configuration. For content of $messageData see method comment above.
123 * @param $messageData An array with all message data
127 protected function removeMessageConfigurationData (array $messageData) {
128 $this->partialStub('Please implement this method.');