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\Bootstrap\FrameworkBootstrap;
17 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
18 use Org\Mxchange\CoreFramework\Registry\Registerable;
21 * A AnnouncementAnswerOkay handler
23 * @author Roland Haeder <webmaster@shipsimu.org>
25 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
26 * @license GNU GPL 3.0 or any newer version
27 * @link http://www.shipsimu.org
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42 class NodeAnnouncementAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
53 $this->searchData = array(
54 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
55 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
59 $this->setHandlerName('announcement_answer_okay');
63 * Creates an instance of this class
65 * @return $handlerInstance An instance of a HandleableMessage class
67 public final static function createNodeAnnouncementAnswerOkayHandler () {
69 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
71 // Return the prepared instance
72 return $handlerInstance;
76 * Handles given message data array
78 * @param $messageInstance An instance of a DeliverableMessage class
79 * @param $packageInstance An instance of a Receivable class
81 * @todo Do some more here: Handle karma, et cetera?
83 public function handleAnswerMessageData (DeliverableMessage $messageInstance, Receivable $packageInstance) {
85 * Query DHT and force update (which will throw an exception if the
88 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageInstance($messageInstance, $this, TRUE);
90 // Get handler instance
91 $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler');
93 // Generate DHT bootstrap task
94 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
96 // Register it as well
97 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
99 // Get the node instance
100 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
101 $nodeInstance = NodeObjectFactory::createNodeInstance();
104 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
106 // Prepare next message
107 $this->prepareNextMessage($messageInstance, $packageInstance);
111 * Initializes configuration data from given message data array
113 * The following array is being handled over:
115 * my-external-address => 1.2.3.4
116 * my-internal-address => 5.6.7.8
117 * my-status => reachable
118 * my-node-id => aaabbbcccdddeeefff123456789
119 * my-session-id => aaabbbcccdddeeefff123456789
120 * my-tcp-port => 9060
121 * my-udp-port => 9060
122 * answer-status => OKAY
123 * message_type => announcement_answer
125 * @param $messageInstance An instance of a DeliverableMessage class
128 protected function initMessageConfigurationData (DeliverableMessage $messageInstance) {
130 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
131 $nodeInstance = NodeObjectFactory::createNodeInstance();
133 // Get an array of all accepted object types
134 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
136 // Add missing (temporary) configuration 'accepted_object_types'
137 FrameworkBootstrap::getConfigurationInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
141 * Removes configuration data with given message data array from global
142 * configuration. For content of $messageInstance see method comment above.
144 * @param $messageInstance An instance of a DeliverableMessage class
147 protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) {
148 // Remove temporay configuration
149 FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);