]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 25 Feb 2023 04:23:21 +0000 (05:23 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 25 Feb 2023 05:54:15 +0000 (06:54 +0100)
- added some more commented-out debug lines
- rewrote a few to use sprintf()
- updated index.php
- updated 'core' framework

application/hub/classes/package/fragmenter/class_PackageFragmenter.php
core
index.php

index 6764157d58ac64dba3ae855a56a8e2bb206f3d23..7c0a63e0add150a47aede3c8a17ba409973a9ae0 100644 (file)
@@ -133,10 +133,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function __construct () {
                // Call parent constructor
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: CONSTRUCTED!');
                parent::__construct(__CLASS__);
 
                // Init this fragmenter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: Invoking this->initFragmenter() ...');
                $this->initFragmenter();
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -146,7 +151,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public static final function createPackageFragmenter () {
                // Get new instance
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: CALLED!');
                $fragmenterInstance = new PackageFragmenter();
 
                // Get a crypto instance
@@ -156,6 +161,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                $fragmenterInstance->setCryptoInstance($cryptoInstance);
 
                // Return the prepared instance
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: fragmenterInstance=%s - EXIT!', $fragmenterInstance->__toString()));
                return $fragmenterInstance;
        }
 
@@ -166,15 +172,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function initFragmenter () {
                // Load some configuration entries and "cache" them:
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!');
                // - Chunk size in bits
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: CALLED!');
                $this->chunkSize = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('package_chunk_size');
 
                // - Maximum serial number
                $this->maxSerialNumber = StringUtils::hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH));
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -185,8 +191,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function initPointer (string $finalHash) {
                // Init counter
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s - CALLED!', $finalHash));
                $this->chunkPointers[$finalHash] = 0;
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -197,14 +206,18 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) {
                // Generate array index
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-               return (sprintf('%s%s%s%s%s',
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               $index = sprintf('%s%s%s%s%s',
                        $packageInstance->getSenderAddress(),
                        NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
                        $packageInstance->getRecipientUnl(),
                        NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
                        $packageInstance->getPackageContent()
-               ));
+               );
+
+               // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: index=%s - EXIT!', $index));
+               return $index;
        }
 
        /**
@@ -215,10 +228,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function isPackageProcessed (DeliverablePackage $packageInstance) {
                // Get array index
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $index = $this->getProcessedPackagesIndex($packageInstance);
 
                // Is the array index there?
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: index=%s', $index));
                $isProcessed = (
                        (
                                isset($this->isProcessedPackage[$index])
@@ -228,7 +242,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                );
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: isProcessed=%d - EXIT!', intval($isProcessed)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: isProcessed=%d - EXIT!', intval($isProcessed)));
                return $isProcessed;
        }
 
@@ -240,8 +254,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function markPackageDataProcessed (DeliverablePackage $packageInstance) {
                // Remember it (until we may remove it)
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->isProcessedPackage[$this->getProcessedPackagesIndex($packageInstance)] = TRUE;
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -251,15 +268,12 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @return      $finalHash              Final hash for package data
         */
        private function getFinalHashFromPackageInstance (DeliverablePackage $packageInstance) {
-               // Make sure it is there
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-               assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)]));
-
-               // Return it
+               // Get it from processed packages array
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $finalHash = $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)];
 
                // Return it
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
                return $finalHash;
        }
 
@@ -267,18 +281,16 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * Get next chunk pointer for given final hash
         *
         * @param       $finalHash      Final hash to get current pointer for
+        * @return      $chunkPointer   Next chunk pointer
         */
        private function getCurrentChunkPointer (string $finalHash) {
-               // Is the final hash valid?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
-               assert(!empty($finalHash));
-
-               // Is the pointer already initialized?
-               assert(isset($this->chunkPointers[$finalHash]));
+               // Get it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s - CALLED!', $finalHash));
+               $chunkPointer = $this->chunkPointers[$finalHash];
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: Returning chunk pointers for finalHash=%s - EXIT!', $finalHash));
-               return $this->chunkPointers[$finalHash];
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: chunkPointer=%d - EXIT!', $chunkPointer));
+               return $chunkPointer;
        }
 
        /**
@@ -287,13 +299,12 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash to advance the pointer for
         */
        private function nextChunkPointer (string $finalHash) {
-               // Is the pointer already initialized?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
-               assert(isset($this->chunkPointers[$finalHash]));
-
                // Count one up
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                $this->chunkPointers[$finalHash]++;
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -304,7 +315,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function getDataChunkSizeFromHash (string $hash) {
                // Calculate real (data) chunk size
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - CALLED!', $hash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: hash=%s - CALLED!', $hash));
                $dataChunkSize = (
                        // Real chunk size
                        ($this->chunkSize / 8) -
@@ -316,11 +327,8 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        self::MAX_SERIAL_LENGTH
                );
 
