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