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