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