]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 03:47:42 +0000 (04:47 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 03:51:03 +0000 (04:51 +0100)
- package and message are different things, so there is no "new package arrived"
  but more decompressed XML
- renamed methods for better understanding them
- added missing config key
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/tasks/network/class_NetworkPackageReaderTask.php
application/hub/config.php
application/hub/interfaces/receiver/class_Receivable.php
core

index 3e6d1c5e15ce2c6414b37f99fd9242105d7efd5a..8e6115393237c580d899fd1def93c49b99dc56ad 100644 (file)
@@ -247,6 +247,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        const STACKER_NAME_DECODED_CHUNKED = 'package_chunked_decoded';
 
+       /**
+        * Stacker name for decompressed XML
+        */
+       const STACKER_NAME_PACKAGE_DECOMPRESSED_XML = 'package_decompressed_xml';
+
        /**************************************************************************
         *                     Stacker for incoming messages                      *
         **************************************************************************/
@@ -446,7 +451,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                        self::STACKER_NAME_DECODED_INCOMING,
                        self::STACKER_NAME_DECODED_HANDLED,
                        self::STACKER_NAME_DECODED_CHUNKED,
-                       self::STACKER_NAME_NEW_MESSAGE,
+                       self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML,
                        self::STACKER_NAME_PROCESSED_MESSAGE,
                        self::STACKER_NAME_OUTGOING_STREAM
                ), $forceReInit);
@@ -1463,7 +1468,6 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         * @throws      InvalidArgumentException        If the package content does not have expected amount of entries
-        * @throws      InvalidDataChecksumException    If the checksum doesn't match
         */
        public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) {
                // Is the package content set?
@@ -1503,20 +1507,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                // Checksum of the _decoded_ data
                $packageInstance->setContentChecksum($decodedContent[self::INDEX_CHECKSUM]);
 
-               // Is the checksum valid?
-               if (!$this->isChecksumValid($packageInstance)) {
-                       // Is not the same, so throw an exception here
-                       throw new InvalidDataChecksumException(array($this, $packageInstance), self::EXCEPTION_INVALID_DATA_CHECKSUM);
-               }
-
-               /*
-                * The checksum is the same, then it can be decompressed safely. The
-                * original message is at this point fully decoded.
-                */
+               // Decompress raw XML stream
                $packageInstance->setRawXml($this->getCompressorInstance()->decompressStream($packageInstance->getRawXml()));
 
                // And push it on the next stack
-               $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $packageInstance);
+               $this->getStackInstance()->pushNamed(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML, $packageInstance);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
@@ -1530,7 +1525,22 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
        public function isNewMessageArrived () {
                // Determine if the stack is not empty
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
-               $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_NEW_MESSAGE));
+               $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML));
+
+               // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hasArrived=%d - EXIT!', intval($hasArrived)));
+               return $hasArrived;
+       }
+
+       /**
+        * Checks whether decoded package's XML is pending for parsing
+        *
+        * @return      $hasArrived             Whether a new package has arrived for processing
+        */
+       public function isDecodedPackageXmlPending () {
+               // Determine if the stack is not empty
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+               $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML));
 
                // Return it
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hasArrived=%d - EXIT!', intval($hasArrived)));
@@ -1538,7 +1548,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
        }
 
        /**
-        * Handles newly arrived messages
+        * Handles newly arrived message
         *
         * @return      void
         * @throws      BadMethodCallException  If no new message has arrived
@@ -1555,30 +1565,30 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                }
 
                // Get it from the stacker, it is the full array with the decoded message
-               $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
+               $messageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
 
                // Generate the hash of comparing it
-               /* DEBUG-DIE: */ die(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()));
-               if (empty($packageInstance->getSenderId())) {
-                       // Invalid $packageInstance
-                       throw new InvalidArgumentException('packageInstance does not contain senderId');
-               } elseif (empty($packageInstance->getSenderPrivateKeyHash())) {
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: messageInstance=%s', __METHOD__, __LINE__, print_r($messageInstance, TRUE)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: messageInstance=%s,senderId=%s,senderPrivateKeyHash=%s', $messageInstance->__toString(), $messageInstance->getSenderId(), $messageInstance->getSenderPrivateKeyHash()));
+               if (empty($messageInstance->getSenderId())) {
+                       // Invalid $messageInstance
+                       throw new InvalidArgumentException('messageInstance does not contain senderId');
+               } elseif (empty($messageInstance->getSenderPrivateKeyHash())) {
                        // This needs fixing
                        throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
-               } elseif (!$this->isPackageHashValid($packageInstance)) {
+               } elseif (!$this->isPackageHashValid($messageInstance)) {
                        // Is not valid, so throw an exception here
-                       exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10));
+                       exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
                }
 
                // Now get a filter chain back from factory with given tags array
-               $chainInstance = PackageFilterChainFactory::createChainByTagsArray($packageInstance->getContentHash());
+               $chainInstance = PackageFilterChainFactory::createChainByTagsArray($messageInstance->getContentHash());
 
                /*
                 * Process the message through all filters, note that all other
-                * elements from $packageInstance are no longer needed.
+                * elements from $messageInstance are no longer needed.
                 */
