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\Receive\Receivable;
11 use Org\Shipsimu\Hub\Node\BaseHubNode;
12 use Org\Shipsimu\Hub\Template\Engine\Xml\Answer\Announcement\XmlAnnouncementAnswerTemplateEngine;
14 // Import framework stuff
15 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
16 use Org\Mxchange\CoreFramework\Registry\Registerable;
19 * A AnnouncementAnswerOkay handler
21 * @author Roland Haeder <webmaster@shipsimu.org>
23 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
24 * @license GNU GPL 3.0 or any newer version
25 * @link http://www.shipsimu.org
27 * This program is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
40 class NodeAnnouncementAnswerOkayHandler extends BaseAnswerStatusHandler implements HandleableAnswerStatus, Registerable {
42 * Protected constructor
46 protected function __construct () {
47 // Call parent constructor
48 parent::__construct(__CLASS__);
51 $this->searchData = array(
52 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
53 XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
57 $this->setHandlerName('announcement_answer_okay');
61 * Creates an instance of this class
63 * @return $handlerInstance An instance of a HandleableMessage class
65 public final static function createNodeAnnouncementAnswerOkayHandler () {
67 $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
69 // Return the prepared instance
70 return $handlerInstance;
74 * Handles given message data array
76 * @param $messageData An array of message data
77 * @param $packageInstance An instance of a Receivable class
79 * @todo Do some more here: Handle karma, et cetera?
81 public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
83 * Query DHT and force update (which will throw an exception if the
86 DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
88 // Get handler instance
89 $handlerInstance = GenericRegistry::getRegistry()->getInstance('task_handler');
91 // Generate DHT bootstrap task
92 $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
94 // Register it as well
95 $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
97 // Get the node instance
98 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
99 $nodeInstance = NodeObjectFactory::createNodeInstance();
102 $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
104 // Prepare next message
105 $this->prepareNextMessage($messageData, $packageInstance);
109 * Initializes configuration data from given message data array
111 * The following array is being handled over:
113 * my-external-address => 1.2.3.4
114 * my-internal-address => 5.6.7.8
115 * my-status => reachable
116 * my-node-id => aaabbbcccdddeeefff123456789
117 * my-session-id => aaabbbcccdddeeefff123456789
118 * my-tcp-port => 9060
119 * my-udp-port => 9060
120 * answer-status => OKAY
121 * message_type => announcement_answer
123 * @param $messageData An array with all message data
126 protected function initMessageConfigurationData (array $messageData) {
128 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...');
129 $nodeInstance = NodeObjectFactory::createNodeInstance();
131 // Get an array of all accepted object types
132 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
134 // Add missing (temporary) configuration 'accepted_object_types'
135 $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
139 * Removes configuration data with given message data array from global
140 * configuration. For content of $messageData see method comment above.
142 * @param $messageData An array with all message data
145 protected function removeMessageConfigurationData (array $messageData) {
146 // Remove temporay configuration
147 $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);