]> git.mxchange.org Git - hub.git/blob - application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php
Updated 'core'.
[hub.git] / application / hub / main / handler / answer-status / requests / class_RequestNodeListAnswerOkayHandler.php
1 <?php
2 /**
3  * A RequestNodeListAnswerOkay handler
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
25         /**
26          * Protected constructor
27          *
28          * @return      void
29          */
30         protected function __construct () {
31                 // Call parent constructor
32                 parent::__construct(__CLASS__);
33
34                 // Init array
35                 $this->searchData = array(
36                         XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
37                 );
38
39                 // Set handler name
40                 $this->setHandlerName('request_node_list_answer_okay');
41         }
42
43         /**
44          * Creates an instance of this class
45          *
46          * @return      $handlerInstance        An instance of a HandleableMessage class
47          */
48         public final static function createRequestNodeListAnswerOkayHandler () {
49                 // Get new instance
50                 $handlerInstance = new RequestNodeListAnswerOkayHandler();
51
52                 // Return the prepared instance
53                 return $handlerInstance;
54         }
55
56         /**
57          * Handles given message data array
58          *
59          * @param       $messageData            An array of message data
60          * @param       $packageInstance        An instance of a Receivable class
61          * @return      void
62          * @throws      NodeSessionIdVerficationException       If the provided session id is not matching
63          * @todo        Do some more here: Handle karma, et cetera?
64          */
65         public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
66                 // Make sure node-list is found in array
67                 assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
68
69                 // Save node list
70                 $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
71
72                 // Make sure it is completely decoded
73                 assert(is_array($nodeList));
74
75                 // ... and remove it as it should not be included now
76                 unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
77
78                 // Write node list to DHT
79                 $this->getDhtInstance()->insertNodeList($nodeList);
80
81                 /*
82                  * Query DHT and force update (which will throw an exception if the
83                  * node is not found).
84                  */
85                 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
86
87                 // Prepare next message ("hello" message to all returned nodes)
88                 //$this->prepareNextMessage($messageData, $packageInstance);
89         }
90
91         /**
92          * Initializes configuration data from given message data array
93          *
94          * The following array is being handled over:
95          *
96          *   session-id    => aaabbbcccdddeeefff123456789
97          *   node-list     => aabb:ccdd:eeff
98          *   answer-status => OKAY
99          *   message_type  => request_node_list_answer
100          *
101          * @param       $messageData    An array with all message data
102          * @return      void
103          * @todo        0% done
104          */
105         protected function initMessageConfigurationData (array $messageData) {
106                 $this->partialStub('Please implement this method.');
107         }
108
109         /**
110          * Removes configuration data with given message data array from global
111          * configuration. For content of $messageData see method comment above.
112          *
113          * @param       $messageData    An array with all message data
114          * @return      void
115          * @todo        0% done
116          */
117         protected function removeMessageConfigurationData (array $messageData) {
118                 $this->partialStub('Please implement this method.');
119         }
120 }
121
122 // [EOF]
123 ?>