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