-               // This should be larger than zero bytes
-               assert($dataChunkSize > 0);
-
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d - CALLED!', $dataChunkSize));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d - CALLED!', $dataChunkSize));
                return $dataChunkSize;
        }
 
@@ -336,11 +344,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                 * Get the crypto instance and hash the data with no extra salt because
                 * the other peer doesn't have *this* peer's salt.
                 */
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s - CALLED!', $rawData));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: rawData=%s - CALLED!', $rawData));
                $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE);
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - EXIT!', $hash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: hash=%s - EXIT!', $hash));
                return $hash;
        }
 
@@ -355,20 +363,18 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function appendEndOfPackageChunk (string $lastChunk, string $finalHash) {
                // Generate end-of-package marker
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: lastChunk=%s,finalHash[%s]=%s - CALLED!', $lastChunk, gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: lastChunk=%s,finalHash=%s - CALLED!', $lastChunk, $finalHash));
                $chunkData =
                        self::END_OF_PACKAGE_IDENTIFIER .
                        $finalHash . self::CHUNK_HASH_SEPARATOR .
                        $this->generateHashFromRawData($lastChunk);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
-
                // Add it as regular chunk
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
                $this->addChunkData($finalHash, $chunkData);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -381,35 +387,32 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @return      void
         */
        private function splitEncodedDataIntoChunks (string $rawData, string $finalHash) {
-               // Make sure final hashes with at least 32 bytes can pass
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s,finalHash[%s]=%s - CALLED!', $rawData, gettype($finalHash), $finalHash));
-               assert(strlen($finalHash) >= 32);
-
                // Calculate real (data) chunk size
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: rawData=%s,finalHash=%s - CALLED!', $rawData, $finalHash));
                $dataChunkSize = $this->getDataChunkSizeFromHash($finalHash);
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: dataChunkSize=' . $dataChunkSize);
 
                // Init variables
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d', $dataChunkSize));
                $chunkHash = '';
                $chunkData = '';
 
                // Now split it up
                for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
                        // Get the next chunk
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: idx=%d', $idx));
                        $chunkData = substr($rawData, $idx, $dataChunkSize);
 
                        // Add the chunk to the propper array and do all the stuff there
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: Invoking this->addChunkData(%s,%s) ...', $finalHash, $chunkData));
                        $this->addChunkData($finalHash, $chunkData);
                }
 
-               // Debug output
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
-
                // Add end-of-package chunk
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
                $this->appendEndOfPackageChunk($chunkData, $finalHash);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -423,7 +426,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function addChunkData (string $finalHash, string $chunkData, bool $prepend = FALSE) {
                // Hash it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s,chunkData=%s,prepend=%d - CALLED!', gettype($finalHash), $finalHash, $chunkData, intval($prepend)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,chunkData=%s,prepend=%d - CALLED!', $finalHash, $chunkData, intval($prepend)));
                $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
 
                // Prepend the hash to the chunk
@@ -434,20 +437,18 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                );
 
                // Make sure the chunk is not larger than a TCP package can hold
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: assert: ' . strlen($rawData) . '/' . NetworkPackageHandler::TCP_PACKAGE_SIZE . ' ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: Checking: %d/%d ...', strlen($rawData), NetworkPackageHandler::TCP_PACKAGE_SIZE));
                // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackageHandler::TCP_PACKAGE_SIZE);
 
                // Add it to the array
                if ($prepend === TRUE) {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Prepending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
                        array_unshift($this->chunkHashes[$finalHash], $rawDataHash);
                        array_unshift($this->chunks[$finalHash]     , $rawData);
                } else {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
-
                        // Is the array there?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Appending ' . strlen($rawData) . ' bytes of a chunk, finalHash=' . $finalHash . ' ...');
                        if (!isset($this->chunks[$finalHash])) {
                                // Then initialize it
                                $this->chunks[$finalHash]      = [];
@@ -460,7 +461,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                }
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -471,14 +472,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function prependHashChunk (string $finalHash) {
                // "Implode" the whole array of hashes into one string
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s - CALLED!', $finalHash));
                $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
 
                // Prepend chunk
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: Invoking this->addChunkData(%s,%s,true) ...', $finalHash, $chunkData));
                $this->addChunkData($finalHash, $rawData, TRUE);
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -486,22 +488,24 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         *
         * @param       $finalHash                              Final hash
         * @return      $encodedSerialNumber    The next hexadecimal-encoded serial number
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public function getNextHexSerialNumber (string $finalHash) {
-               // Assert on maximum serial number length
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
-               assert(isset($this->serialNumber[$finalHash]));
-               assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber);
+               // Check parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s - CALLED!', $finalHash));
+               if (empty($finalHash)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "finalHash" is empty');
+               }
 
                // Encode the current serial number
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: serialNumber[' . $finalHash . ']=' . $this->serialNumber[$finalHash]);
                $encodedSerialNumber = StringUtils::dec2hex($this->serialNumber[$finalHash], self::MAX_SERIAL_LENGTH);
 
                // Count one up
                $this->serialNumber[$finalHash]++;
 
                // Return the encoded serial number
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: encodedSerialNumber=' . $encodedSerialNumber . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: encodedSerialNumber=%s - EXIT!', $encodedSerialNumber));
                return $encodedSerialNumber;
        }
 
