3 namespace Org\Shipsimu\Hub\Handler\Node\Announcement\Answer;
5 // Import application-specific stuff
6 use Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
7 use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory;
8 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
9 use Org\Shipsimu\Hub\Handler\Message\HandleableMessage;
10 use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
11 use Org\Shipsimu\Hub\Network\Receive\Receivable;
12 use Org\Shipsimu\Hub\Node\BaseHubNode;
13 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Announcement\XmlAnnouncementAnswerTemplateEngine;
15 // Import framework stuff
16 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
17 use Org\Mxchange\CoreFramework\Registry\Registerable;
20 * A AnnouncementAnswerOkay handler
22 * @author Roland Haeder <webmaster@shipsimu.org>
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
25 * @license GNU GPL 3.0 or any newer version
26 * @link http://www.shipsimu.org
28 * This program is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program. If not, see <http://www.gnu.org/licenses/>.
41 class NodeAnnouncementAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
43 * Protected constructor
47 protected function __construct () {
48 // Call parent constructor
49 parent::__construct(__CLASS__);
52 $this->searchData = array(
53 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
54 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
58 $this->setHandlerName('announcement_answer_okay');
62 * Creates an instance of this class
64 * @return $handlerInstance An instance of a HandleableMessage class
66 public final static function createNodeAnnouncementAnswerOkayHandler () {
68 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
70 // Return the prepared instance
71 return $handlerInstance;
75 * Handles given message data array
77 * @param $messageInstance An instance of a DeliverableMessage class
78 * @param $packageInstance An instance of a Receivable class
80 * @todo Do some more here: Handle karma, et cetera?
82 public function handleAnswerMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
84 * Query DHT and force update (which will throw an exception if the
87 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageInstance($messageInstance, $this, TRUE);
89 // Get handler instance
90 $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler');
92 // Generate DHT bootstrap task
93 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
95 // Register it as well
96 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
98 // Get the node instance
99 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
100 $nodeInstance = NodeObjectFactory::createNodeInstance();
103 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
105 // Prepare next message
106 $this->prepareNextMessage($messageInstance, $packageInstance);
110 * Initializes configuration data from given message data array
112 * The following array is being handled over:
114 * my-external-address => 1.2.3.4
115 * my-internal-address => 5.6.7.8
116 * my-status => reachable
117 * my-node-id => aaabbbcccdddeeefff123456789
118 * my-session-id => aaabbbcccdddeeefff123456789
119 * my-tcp-port => 9060
120 * my-udp-port => 9060
121 * answer-status => OKAY
122 * message_type => announcement_answer
124 * @param $messageInstance An instance of a DeliverableMessage class
127 protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
129 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
130 $nodeInstance = NodeObjectFactory::createNodeInstance();
132 // Get an array of all accepted object types
133 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
135 // Add missing (temporary) configuration 'accepted_object_types'
136 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
140 * Removes configuration data with given message data array from global
141 * configuration. For content of $messageInstance see method comment above.
143 * @param $messageInstance An instance of a DeliverableMessage class
146 protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
147 // Remove temporay configuration
148 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);