3 * A AnnouncementAnswerOkay handler
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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,
38 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
42 $this->setHandlerName('announcement_answer_okay');
46 * Creates an instance of this class
48 * @return $handlerInstance An instance of a HandleableMessage class
50 public final static function createAnnouncementAnswerOkayHandler () {
52 $handlerInstance = new AnnouncementAnswerOkayHandler();
54 // Return the prepared instance
55 return $handlerInstance;
59 * Handles given message data array
61 * @param $messageData An array of message data
62 * @param $packageInstance An instance of a Receivable class
64 * @todo Do some more here: Handle karma, et cetera?
66 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
68 * Query DHT and force update (which will throw an exception if the
71 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
73 // Get handler instance
74 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
76 // Generate DHT bootstrap task
77 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
79 // Register it as well
80 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
82 // Get the node instance
83 $nodeInstance = NodeObjectFactory::createNodeInstance();
86 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
88 // Prepare next message
89 $this->prepareNextMessage($messageData, $packageInstance);
93 * Initializes configuration data from given message data array
95 * The following array is being handled over:
97 * my-external-address => 1.2.3.4
98 * my-internal-address => 5.6.7.8
99 * my-status => reachable
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);