@@ -518,10 +522,10 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance) {
                // Is this package already fragmented?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString()));
                if (!$this->isPackageProcessed($packageInstance)) {
                        // First put it the right way together again, implode on getAllAsArray() won't work!
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
                        //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: packageInstance->allAsArray=%s', __METHOD__, __LINE__, print_r($packageInstance->getAllAsArray(), TRUE)));
                        $rawData = sprintf('%s%s%s%s%d%s%s%s%s%s%s%s%s%s%s',
                                $packageInstance->getSenderAddress(),
@@ -542,11 +546,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        );
 
                        // Generate the final hash from the raw data (not encoded!)
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
                        $finalHash = $this->generateHashFromRawData($rawData);
 
                        // Remember it
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
                        $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash;
 
                        // Init pointer and reset serial number
@@ -563,13 +567,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        $this->markPackageDataProcessed($packageInstance);
                } else {
                        // Get the final hash from the package data
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...');
                        $finalHash = $this->getFinalHashFromPackageInstance($packageInstance);
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
                }
 
                // Return final hash
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
                return $finalHash;
        }
 
@@ -585,7 +589,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function getNextRawDataChunk (string $finalHash) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
                if (empty($finalHash)) {
                        // Should not be empty
                        throw new InvalidArgumentException('Parameter "finalHash" is empty');
@@ -608,21 +612,22 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // If there is no entry left, return an empty array
                if ((!isset($this->chunkHashes[$finalHash][$current])) || (!isset($this->chunks[$finalHash][$current]))) {
                        // No more entries found
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,current=%s - No more entries found!', $finalHash, $current));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,current=%s - No more entries found!', $finalHash, $current));
                        return [];
                }
 
                // Generate the array
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,current=%s,chunkHashes()=%d - Entry choosen ...', $finalHash, $current, count($this->chunkHashes[$finalHash])));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,current=%s,chunkHashes()=%d - Entry choosen ...', $finalHash, $current, count($this->chunkHashes[$finalHash])));
                $rawDataChunk = [
                        $this->chunkHashes[$finalHash][$current] => $this->chunks[$finalHash][$current]
                ];
 
                // Count one index up
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: Invoking this->nextChunkPointer(%s) ...', $finalHash));
                $this->nextChunkPointer($finalHash);
 
                // Return the chunk array
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Returning rawDataChunk ... - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: rawDataChunk[%s]=%s - EXIT!', $this->chunkHashes[$finalHash][$current], $this->chunks[$finalHash][$current]));
                return $rawDataChunk;
        }
 
@@ -631,21 +636,21 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         *
         * @param       $finalHash      Final hash to reset counter for
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public function resetSerialNumber (string $finalHash) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
                if (empty($finalHash)) {
                        // Should not be empty
                        throw new InvalidArgumentException('Parameter "finalHash" is empty');
                }
 
-
                // Reset/set serial number
                $this->serialNumber[$finalHash] = 0;
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
        }
 
 }
