]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 09:57:57 +0000 (10:57 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 09:57:57 +0000 (10:57 +0100)
- renamed packageInstance -> handlerInstance as this is no longer the package
  but the handler of the package
- added some debug lines
- 'fake' package status removed

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

index 22123edc38fc249889ccd9cf4397ebd8d82334a3..29f99fbd687af4785c5a1e05ea0b5b846c6fea6c 100644 (file)
@@ -89,7 +89,7 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
                $unhandledDataLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA));
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: unhandledDataLeft=' . intval($unhandledDataLeft));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: unhandledDataLeft=' . intval($unhandledDataLeft) . ' - EXIT!');
                return $unhandledDataLeft;
        }
 
@@ -100,6 +100,7 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
         */
        public function handleRawPackageData () {
                // Assert on it to make sure the next popNamed() call won't throw an exception
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: CALLED!');
                assert($this->ifUnhandledRawPackageDataLeft());
 
                // "Pop" the next raw package content
@@ -135,10 +136,11 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
         */
        public function ifDeocedPackagesLeft () {
                // Check it ...
-               $ifRawPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
+               $ifDecodedPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
 
                // ... return it
-               return $ifRawPackagesLeft;
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: ifDecodedPackagesLeft=' . intval($ifDecodedPackagesLeft) . ' - EXIT!');
+               return $ifDecodedPackagesLeft;
        }
 
        /**
@@ -155,7 +157,7 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
 
                // Handle it
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: packageInstance=' . $packageInstance->__toString() . ')=' . print_r($packageInstance, TRUE));
-               $this->getPackageHandlerInstance()->handleRawData($packageInstance);
+               $this->getPackageHandlerInstance()->handleReceivedPackageInstance($packageInstance);
        }
 
 }
index a0f49260a133300a56458963e5a24170f953251b..434b64839633c1028d142c23fe702a4770a30d3d 100644 (file)
@@ -85,7 +85,6 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         * 1: Raw package data
         * 2: Tags, seperated by semicolons, no semicolon is required if only one tag is needed
         * 3: Checksum
-        *                     0  1  2  3
         */
        const PACKAGE_MASK = '%s%s%s%s%s%s%s';
 
@@ -132,7 +131,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
        /**
         * Named array elements for decoded package content
         */
-       const PACKAGE_CONTENT_EXTENSION        = 'compressor';
+       const PACKAGE_CONTENT_COMPRESSOR       = 'compressor';
        const PACKAGE_CONTENT_MESSAGE          = 'message';
        const PACKAGE_CONTENT_TAGS             = 'tags';
        const PACKAGE_CONTENT_CHECKSUM         = 'checksum';
@@ -146,7 +145,6 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
        const PACKAGE_STATUS_NEW     = 'new';
        const PACKAGE_STATUS_FAILED  = 'failed';
        const PACKAGE_STATUS_DECODED = 'decoded';
-       const PACKAGE_STATUS_FAKED   = 'faked';
 
        /**
         * Constants for message data array
@@ -523,7 +521,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        public function getHashFromContentSessionId (array $decodedContent, $sessionId) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]);
 
                // Create the hash
                // @TODO md5() is very weak, but it needs to be fast
@@ -532,7 +530,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                        self::PACKAGE_CHECKSUM_SEPARATOR .
                        $sessionId .
                        self::PACKAGE_CHECKSUM_SEPARATOR .
-                       $decodedContent[self::PACKAGE_CONTENT_EXTENSION]
+                       $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]
                );
 
                // And return it
@@ -1366,7 +1364,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        public function decodeRawContent ($rawPackageContent) {
                // Use the separator '#' to "decode" it
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent(%d)=%s - CALLED!', strlen($rawPackageContent), $rawPackageContent));
                $decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
 
                // Assert on count (should be always 3)
@@ -1380,6 +1378,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $packageInstance->setSenderAddress($decodedArray[self::INDEX_PACKAGE_SENDER_ADDRESS]);
                $packageInstance->setSenderPort($decodedArray[self::INDEX_PACKAGE_SENDER_PORT]);
                $packageInstance->setRecipientId($decodedArray[self::INDEX_PACKAGE_RECIPIENT]);
+               $packageInstance->setRecipientType(self::NETWORK_TARGET_DIRECT);
                $packageInstance->setPackageContent($decodedArray[self::INDEX_PACKAGE_CONTENT]);
                $packageInstance->setStatus(self::PACKAGE_STATUS_DECODED);
                $packageInstance->setContentHash($decodedArray[self::INDEX_PACKAGE_HASH]);
@@ -1398,7 +1397,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         * @return      void
         * @throws      InvalidDataChecksumException    If the checksum doesn't match
         */
-       public function handleRawData (DeliverablePackage $packageInstance) {
+       public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) {
                /*
                 * "Decode" the package's content by a simple explode() call, for
                 * details of the array elements, see comments for constant
@@ -1415,7 +1414,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                 */
                $decodedContent = array(
                        // Compressor's extension used to compress the data
-                       self::PACKAGE_CONTENT_EXTENSION        => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
+                       self::PACKAGE_CONTENT_COMPRESSOR       => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
                        // Package data (aka "message") in BASE64-decoded form but still compressed
                        self::PACKAGE_CONTENT_MESSAGE          => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
                        // Tags as an indexed array for "tagging" the message
index f7a97036cc3951438f3022557b4048320cdbe596..921570cdea5a5a98713fbbf506a1cd896185d431 100644 (file)
@@ -83,30 +83,21 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
         * @return      void
         */
        public function executeTask () {
-               // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
-
                // Get package instance
-               $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: packageInstance=%s', $packageInstance->__toString()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
+               $handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
 
                // Do we have something to handle?
-               if ($packageInstance->isProcessedMessagePending()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleProcessedMessage() ...');
-
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: handlerInstance=%s', $handlerInstance->__toString()));
+               if ($handlerInstance->isProcessedMessagePending()) {
                        /*
                         * A previously proccessed message is waiting for being
                         * "interpreted". This is done by trying to find a configuration
                         * entry based on 'message_type' element.
                         */
-                       $packageInstance->handleProcessedMessage();
-               } elseif ($packageInstance->isNewMessageArrived()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleNewlyArrivedMessage() ...');
-
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleProcessedMessage() ...');
+                       $handlerInstance->handleProcessedMessage();
+               } elseif ($handlerInstance->isNewMessageArrived()) {
                        /*
                         * A fully "decoded" message has been received and added for being
                         * processed. Processing a message should not take long, so mostly
@@ -114,37 +105,31 @@ class NetworkPackageReaderTask extends BaseHubTask implements Taskable, Visitabl
                         * as "XML variables" from the content (which must be a well-formed
                         * XML) and then pushing it on the next stack "processed messages".
                         */
-                       $packageInstance->handleNewlyArrivedMessage();
-               } elseif ($packageInstance->isIncomingRawDataHandled()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->assembleDecodedDataToPackage() ...');
-
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleNewlyArrivedMessage() ...');
+                       $handlerInstance->handleNewlyArrivedMessage();
+               } elseif ($handlerInstance->isIncomingRawDataHandled()) {
                        /*
                         * Incoming decoded data has been handled (see below) so it needs to
-                        * be assembled back to a "package array". Please see NetworkPackage
-                        * for further details (what array elements are required et cetera).
+                        * be assembled back to a package data instance. Please see
+                        * PackageData for further details (what array elements are
+                        * required et cetera).
                         */
-                       $packageInstance->assembleDecodedDataToPackage();
-               } elseif ($packageInstance->ifMultipleMessagesPending()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleMultipleMessages() ...');
-
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->assembleDecodedDataToPackage() ...');
+                       $handlerInstance->assembleDecodedDataToPackage();
+               } elseif ($handlerInstance->ifMultipleMessagesPending()) {
                        /*
                         * Some raw data contained multiple messages which where now splitted.
                         */
-                       $packageInstance->handleMultipleMessages();
-               } elseif ($packageInstance->isNewRawDataPending()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleIncomingDecodedData() ...');
-
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleMultipleMessages() ...');
+                       $handlerInstance->handleMultipleMessages();
+               } elseif ($handlerInstance->isNewRawDataPending()) {
                        // Raw, decoded data has been received
-                       $packageInstance->handleIncomingDecodedData();
-               } elseif ($packageInstance->ifAssemblerHasPendingDataLeft()) {
-                       // Trace message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleAssemblerPendingData() ...');
-
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleIncomingDecodedData() ...');
+                       $handlerInstance->handleIncomingDecodedData();
+               } elseif ($handlerInstance->ifAssemblerHasPendingDataLeft()) {
                        // Handle any pending data from the package assembler
-                       $packageInstance->handleAssemblerPendingData();
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleAssemblerPendingData() ...');
+                       $handlerInstance->handleAssemblerPendingData();
                }
 
                // Trace message
index 399a9131aff0fe2548daf4f50eb7f38adb2557d4..6b18235a1402c98e2ace9698735e9afb0612e489 100644 (file)
@@ -79,12 +79,12 @@ class NodePackageDecoderTask extends BaseHubTask implements Taskable, Visitable
                $decoderInstance = DecoderFactory::createPackageDecoderInstance();
 
                // Check if the stacker has some entries left
-               if ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
-                       // Then handle it
-                       $decoderInstance->handleRawPackageData();
-               } elseif ($decoderInstance->ifDeocedPackagesLeft()) {
-                       // Some decoded packages have arrived (for this peer)
+               if ($decoderInstance->ifDeocedPackagesLeft()) {
+                       // Some decoded packages have arrived (for this node)
                        $decoderInstance->handleDecodedPackage();
+               } elseif ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
+                       // Handle raw data as last option to prevent that the stack runs full
+                       $decoderInstance->handleRawPackageData();
                }
        }
 
index 70ee6a2e5537ee9d2ceca9bb91e8d58d456323ac..df10735e06d76fb52296aa436246f3916286423e 100644 (file)
@@ -124,12 +124,12 @@ interface Receivable extends HubInterface {
        function handleAssemblerPendingData ();
 
        /**
-        * Handles decoded data for this node
+        * Handles received package instance
         *
         * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         */
-       function handleRawData (DeliverablePackage $packageInstance);
+       function handleReceivedPackageInstance (DeliverablePackage $packageInstance);
 
        /**
         * Checks whether the assembler has multiple messages pending