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\Message\DeliverableMessage;
9 use Org\Shipsimu\Hub\Network\Receive\Receivable;
10 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Request\NodeList\XmlRequestNodeListAnswerTemplateEngine;
12 // Import framework stuff
13 use Org\Mxchange\CoreFramework\Registry\Registerable;
16 * A RequestNodeListAnswerOkay handler
18 * @author Roland Haeder <webmaster@shipsimu.org>
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class RequestNodeListAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
48 $this->searchData = array(
49 XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
53 $this->setHandlerName('request_node_list_answer_okay');
57 * Creates an instance of this class
59 * @return $handlerInstance An instance of a HandleableMessage class
61 public final static function createRequestNodeListAnswerOkayHandler () {
63 $handlerInstance = new RequestNodeListAnswerOkayHandler();
65 // Return the prepared instance
66 return $handlerInstance;
70 * Handles given message data array
72 * @param $messageInstance An instance of a DeliverableMessage class
73 * @param $packageInstance An instance of a Receivable class
75 * @throws NodeSessionIdVerficationException If the provided session id is not matching
76 * @todo Do some more here: Handle karma, et cetera?
78 public function handleAnswerMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
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')->registerNodeByMessageInstance($messageInstance, $this, TRUE);
97 // Prepare next message ("hello" message to all returned nodes)
98 // @TODO $this->prepareNextMessage($messageInstance, $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 $messageInstance An instance of a DeliverableMessage class
115 protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
116 $this->partialStub('Please implement this method.');
120 * Removes configuration data with given message data array from global
121 * configuration. For content of $messageInstance see method comment above.
123 * @param $messageInstance An instance of a DeliverableMessage class
127 protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
128 $this->partialStub('Please implement this method.');