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\Registerable;
12 use CoreFramework\Registry\Registry;
15 * A AnnouncementAnswerOkay handler
17 * @author Roland Haeder <webmaster@shipsimu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
47 $this->searchData = array(
48 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
49 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
53 $this->setHandlerName('announcement_answer_okay');
57 * Creates an instance of this class
59 * @return $handlerInstance An instance of a HandleableMessage class
61 public final static function createNodeAnnouncementAnswerOkayHandler () {
63 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
65 // Return the prepared instance
66 return $handlerInstance;
70 * Handles given message data array
72 * @param $messageData An array of message data
73 * @param $packageInstance An instance of a Receivable class
75 * @todo Do some more here: Handle karma, et cetera?
77 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
79 * Query DHT and force update (which will throw an exception if the
82 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
84 // Get handler instance
85 $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
87 // Generate DHT bootstrap task
88 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
90 // Register it as well
91 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
93 // Get the node instance
94 $nodeInstance = NodeObjectFactory::createNodeInstance();
97 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
99 // Prepare next message
100 $this->prepareNextMessage($messageData, $packageInstance);
104 * Initializes configuration data from given message data array
106 * The following array is being handled over:
108 * my-external-address => 1.2.3.4
109 * my-internal-address => 5.6.7.8
110 * my-status => reachable
111 * my-node-id => aaabbbcccdddeeefff123456789
112 * my-session-id => aaabbbcccdddeeefff123456789
113 * my-tcp-port => 9060
114 * my-udp-port => 9060
115 * answer-status => OKAY
116 * message_type => announcement_answer
118 * @param $messageData An array with all message data
121 protected function initMessageConfigurationData (array $messageData) {
123 $nodeInstance = NodeObjectFactory::createNodeInstance();
125 // Get an array of all accepted object types
126 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
128 // Add missing (temporary) configuration 'accepted_object_types'
129 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
133 * Removes configuration data with given message data array from global
134 * configuration. For content of $messageData see method comment above.
136 * @param $messageData An array with all message data
139 protected function removeMessageConfigurationData (array $messageData) {
140 // Remove temporay configuration
141 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);