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