3 namespace Hub\Handler\Node\Announcement\Answer;
5 // Import application-specific stuff
6 use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
7 use Hub\Factory\Dht\DhtObjectFactory;
8 use Hub\Factory\Node\NodeObjectFactory;
9 use Hub\Network\Receive\Receivable;
10 use Hub\Node\BaseHubNode;
12 // Import framework stuff
13 use CoreFramework\Registry\Registerable;
14 use CoreFramework\Registry\Registry;
17 * A AnnouncementAnswerOkay handler
19 * @author Roland Haeder <webmaster@shipsimu.org>
21 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.shipsimu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 class NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
40 * Protected constructor
44 protected function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
49 $this->searchData = array(
50 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
51 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
55 $this->setHandlerName('announcement_answer_okay');
59 * Creates an instance of this class
61 * @return $handlerInstance An instance of a HandleableMessage class
63 public final static function createNodeAnnouncementAnswerOkayHandler () {
65 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
67 // Return the prepared instance
68 return $handlerInstance;
72 * Handles given message data array
74 * @param $messageData An array of message data
75 * @param $packageInstance An instance of a Receivable class
77 * @todo Do some more here: Handle karma, et cetera?
79 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
81 * Query DHT and force update (which will throw an exception if the
84 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
86 // Get handler instance
87 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
89 // Generate DHT bootstrap task
90 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
92 // Register it as well
93 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
95 // Get the node instance
96 $nodeInstance = NodeObjectFactory::createNodeInstance();
99 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
101 // Prepare next message
102 $this->prepareNextMessage($messageData, $packageInstance);
106 * Initializes configuration data from given message data array
108 * The following array is being handled over:
110 * my-external-address => 1.2.3.4
111 * my-internal-address => 5.6.7.8
112 * my-status => reachable
113 * my-node-id => aaabbbcccdddeeefff123456789
114 * my-session-id => aaabbbcccdddeeefff123456789
115 * my-tcp-port => 9060
116 * my-udp-port => 9060
117 * answer-status => OKAY
118 * message_type => announcement_answer
120 * @param $messageData An array with all message data
123 protected function initMessageConfigurationData (array $messageData) {
125 $nodeInstance = NodeObjectFactory::createNodeInstance();
127 // Get an array of all accepted object types
128 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
130 // Add missing (temporary) configuration 'accepted_object_types'
131 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
135 * Removes configuration data with given message data array from global
136 * configuration. For content of $messageData see method comment above.
138 * @param $messageData An array with all message data
141 protected function removeMessageConfigurationData (array $messageData) {
142 // Remove temporay configuration
143 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);