3 * A AnnouncementAnswerOkay handler
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
26 * Protected constructor
30 protected function __construct () {
31 // Call parent constructor
32 parent::__construct(__CLASS__);
35 $this->searchData = array(
36 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
37 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
41 $this->setHandlerName('announcement_answer_okay');
45 * Creates an instance of this class
47 * @return $handlerInstance An instance of a HandleableMessage class
49 public final static function createAnnouncementAnswerOkayHandler () {
51 $handlerInstance = new AnnouncementAnswerOkayHandler();
53 // Return the prepared instance
54 return $handlerInstance;
58 * Handles given message data array
60 * @param $messageData An array of message data
61 * @param $packageInstance An instance of a Receivable class
63 * @todo Do some more here: Handle karma, et cetera?
65 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
67 * Query DHT and force update (which will throw an exception if the
70 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
72 // Get handler instance
73 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
75 // Generate DHT bootstrap task
76 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
78 // Register it as well
79 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
81 // Get the node instance
82 $nodeInstance = NodeObjectFactory::createNodeInstance();
85 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
87 // Prepare next message
88 $this->prepareNextMessage($messageData, $packageInstance);
92 * Initializes configuration data from given message data array
94 * The following array is being handled over:
96 * my-external-address => 1.2.3.4
97 * my-internal-address => 5.6.7.8
98 * my-status => reachable
99 * my-node-id => aaabbbcccdddeeefff123456789
100 * my-session-id => aaabbbcccdddeeefff123456789
101 * my-tcp-port => 9060
102 * my-udp-port => 9060
103 * answer-status => OKAY
104 * message_type => announcement_answer
106 * @param $messageData An array with all message data
109 protected function initMessageConfigurationData (array $messageData) {
111 $nodeInstance = NodeObjectFactory::createNodeInstance();
113 // Get an array of all accepted object types
114 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
116 // Add missing (temporary) configuration 'accepted_object_types'
117 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
121 * Removes configuration data with given message data array from global
122 * configuration. For content of $messageData see method comment above.
124 * @param $messageData An array with all message data
127 protected function removeMessageConfigurationData (array $messageData) {
128 // Remove temporay configuration
129 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);