]> git.mxchange.org Git - hub.git/blob
5addf3415f1ae16d3afa975a4be2c833f325a01e
[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
8 // Import framework stuff
9 use CoreFramework\Registry\Registry;
10
11 /**
12  * A AnnouncementAnswerOkay handler
13  *
14  * @author              Roland Haeder <webmaster@shipsimu.org>
15  * @version             0.0.0
16  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
17  * @license             GNU GPL 3.0 or any newer version
18  * @link                http://www.shipsimu.org
19  *
20  * This program is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation, either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
32  */
33 class NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42
43                 // Init array
44                 $this->searchData = array(
45                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
46                         XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
47                 );
48
49                 // Set handler name
50                 $this->setHandlerName('announcement_answer_okay');
51         }
52
53         /**
54          * Creates an instance of this class
55          *
56          * @return      $handlerInstance        An instance of a HandleableMessage class
57          */
58         public final static function createNodeAnnouncementAnswerOkayHandler () {
59                 // Get new instance
60                 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
61
62                 // Return the prepared instance
63                 return $handlerInstance;
64         }
65
66         /**
67          * Handles given message data array
68          *
69          * @param       $messageData            An array of message data
70          * @param       $packageInstance        An instance of a Receivable class
71          * @return      void
72          * @todo        Do some more here: Handle karma, et cetera?
73          */
74         public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
75                 /*
76                  * Query DHT and force update (which will throw an exception if the
77                  * node is not found).
78                  */
79                 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
80
81                 // Get handler instance
82                 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
83
84                 // Generate DHT bootstrap task
85                 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
86
87                 // Register it as well
88                 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
89
90                 // Get the node instance
91                 $nodeInstance = NodeObjectFactory::createNodeInstance();
92
93                 // Change state
94                 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
95
96                 // Prepare next message
97                 $this->prepareNextMessage($messageData, $packageInstance);
98         }
99
100         /**
101          * Initializes configuration data from given message data array
102          *
103          * The following array is being handled over:
104          *
105          *   my-external-address => 1.2.3.4
106          *   my-internal-address => 5.6.7.8
107          *   my-status           => reachable
108          *   my-node-id          => aaabbbcccdddeeefff123456789
109          *   my-session-id       => aaabbbcccdddeeefff123456789
110          *   my-tcp-port         => 9060
111          *   my-udp-port         => 9060
112          *   answer-status       => OKAY
113          *   message_type        => announcement_answer
114          *
115          * @param       $messageData    An array with all message data
116          * @return      void
117          */
118         protected function initMessageConfigurationData (array $messageData) {
119                 // Get node instance
120                 $nodeInstance = NodeObjectFactory::createNodeInstance();
121
122                 // Get an array of all accepted object types
123                 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
124
125                 // Add missing (temporary) configuration 'accepted_object_types'
126                 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
127         }
128
129         /**
130          * Removes configuration data with given message data array from global
131          * configuration. For content of $messageData see method comment above.
132          *
133          * @param       $messageData    An array with all message data
134          * @return      void
135          */
136         protected function removeMessageConfigurationData (array $messageData) {
137                 // Remove temporay configuration
138                 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
139         }
140 }
141
142 // [EOF]
143 ?>