]> git.mxchange.org Git - hub.git/blob
e573ad4ca7878ccffda85c23b5279d80b633604f
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Org\Shipsimu\Hub\Handler\Answer\Okay\NodeList;
4
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;
10
11 // Import framework stuff
12 use Org\Mxchange\CoreFramework\Registry\Registerable;
13
14 /**
15  * A RequestNodeListAnswerOkay handler
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
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
22  *
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.
27  *
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.
32  *
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/>.
35  */
36 class RequestNodeListAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45
46                 // Init array
47                 $this->searchData = array(
48                         XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
49                 );
50
51                 // Set handler name
52                 $this->setHandlerName('request_node_list_answer_okay');
53         }
54
55         /**
56          * Creates an instance of this class
57          *
58          * @return      $handlerInstance        An instance of a HandleableMessage class
59          */
60         public final static function createRequestNodeListAnswerOkayHandler () {
61                 // Get new instance
62                 $handlerInstance = new RequestNodeListAnswerOkayHandler();
63
64                 // Return the prepared instance
65                 return $handlerInstance;
66         }
67
68         /**
69          * Handles given message data array
70          *
71          * @param       $messageData            An array of message data
72          * @param       $packageInstance        An instance of a Receivable class
73          * @return      void
74          * @throws      NodeSessionIdVerficationException       If the provided session id is not matching
75          * @todo        Do some more here: Handle karma, et cetera?
76          */
77         public function handleAnswerMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
78                 // Make sure node-list is found in array
79                 assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
80
81                 // Save node list
82                 $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
83
84                 // Make sure it is completely decoded
85                 assert(is_array($nodeList));
86
87                 // ... and remove it as it should not be included now
88                 unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
89
90                 // Write node list to DHT
91                 DhtObjectFactory::createDhtInstance('node')->insertNodeList($nodeList);
92
93                 /*
94                  * Query DHT and force update (which will throw an exception if the
95                  * node is not found).
96                  */
97                 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageInstance($messageData, $this, TRUE);
98
99                 // Prepare next message ("hello" message to all returned nodes)
100                 //$this->prepareNextMessage($messageData, $packageInstance);
101         }
102
103         /**
104          * Initializes configuration data from given message data array
105          *
106          * The following array is being handled over:
107          *
108          *   session-id    => aaabbbcccdddeeefff123456789
109          *   node-list     => aabb:ccdd:eeff
110          *   answer-status => OKAY
111          *   message_type  => request_node_list_answer
112          *
113          * @param       $messageData    An array with all message data
114          * @return      void
115          * @todo        0% done
116          */
117         protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
118                 $this->partialStub('Please implement this method.');
119         }
120
121         /**
122          * Removes configuration data with given message data array from global
123          * configuration. For content of $messageData see method comment above.
124          *
125          * @param       $messageData    An array with all message data
126          * @return      void
127          * @todo        0% done
128          */
129         protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
130                 $this->partialStub('Please implement this method.');
131         }
132 }
133
134 // [EOF]
135 ?>