From 9003ce95fc63106e09fcb81f05c78e6a88079b21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 4 Dec 2020 05:11:40 +0100 Subject: [PATCH] Continued: - got rid of deprecated message<->config copying stuff, it should be done more naturally MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../classes/dht/node/class_NodeDhtFacade.php | 4 +- .../handler/chunks/class_ChunkHandler.php | 6 +- ...lass_NodeAnnouncementAnswerOkayHandler.php | 42 --------- ...class_RequestNodeListAnswerOkayHandler.php | 32 ------- .../handler/data/class_BaseDataHandler.php | 50 ----------- .../class_NodeMessageAnnouncementHandler.php | 84 +++--------------- ...s_NodeMessageAnnouncementAnswerHandler.php | 49 ++--------- ...s_NodeMessageDhtBootstrapAnswerHandler.php | 42 ++------- ...odeMessageRequestNodeListAnswerHandler.php | 37 ++------ .../class_NodeMessageDhtBootstrapHandler.php | 87 ++----------------- ...lass_NodeMessageRequestNodeListHandler.php | 72 +-------------- .../class_NodeMessageSelfConnectHandler.php | 26 ------ .../package/class_NetworkPackageHandler.php | 2 +- .../lists/recipient/class_RecipientList.php | 6 +- 14 files changed, 51 insertions(+), 488 deletions(-) diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index c44e1159a..256877953 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -439,7 +439,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { $current = $resultInstance->current(); // Add instance to recipient list - /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: current=%s', print_r($current, TRUE))); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: current=%s', print_r($current, TRUE))); array_push($recipients, $current); // Advanced to next entry @@ -491,7 +491,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { $current = $resultInstance->current(); // Add instance to recipient list - /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: current=%s', print_r($current, TRUE))); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: current=%s', print_r($current, TRUE))); array_push($recipients, $current); // Advanced to next entry diff --git a/application/hub/classes/handler/chunks/class_ChunkHandler.php b/application/hub/classes/handler/chunks/class_ChunkHandler.php index de5cac418..e295acd52 100644 --- a/application/hub/classes/handler/chunks/class_ChunkHandler.php +++ b/application/hub/classes/handler/chunks/class_ChunkHandler.php @@ -459,7 +459,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera * @return $isValid Whether the final (last) chunk is valid * @throws UnexpectedValueException If some unexpected value was found */ - private function isValidFinalChunk (array $chunks) { + private function isFinalChunkValid (array $chunks) { // Default is all fine /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks))); $isValid = TRUE; @@ -472,7 +472,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk); // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk=%s,chunkSplits=%s', $chunks[count($chunks) - 1], print_r($chunkSplits, TRUE))); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk=%s,chunkSplits=%s', $chunks[count($chunks) - 1], print_r($chunkSplits, TRUE))); if (count($chunkSplits) != 3) { // Must be 3 elements exact throw new UnexpectedValueException(sprintf('chunk=%s has %d splits, must be exact 3.', $chunk, count($chunkSplits))); @@ -504,7 +504,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks))); try { // Validate final chunk - $this->isValidFinalChunk($chunks); + $this->isFinalChunkValid($chunks); } catch (AssertionException $e) { // Last chunk is not valid throw new FinalChunkVerificationException(array($this, $chunks, $e), self::EXCEPTION_FINAL_CHUNK_VERIFICATION); diff --git a/application/hub/classes/handler/data/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php b/application/hub/classes/handler/data/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php index 8face5026..7e49a7778 100644 --- a/application/hub/classes/handler/data/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php +++ b/application/hub/classes/handler/data/answer-status/announcement/class_NodeAnnouncementAnswerOkayHandler.php @@ -107,46 +107,4 @@ class NodeAnnouncementAnswerOkayHandler extends BaseAnswerStatusHandler implemen $this->prepareNextMessage($messageInstance, $handlerInstance); } - /** - * Initializes configuration data from given message data array - * - * The following array is being handled over: - * - * my-external-address => 1.2.3.4 - * my-internal-address => 5.6.7.8 - * my-status => reachable - * my-node-id => aaabbbcccdddeeefff123456789 - * my-session-id => aaabbbcccdddeeefff123456789 - * my-tcp-port => 9060 - * my-udp-port => 9060 - * answer-status => OKAY - * message_type => announcement_answer - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Get node instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-MESSAGE-HANDLER: Creating node instance ...'); - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Get an array of all accepted object types - $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); - - // Add missing (temporary) configuration 'accepted_object_types' - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); - } - - /** - * Removes configuration data with given message data array from global - * configuration. For content of $messageInstance see method comment above. - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // Remove temporay configuration - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ACCEPTED_OBJECTS); - } - } diff --git a/application/hub/classes/handler/data/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php b/application/hub/classes/handler/data/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php index c0bcab027..9c99343e8 100644 --- a/application/hub/classes/handler/data/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php +++ b/application/hub/classes/handler/data/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php @@ -98,36 +98,4 @@ class RequestNodeListAnswerOkayHandler extends BaseAnswerStatusHandler implement // @TODO $this->prepareNextMessage($messageInstance, $handlerInstance); } - /** - * Initializes configuration data from given message data array - * - * The following array is being handled over: - * - * session-id => aaabbbcccdddeeefff123456789 - * node-list => aabb:ccdd:eeff - * answer-status => OKAY - * message_type => request_node_list_answer - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @todo 0% done - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - $this->partialStub('Please implement this method.'); - } - - /** - * Removes configuration data with given message data array from global - * configuration. For content of $messageInstance see method comment above. - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @todo 0% done - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - $this->partialStub('Please implement this method.'); - } } - -// [EOF] -?> diff --git a/application/hub/classes/handler/data/class_BaseDataHandler.php b/application/hub/classes/handler/data/class_BaseDataHandler.php index c452b7425..2f541a58d 100644 --- a/application/hub/classes/handler/data/class_BaseDataHandler.php +++ b/application/hub/classes/handler/data/class_BaseDataHandler.php @@ -51,17 +51,6 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { */ protected $messageDataElements = []; - /** - * Array for translating message data elements (other node's data mostly) - * into configuration elements. - */ - protected $messageToConfig = []; - - /** - * Array for copying configuration entries - */ - protected $configCopy = []; - /** * Protected constructor * @@ -120,12 +109,6 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { // Load descriptor XML $helperInstance->loadDescriptorXml($nodeInstance); - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageInstance); - // Compile any configuration variables $helperInstance->getTemplateInstance()->compileConfigInVariables(); @@ -133,11 +116,6 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-DATA-HANDLER: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString())); $helperInstance->sendPackage($nodeInstance); - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageInstance); - // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DATA-HANDLER: Answer message has been prepared.'); } @@ -162,12 +140,6 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { // Load descriptor XML $helperInstance->loadDescriptorXml($nodeInstance); - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageInstance); - // Compile any configuration variables $helperInstance->getTemplateInstance()->compileConfigInVariables(); @@ -175,30 +147,8 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString())); $helperInstance->sendPackage($nodeInstance); - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageInstance); - // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-DATA-HANDLER:Next message has been prepared.'); } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - abstract protected function initMessageConfigurationData (DeliverableMessage $messageInstance); - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - abstract protected function removeMessageConfigurationData (DeliverableMessage $messageInstance); - } diff --git a/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php index f8718cde1..a52d142f3 100644 --- a/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -54,7 +54,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl $this->setHandlerName('message_announcement'); // Init message data array - $this->messageDataElements = array( + $this->messageDataElements = [ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, @@ -62,30 +62,27 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, - ); + ]; // Init message-data->configuration translation array - $this->messageToConfig = array( + /* + $this->messageToConfig = [ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => 'your_node_id', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash', - ); - - // Init config-copy array - $this->configCopy = array( - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash', - ); + ]; + */ // Init array - $this->searchData = array( + $this->searchData = [ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS - ); + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, + ]; } /** @@ -152,61 +149,4 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // "Walk" throught the translation array - /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: messageInstance=' . print_r($messageInstance, TRUE)); - foreach ($this->messageToConfig as $messageKey => $configKey) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]); - - // Set the element in configuration - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry($configKey, $messageData[$messageKey]); - } // END - foreach - - // "Walk" throught the config-copy array - foreach ($this->configCopy as $targetKey => $sourceKey) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...'); - - // Copy from source to targetKey - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry($targetKey, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($sourceKey)); - } // END - foreach - - // Translate last exception into a status code - $statusCode = $this->getTranslatedStatusFromLastException(); - - // Set it in configuration (temporarily) - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS, $statusCode); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageData An instance of a DeliverableMessage class - * @return void - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // "Walk" throught the translation array again - foreach ($this->messageToConfig as $dummy => $configKey) { - // Now unset this configuration entry (to save some memory) - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry($configKey); - } // END - foreach - - // "Walk" throught the config-copy array again - foreach ($this->configCopy as $configKey => $dummy) { - // Now unset this configuration entry (to save some memory again) - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry($configKey); - } // END - foreach - - // Remove NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS as well - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS); - } - } diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index b489a9593..716c099f4 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -53,7 +53,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements $this->setHandlerName('message_announcement_answer'); // Init message data array - $this->messageDataElements = array( + $this->messageDataElements = [ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, @@ -61,32 +61,26 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, - ); + ]; // Init message-data->configuration translation array - $this->messageToConfig = array( /* + $this->messageToConfig = [ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id' XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash' + ]; */ - ); - - // Init config-copy array - $this->configCopy = array( - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash', - ); // Init array - $this->searchData = array( + $this->searchData = [ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, - ); + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH, + ]; } /** @@ -155,29 +149,4 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - } diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php index 587c1701e..fcb3afda4 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php @@ -62,27 +62,22 @@ class NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements ]; // Init message-data->configuration translation array - $this->messageToConfig = [ /* + $this->messageToConfig = [ @TODO Why commented out? XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id' - */ - ]; - - // Init config-copy array - $this->configCopy = [ - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id', ]; + */ // Init array $this->searchData = [ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, + XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS, + XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS, + XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, ]; } @@ -149,31 +144,4 @@ class NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } } - -// [EOF] -?> diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php index d18f99fc3..d3ab2e9b6 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php @@ -53,23 +53,23 @@ class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler impleme $this->setHandlerName('message_request_node_list_answer'); // Init message data array - $this->messageDataElements = array( + $this->messageDataElements = [ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID, XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, - ); + ]; // Init message-data->configuration translation array - $this->messageToConfig = array( /* + $this->messageToConfig = [ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id' + ]; */ - ); // Init search data array - $this->searchData = array( + $this->searchData = [ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID, - ); + ]; } /** @@ -144,29 +144,4 @@ class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler impleme } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - } diff --git a/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index 37fc745eb..6701a57ff 100644 --- a/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -63,24 +63,21 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl ]; // Init message-data->configuration translation array + /* $this->messageToConfig = [ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id' ]; - - // Init config-copy array - $this->configCopy = [ - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id', - ]; + */ // Init array - $this->searchData = array( + $this->searchData = [ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, - ); + XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS, + XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS, + XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, + ]; } /** @@ -142,74 +139,4 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // "Walk" throught the translation array - /* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: messageInstance=' . print_r($messageInstance, TRUE)); - foreach ($this->messageToConfig as $messageKey => $configKey) { - // Set the element in configuration - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]); - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry($configKey, $messageData[$messageKey]); - } // END - foreach - - // "Walk" throught the config-copy array - foreach ($this->configCopy as $targetKey => $sourceKey) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...'); - - // Copy from source to target key - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry($targetKey, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($sourceKey)); - } // END - foreach - - // Translate last exception into a status code - $statusCode = $this->getTranslatedStatusFromLastException(); - - // Set it in configuration (temporarily) - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS, $statusCode); - - /* - * Use the DHT instance to get a list of recipients. This means that all - * DHT nodes that accept bootstrap requests are read from the DHT - * database. - */ - $nodeList = DhtObjectFactory::createDhtInstance('node')->findRecipientsByKey(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ACCEPT_BOOTSTRAP, 'Y'); - - // Make sure it is an array and has at least one entry - assert(is_array($nodeList)); - assert(count($nodeList) > 0); - - // Set it in configuration - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('dht_nodes', base64_encode(json_encode($nodeList))); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // "Walk" throught the translation array again - foreach ($this->messageToConfig as $dummy => $configKey) { - // Now unset this configuration entry (to save some memory) - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry($configKey); - } // END - foreach - - // "Walk" throught the config-copy array again - foreach ($this->configCopy as $configKey => $dummy) { - // Now unset this configuration entry (to save some memory again) - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry($configKey); - } // END - foreach - - // Remove temporary "special" values as well - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS); - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry('dht_nodes'); - } - } diff --git a/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php b/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php index 52b13ac86..ab644e7ad 100644 --- a/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -54,18 +54,14 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha $this->setHandlerName('message_request_node_list'); // Init message data array - $this->messageDataElements = array( + $this->messageDataElements = [ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES, - ); - - // Init config-copy array - $this->configCopy = array( - ); + ]; // Init search data array - $this->searchData = array( + $this->searchData = [ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID, - ); + ]; } /** @@ -131,64 +127,4 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha } // END - foreach } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: messageInstance=' . print_r($messageInstance, TRUE)); - - // "Walk" throught the config-copy array - foreach ($this->configCopy as $targetKey => $sourceKey) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...'); - - // Copy from source to targetKey - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry($targetKey, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($sourceKey)); - } // END - foreach - - // Query local DHT for nodes except given session id - $nodeList = DhtObjectFactory::createDhtInstance('node')->queryLocalNodeListExceptByMessageInstance( - $messageInstance, - $this, - XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID, - XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES, - BaseHubNode::OBJECT_LIST_SEPARATOR - ); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Got a node list of ' . count($nodeList) . ' entry/-ies back.'); - - // Set it serialized in configuration (temporarily) - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('node_list', base64_encode(json_encode($nodeList))); - - // Translate last exception into a status code - $statusCode = $this->getTranslatedStatusFromLastException(); - - // Set it in configuration (temporarily) - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS, $statusCode); - } - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // "Walk" throught the config-copy array again - foreach ($this->configCopy as $configKey => $dummy) { - // Now unset this configuration entry (to save some memory again) - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry($configKey); - } // END - foreach - - // Remove answer status/node list as well - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_ANSWER_STATUS); - FrameworkBootstrap::getConfigurationInstance()->unsetConfigEntry('node_list'); - } - } diff --git a/application/hub/classes/handler/data/message-types/self-connect/class_NodeMessageSelfConnectHandler.php b/application/hub/classes/handler/data/message-types/self-connect/class_NodeMessageSelfConnectHandler.php index 34a5bceb0..605dc05a8 100644 --- a/application/hub/classes/handler/data/message-types/self-connect/class_NodeMessageSelfConnectHandler.php +++ b/application/hub/classes/handler/data/message-types/self-connect/class_NodeMessageSelfConnectHandler.php @@ -106,30 +106,4 @@ class NodeMessageSelfConnectHandler extends BaseMessageHandler implements Handle throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } - /** - * Initializes configuration data from given message data array - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function initMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method! - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Removes configuration data with given message data array from global configuration - * - * @param $messageInstance An instance of a DeliverableMessage class - * @return void - * @throws UnsupportedOperationException If this method is called - */ - protected function removeMessageConfigurationData (DeliverableMessage $messageInstance) { - // Please don't call this method! - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } } - -// [EOF] -?> diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index b7e537db7..cc1ce6d1b 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -1622,7 +1622,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Generate the hash of comparing it //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE))); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $packageInstance->__toString(), $packageInstance->getSenderId(), $packageInstance->getSenderPrivateKeyHash())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $packageInstance->__toString(), $packageInstance->getSenderId(), $packageInstance->getSenderPrivateKeyHash())); if (empty($packageInstance->getSenderId())) { // Invalid $packageInstance throw new InvalidArgumentException('packageInstance does not contain senderId'); diff --git a/application/hub/classes/lists/recipient/class_RecipientList.php b/application/hub/classes/lists/recipient/class_RecipientList.php index 8b1e7010a..de2c3f61c 100644 --- a/application/hub/classes/lists/recipient/class_RecipientList.php +++ b/application/hub/classes/lists/recipient/class_RecipientList.php @@ -76,9 +76,7 @@ class RecipientList extends BaseList implements Listable, Registerable { */ public function clearList () { // Clear both groups - $this->clearGroups(array('unl', 'session_id')); + $this->clearGroups(['unl', 'session_id']); } -} -// [EOF] -?> +} -- 2.39.5