diff --git a/core b/core
index f861d6bc00f8a3ecf6b057f2aa93129572643896..bfe1b8bbcc74881eb34f03922f29c6e2d642bc6b 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit f861d6bc00f8a3ecf6b057f2aa93129572643896
+Subproject commit bfe1b8bbcc74881eb34f03922f29c6e2d642bc6b
index 94177e3062c449faaa117332f0d0fac89dad4038..37fa261279410afe592905650fe6afaa2af5454c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -60,6 +60,7 @@ final class ApplicationEntryPoint {
         */
        public static final function exitApplication (string $message = '', int $code = -1, string $extraData = '', bool $silentMode = false) {
                // Is this method already called?
+               //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,code=%d,extraData=%s,silentMode=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, $code, $extraData, intval($silentMode));
                if (isset($GLOBALS['app_die_called'])) {
                        // Then output the text directly
                        print $message . PHP_EOL;
@@ -81,6 +82,7 @@ final class ApplicationEntryPoint {
                // Do we have debug installation?
                if (($configInstance->getConfigEntry('product_install_mode') == 'productive') || ($silentMode === true)) {
                        // Abort here
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: product_install_mode=%d,silentMode=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $configInstance->getConfigEntry('product_install_mode'), intval($silentMode));
                        exit(255);
                }
 
@@ -185,6 +187,9 @@ final class ApplicationEntryPoint {
                        printf('[Main:] Emergency exit reached: <span class="emergency_span">%s</span>', $message);
                        exit(255);
                }
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
 
        /**
@@ -197,16 +202,19 @@ final class ApplicationEntryPoint {
         */
        public static final function detectFrameworkPath () {
                // Is it not set?
+               //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
                if (empty(self::$frameworkPath)) {
                        // Auto-detect core path (first application-common)
-                       foreach (array('core', __DIR__, '/usr/local/share/php/core', '/usr/share/php/core') as $possiblePath) {
+                       foreach (['core', self::getRootPath(), '/usr/local/share/php/core', '/usr/share/php/core'] as $possiblePath) {
                                // Create full path for testing
+                               //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s' . PHP_EOL, __METHOD__, __LINE__, $possiblePath);
                                $realPath = realpath($possiblePath);
 
                                // Is it false?
                                //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath);
                                if ($realPath === false) {
                                        // Then, not found.
+                                       //* NOISY-DEBUG: */ printf('[%s:%d]: possiblePath=%s was not found. - SKIPPED!' . PHP_EOL, __METHOD__, __LINE__, $possiblePath);
                                        continue;
                                }
 
@@ -214,6 +222,7 @@ final class ApplicationEntryPoint {
                                $frameworkPath = sprintf('%s%sframework%s', $realPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
 
                                // First create full-qualified file name (FQFN) to framework/config-global.php
+                               //* NOISY-DEBUG: */ printf('[%s:%d]: frameworkPath=%s' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath);
                                $configFile = $frameworkPath . 'config-global.php';
 
                                // Is it readable?
@@ -223,11 +232,13 @@ final class ApplicationEntryPoint {
                                        self::$frameworkPath = $frameworkPath;
 
                                        // Abort here
+                                       //* NOISY-DEBUG: */ printf('[%s:%d]: Setting self::frameworkPath=%s - BREAK!' . PHP_EOL, __METHOD__, __LINE__, $frameworkPath);
                                        break;
                                }
                        }
 
                        // Able to find?
+                       //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - Checking ...' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
                        if (!is_dir(self::$frameworkPath)) {
                                // Is no directory
                                throw new Exception('Cannot find framework.');
@@ -235,6 +246,7 @@ final class ApplicationEntryPoint {
                }
 
                // Return it
+               //* NOISY-DEBUG: */ printf('[%s:%d]: self::frameworkPath=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, self::$frameworkPath);
                return self::$frameworkPath;
        }
 
@@ -258,6 +270,7 @@ final class ApplicationEntryPoint {
         */
        public static final function main () {
                // Load bootstrap file
+               //* NOISY-DEBUG: */ printf('[%s:%d]: CALLED!' . PHP_EOL, __METHOD__, __LINE__);
                require sprintf('%sbootstrap%sbootstrap.inc.php', self::detectFrameworkPath(), DIRECTORY_SEPARATOR);
 
                /*
@@ -274,13 +287,14 @@ final class ApplicationEntryPoint {
                 * register the application instance in registry.
                 */
                FrameworkBootstrap::startApplication();
+
+               // Trace message
+               //* NOISY-DEBUG: */ printf('[%s:%d]: EXIT!' . PHP_EOL, __METHOD__, __LINE__);
        }
 }
 
 // Log all exceptions (only debug! This option can create large error logs)
 //define('LOG_EXCEPTIONS', true);
 
-//xdebug_start_trace();
-
 // Call above main() method
 ApplicationEntryPoint::main();