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