]> git.mxchange.org Git - hub.git/blob
3494284e799a6faf676f81916f3630db715eaefa
[hub.git] /
1 <?php
2 // Own namespace
3 namespace Hub\Handler\Node\Announcement\Answer;
4
5 // Import application-specific stuff
6 use Hub\Factory\Node\NodeObjectFactory;
7 use Hub\Network\Receive\Receivable;
8 use Hub\Node\BaseHubNode;
9
10 // Import framework stuff
11 use CoreFramework\Registry\Registerable;
12 use CoreFramework\Registry\Registry;
13
14 /**
15  * A AnnouncementAnswerOkay handler
16  *
17  * @author              Roland Haeder <webmaster@shipsimu.org>
18  * @version             0.0.0
19  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler 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                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
49                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
50                 );
51
52                 // Set handler name
53                 $this->setHandlerName('announcement_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 createNodeAnnouncementAnswerOkayHandler () {
62                 // Get new instance
63                 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
64
65                 // Return the prepared instance
66                 return $handlerInstance;
67         }
68
69         /**
70          * Handles given message data array
71          *
72          * @param       $messageData            An array of message data
73          * @param       $packageInstance        An instance of a Receivable class
74          * @return      void
75          * @todo        Do some more here: Handle karma, et cetera?
76          */
77         public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
78                 /*
79                  * Query DHT and force update (which will throw an exception if the
80                  * node is not found).
81                  */
82                 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
83
84                 // Get handler instance
85                 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
86
87                 // Generate DHT bootstrap task
88                 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
89
90                 // Register it as well
91                 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
92
93                 // Get the node instance
94                 $nodeInstance = NodeObjectFactory::createNodeInstance();
95
96                 // Change state
97                 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
98
99                 // Prepare next message
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          *   my-external-address => 1.2.3.4
109          *   my-internal-address => 5.6.7.8
110          *   my-status           => reachable
111          *   my-node-id          => aaabbbcccdddeeefff123456789
112          *   my-session-id       => aaabbbcccdddeeefff123456789
113          *   my-tcp-port         => 9060
114          *   my-udp-port         => 9060
115          *   answer-status       => OKAY
116          *   message_type        => announcement_answer
117          *
118          * @param       $messageData    An array with all message data
119          * @return      void
120          */
121         protected function initMessageConfigurationData (array $messageData) {
122                 // Get node instance
123                 $nodeInstance = NodeObjectFactory::createNodeInstance();
124
125                 // Get an array of all accepted object types
126                 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
127
128                 // Add missing (temporary) configuration 'accepted_object_types'
129                 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
130         }
131
132         /**
133          * Removes configuration data with given message data array from global
134          * configuration. For content of $messageData see method comment above.
135          *
136          * @param       $messageData    An array with all message data
137          * @return      void
138          */
139         protected function removeMessageConfigurationData (array $messageData) {
140                 // Remove temporay configuration
141                 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
142         }
143 }
144
145 // [EOF]
146 ?>