3 namespace Hub\Handler\Node\Announcement\Answer;
5 // Import application-specific stuff
6 use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
7 use Hub\Factory\Node\NodeObjectFactory;
8 use Hub\Network\Receive\Receivable;
9 use Hub\Node\BaseHubNode;
11 // Import framework stuff
12 use CoreFramework\Registry\Registerable;
13 use CoreFramework\Registry\Registry;
16 * A AnnouncementAnswerOkay handler
18 * @author Roland Haeder <webmaster@shipsimu.org>
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.shipsimu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
39 * Protected constructor
43 protected function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
48 $this->searchData = array(
49 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
50 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
54 $this->setHandlerName('announcement_answer_okay');
58 * Creates an instance of this class
60 * @return $handlerInstance An instance of a HandleableMessage class
62 public final static function createNodeAnnouncementAnswerOkayHandler () {
64 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
66 // Return the prepared instance
67 return $handlerInstance;
71 * Handles given message data array
73 * @param $messageData An array of message data
74 * @param $packageInstance An instance of a Receivable class
76 * @todo Do some more here: Handle karma, et cetera?
78 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
80 * Query DHT and force update (which will throw an exception if the
83 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
85 // Get handler instance
86 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
88 // Generate DHT bootstrap task
89 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
91 // Register it as well
92 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
94 // Get the node instance
95 $nodeInstance = NodeObjectFactory::createNodeInstance();
98 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
100 // Prepare next message
101 $this->prepareNextMessage($messageData, $packageInstance);
105 * Initializes configuration data from given message data array
107 * The following array is being handled over:
109 * my-external-address => 1.2.3.4
110 * my-internal-address => 5.6.7.8
111 * my-status => reachable
112 * my-node-id => aaabbbcccdddeeefff123456789
113 * my-session-id => aaabbbcccdddeeefff123456789
114 * my-tcp-port => 9060
115 * my-udp-port => 9060
116 * answer-status => OKAY
117 * message_type => announcement_answer
119 * @param $messageData An array with all message data
122 protected function initMessageConfigurationData (array $messageData) {
124 $nodeInstance = NodeObjectFactory::createNodeInstance();
126 // Get an array of all accepted object types
127 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
129 // Add missing (temporary) configuration 'accepted_object_types'
130 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
134 * Removes configuration data with given message data array from global
135 * configuration. For content of $messageData see method comment above.
137 * @param $messageData An array with all message data
140 protected function removeMessageConfigurationData (array $messageData) {
141 // Remove temporay configuration
142 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);