-               $chainInstance->processMessage($packageInstance, $this);
+               $chainInstance->processMessage($messageInstance, $this);
 
                /*
                 * Post-processing of message data (this won't remove the message from
@@ -1590,6 +1600,47 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
        }
 
+       /**
+        * Handles package's decoded XML
+        *
+        * @return      void
+        * @throws      BadMethodCallException  If no new package has arrived
+        * @throws      InvalidArgumentException        If $packageInstance contains no senderId
+        * @throws      InvalidPrivateKeyHashException  If the private key-hash is empty
+        * @todo        Implement verification of all sent tags here?
+        */
+       public function handleDecodedPackageXml () {
+               // Make sure there is at least one package
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+               if (!$this->isDecodedPackageXmlPending()) {
+                       // Bad method call
+                       throw new BadMethodCallException('No package waiting XML parsing');
+               }
+
+               // Get it from the stacker, it is the full array with the decoded package (raw XML)
+               $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML);
+
+               // Generate the hash of comparing it
+               /* DEBUG-DIE: */ die(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()));
+               if (empty($packageInstance->getSenderId())) {
+                       // Invalid $packageInstance
+                       throw new InvalidArgumentException('packageInstance does not contain senderId');
+               } elseif (empty($packageInstance->getSenderPrivateKeyHash())) {
+                       // This needs fixing
+                       throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH);
+               } elseif (!$this->isPackageHashValid($packageInstance)) {
+                       // Is not valid, so throw an exception here
+                       exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL);
+               }
+
+               // Parse package's XML into a message instance
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
+       }
+
        /**
         * Checks whether a processed message is pending for "interpretation"
         *
index e9f87725dcb38ccc4979b858c3aac0087cae77e6..e315aa3bdf756985288071d1558bbe3ab460fb12 100644 (file)
@@ -98,6 +98,14 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleProcessedMessage() ...');
                        $handlerInstance->handleProcessedMessage();
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleProcessedMessage() ...');
+               } elseif ($handlerInstance->isDecodedPackageXmlPending()) {
+                       /*
+                        * A fully "decoded" package has arrived. This is raw XML and needs
+                        * to be parsed to a message.
+                        */
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleDecodedPackageXml() ...');
+                       $handlerInstance->handleDecodedPackageXml();
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: After handlerInstance->handleDecodedPackageXml() ...');
                } elseif ($handlerInstance->isNewMessageArrived()) {
                        /*
                         * A fully "decoded" message has been received and added for being
index d93a7199a046d85ffbca3ec000bf45fe34bd966a..e1e21925846dc32ef2aa44ae7a378775825fb853 100644 (file)
@@ -453,8 +453,11 @@ $cfg->setConfigEntry('stacker_package_handled_decoded_max_size', 200);
 // CFG: STACKER-PACKAGE-CHUNKED-DECODED-MAX-SIZE
 $cfg->setConfigEntry('stacker_package_chunked_decoded_max_size', 800);
 
-// CFG: STACKER-PACKAGE-NEW-MESSAGE-MAX-SIZE
-$cfg->setConfigEntry('stacker_package_new_message_max_size', 400);
+// CFG: STACKER-PACKAGE-DECOMPRESSED-XML-MAX-SIZE
+$cfg->setConfigEntry('stacker_package_decompressed_xml_max_size', 500);
+
+// CFG: STACKER-PACKAGE-NEW-PACKAGE-MAX-SIZE
+$cfg->setConfigEntry('stacker_package_new_package_max_size', 400);
 
 // CFG: STACKER-PACKAGE-PROCESSED-MESSAGE-MAX-SIZE
 $cfg->setConfigEntry('stacker_package_processed_message_max_size', 400);
index efaa98af939714f6bbfc024198e15825fd7a57cd..8cc0826dd48b337c4df5ad8a84633edaaa8b6389 100644 (file)
@@ -71,6 +71,13 @@ interface Receivable extends HubInterface {
         */
        function isNewMessageArrived ();
 
+       /**
+        * Checks whether pending decoded package's XML is pending parsing
+        *
+        * @return      $hasArrived             Whether a new package has arrived for processing
+        */
+       function isDecodedPackageXmlPending ();
+
        /**
         * Handle newly arrived message
         *
@@ -78,6 +85,13 @@ interface Receivable extends HubInterface {
         */
        function handleNewlyArrivedMessage ();
 
+       /**
+        * Handles package's decoded XML
+        *
+        * @return      void
+        */
+       function handleDecodedPackageXml ();
+
        /**
         * Checks whether a processed message is pending for "interpretation"
         *
diff --git a/core b/core
index 8de52623465245375075410e5c14e36c1df1f621..57b4b400d2e4a35f92d83270477157df4ee7c2c4 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 8de52623465245375075410e5c14e36c1df1f621
+Subproject commit 57b4b400d2e4a35f92d83270477157df4ee7c2c4