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