]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 19:31:45 +0000 (20:31 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 19:31:45 +0000 (20:31 +0100)
- throw IAE when e.g. a string parameter is empty
- introduced DeliverableTrait
- improved/commented in debug messages
- added type-hints for primitive variables

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/nodes/class_BaseHubNode.php
application/hub/classes/package/assembler/class_PackageAssembler.php
application/hub/classes/package/fragmenter/class_PackageFragmenter.php
application/hub/interfaces/delivery/fragmenter/class_Fragmentable.php
application/hub/traits/delivery/class_DeliverableTrait.php [new file with mode: 0644]

index 7cb897007c09c5c6398fa636710f224f24d909cd..6927e0ce1e20b142d60f9950be57e5f2c8b78c11 100644 (file)
@@ -18,8 +18,8 @@ use Org\Shipsimu\Hub\Traits\Fragmenter\FragmentableTrait;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Traits\Stream\Output\OutputStreamTrait;
@@ -245,15 +245,21 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
         * @return      $chunkData              Raw data chunk
         */
        private function getRawDataFromPackageArray (DeliverablePackage $packageInstance) {
-               // Make sure the final hash is set
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: currentFinalHash=' . $this->currentFinalHash);
-               assert((is_string($this->currentFinalHash)) && (!empty($this->currentFinalHash)));
-
                // Get the next raw data chunk from the fragmenter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: packageInstance=%s,this->currentFinalHash=%s - CALLED!', $packageInstance->__toString(), $this->currentFinalHash));
                $rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash);
 
+               // At least one entry should be there?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawDataChunk()=%d', count($rawDataChunk)));
+               if (count($rawDataChunk) == 0) {
+                       // No, then all has been added
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: Returning empty string ... - EXIT!');
+                       return '';
+               }
+
                // Get chunk hashes and chunk data
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: rawDataChunk=' . print_r($rawDataChunk, TRUE));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawDataChunk()=%d', count($rawDataChunk)));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawDataChunk=%s', print_r($rawDataChunk, TRUE)));
                $chunkHashes = array_keys($rawDataChunk);
                $chunkData   = array_values($rawDataChunk);
 
@@ -261,14 +267,14 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
                $rawData = '';
 
                // Is the required data there?
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: chunkHashes()=' . count($chunkHashes) . ',chunkData()=' . count($chunkData));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: chunkHashes()=%s,chunkData()=%s', count($chunkHashes), count($chunkData)));
                //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
                if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) {
                        // Remember this chunk as queued
                        $this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
 
                        // Return the raw data
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: rawData()=' . strlen($chunkData[0]) . ' bytes.');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawData()=%d bytes.', strlen($chunkData[0])));
                        $rawData = $chunkData[0];
                }
 
index 8d58abffe77612dd37c480d27c0fa230841f2127..035672ab7ff8f180984bb1fbd7dbe68f45a6b12b 100644 (file)
@@ -345,7 +345,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                        $nodeData = $resultInstance->current();
 
                        // Get the node id from result and set it
-                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
+                       /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
                        $this->setNodeId($resultInstance->getField(NodeInformationDatabaseFrontend::DB_COLUMN_NODE_ID));
 
                        // Output message
index 7274760bdf1bcb34174acf605dd5a3a488201458..eb73d2cb7a27997807e01fcd5bbb7b43c80c9d0c 100644 (file)
@@ -8,13 +8,14 @@ use Org\Shipsimu\Hub\Factory\Handler\Chunk\ChunkHandlerFactory;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
 use Org\Shipsimu\Hub\Handler\Network\PackageCode\UnsupportedPackageCodeHandlerException;
 use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData;
-use Org\Shipsimu\Hub\Network\Delivery\Deliverable;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter;
 use Org\Shipsimu\Hub\Network\Receive\Receivable;
+use Org\Shipsimu\Hub\Traits\Network\Package\Delivery\DeliverableTrait;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Traits\Handler\HandleableTrait;
@@ -52,6 +53,7 @@ use \BadMethodCallException;
  */
 class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, Visitable {
        // Load traits
+       use DeliverableTrait;
        use HandleableTrait;
        use InputStreamTrait;
        use StackableTrait;
@@ -76,11 +78,6 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         */
        private $callbacks = [];
 
-       /**
-        * A network package handler instance
-        */
-       private $packageHandlerInstance = NULL;
-
        /**
         * Protected constructor
         *
@@ -123,7 +120,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
                $assemblerInstance->setStackInstance($stackInstance);
 
                // Return the prepared instance
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: assemblerInstance=%s', __METHOD__, __LINE__, print_r($assemblerInstance, TRUE)));
+               //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: assemblerInstance=%s', __METHOD__, __LINE__, print_r($assemblerInstance, TRUE)));
                return $assemblerInstance;
        }
 
@@ -134,28 +131,10 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         */
        public function clearPendingData () {
                // Clear it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: CALLED!');
                $this->pendingData = '';
        }
 
-       /**
-        * Setter for network package handler instance
-        *
-        * @param       $packageHandlerInstance The network package instance we shall set
-        * @return      void
-        */
-       protected final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) {
-               $this->packageHandlerInstance = $packageHandlerInstance;
-       }
-
-       /**
-        * Getter for network package handler instance
-        *
-        * @return      $packageHandlerInstance The network package handler instance we shall set
-        */
-       protected final function getPackageHandlerInstance () {
-               return $this->packageHandlerInstance;
-       }
-
        /**
         * Checks whether the input buffer (stacker to be more preceise) is empty.
         *
@@ -163,6 +142,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         */
        private function ifInputBufferIsEmpty () {
                // Check it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: CALLED!');
                $isInputBufferEmpty = $this->getPackageHandlerInstance()->getStackInstance()->isStackEmpty(NetworkPackageHandler::STACKER_NAME_DECODED_HANDLED);
 
                // Return it
index 0b180dd57863f8fe627ba3eccb18d9779fef60d8..ccd8c8a52390671424676361b3607030a4f35232 100644 (file)
@@ -17,6 +17,9 @@ use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A PackageFragmenter class to fragment package data into smaller chunks for
  * delivery. This class calculates a final hash on the raw input data and
@@ -180,7 +183,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash to initialize pointer for
         * @return      void
         */
-       private function initPointer ($finalHash) {
+       private function initPointer (string $finalHash) {
                // Init counter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                $this->chunkPointers[$finalHash] = 0;
@@ -265,10 +268,10 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         *
         * @param       $finalHash      Final hash to get current pointer for
         */
-       private function getCurrentChunkPointer ($finalHash) {
+       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(strlen($finalHash) > 0);
+               assert(!empty($finalHash));
 
                // Is the pointer already initialized?
                assert(isset($this->chunkPointers[$finalHash]));
@@ -283,7 +286,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         *
         * @param       $finalHash      Final hash to advance the pointer for
         */
-       private function nextChunkPointer ($finalHash) {
+       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]));
@@ -299,7 +302,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $hash                   Hash to substract it's length
         * @return      $dataChunkSize  The chunk size
         */
-       private function getDataChunkSizeFromHash ($hash) {
+       private function getDataChunkSizeFromHash (string $hash) {
                // Calculate real (data) chunk size
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - CALLED!', $hash));
                $dataChunkSize = (
@@ -328,7 +331,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @return      $hash           Hash from the raw data
         * @todo        Implement a way to send non-announcement packages with extra-salt
         */
-       private function generateHashFromRawData ($rawData) {
+       private function generateHashFromRawData (string $rawData) {
                /*
                 * Get the crypto instance and hash the data with no extra salt because
                 * the other peer doesn't have *this* peer's salt.
@@ -350,7 +353,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash for raw (unencoded) data
         * @return      void
         */
-       private function appendEndOfPackageChunk ($lastChunk, $finalHash) {
+       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));
                $chunkData =
@@ -377,7 +380,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash from the raw data
         * @return      void
         */
-       private function splitEncodedDataIntoChunks ($rawData, $finalHash) {
+       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);
@@ -418,7 +421,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $prepend        Whether append (default) or prepend the chunk
         * @return      void
         */
-       private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) {
+       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)));
                $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
@@ -466,7 +469,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash from the raw data
         * @return      void
         */
-       private function prependHashChunk ($finalHash) {
+       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));
                $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
@@ -484,7 +487,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash                              Final hash
         * @return      $encodedSerialNumber    The next hexadecimal-encoded serial number
         */
-       public function getNextHexSerialNumber ($finalHash) {
+       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]));
@@ -578,10 +581,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash              Final hash for faster lookup
         * @return      $rawDataChunk   An instance of a DeliverablePackage class chunk
         * @throws      AssertionException      If $finalHash was not 'TRUE'
-        */
-       public function getNextRawDataChunk ($finalHash) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
+        * @throws      InvalidArgumentException        If a parameter is invalid
+        */
+       public function getNextRawDataChunk (string $finalHash) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash(%d)=%s - CALLED!', strlen($finalHash), $finalHash));
+               if (empty($finalHash)) {
+                       // Should not be empty
+                       throw new InvalidArgumentException('Parameter "finalHash" is empty');
+               }
 
                try {
                        // Get current chunk index
@@ -600,23 +608,21 @@ 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('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!');
-                       return array();
-               } // END - if
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s,current=%s - No more entries found!', $finalHash, $current));
+                       return [];
+               }
 
                // Generate the array
-               $rawDataChunk = 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])));
+               $rawDataChunk = [
                        $this->chunkHashes[$finalHash][$current] => $this->chunks[$finalHash][$current]
-               );
+               ];
 
                // Count one index up
                $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__)->debugOutput('PACKAGE-FRAGMENTER: Returning rawDataChunk ... - EXIT!');
                return $rawDataChunk;
        }
 
@@ -626,10 +632,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @param       $finalHash      Final hash to reset counter for
         * @return      void
         */
-       public function resetSerialNumber ($finalHash) {
-               // Final hash must be set
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
-               assert((is_string($finalHash)) && (!empty($finalHash)));
+       public function resetSerialNumber (string $finalHash) {
+               // Validate parameter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(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;
index 94134380765f6bcc9016f92e81088ab63f799519..f4d763b37152c23d8f273683afa3dcb4cb737b2a 100644 (file)
@@ -32,15 +32,24 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface Fragmentable extends HubInterface {
+       /**
+        * "Getter" for the next hexadecimal-encoded serial number
+        *
+        * @param       $finalHash                              Final hash
+        * @return      $encodedSerialNumber    The next hexadecimal-encoded serial number
+        */
+       function getNextHexSerialNumber (string $finalHash);
+
        /**
         * This method does "implode" the given package data array into one long
         * string, splits it into small chunks, adds a serial number and checksum
-        * to all chunks and prepends a final hashsum chunk. It will return the
-        * final hash for faster processing of packages.
+        * to all chunks and prepends a chunk with all hashes only in it. It will
+        * return the final hash for faster processing of packages.
         *
-        * @param       $packageInstance        An instance of a DeliverablePackage instance
+        * @param       $packageInstance        An instance of a DeliverablePackage class array
         * @param       $helperInstance         An instance of a ConnectionHelper class
         * @return      $finalHash                      Final hash for faster processing
+        * @todo        $helperInstance is unused
         */
        function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance);
 
@@ -51,7 +60,17 @@ interface Fragmentable extends HubInterface {
         *
         * @param       $finalHash              Final hash for faster lookup
         * @return      $rawDataChunk   An instance of a DeliverablePackage class chunk
+        * @throws      AssertionException      If $finalHash was not 'TRUE'
+        * @throws      InvalidArgumentException        If a parameter is invalid
+        */
+       function getNextRawDataChunk (string $finalHash);
+
+       /**
+        * Resets the serial number to zero for given final hash
+        *
+        * @param       $finalHash      Final hash to reset counter for
+        * @return      void
         */
-       function getNextRawDataChunk ($finalHash);
+       function resetSerialNumber (string $finalHash);
 
 }
diff --git a/application/hub/traits/delivery/class_DeliverableTrait.php b/application/hub/traits/delivery/class_DeliverableTrait.php
new file mode 100644 (file)
index 0000000..bce99ce
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Shipsimu\Hub\Traits\Network\Package\Delivery;
+
+// Import application-specific stuff
+use Org\Shipsimu\Hub\Network\Delivery\Deliverable;
+
+/**
+ * A trait for package delivery
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+trait DeliverableTrait {
+       /**
+        * A network package handler instance
+        */
+       private $packageHandlerInstance = NULL;
+
+       /**
+        * Setter for network package handler instance
+        *
+        * @param       $packageHandlerInstance The network package instance we shall set
+        * @return      void
+        */
+       protected final function setPackageHandlerInstance (Deliverable $packageHandlerInstance) {
+               $this->packageHandlerInstance = $packageHandlerInstance;
+       }
+
+       /**
+        * Getter for network package handler instance
+        *
+        * @return      $packageHandlerInstance The network package handler instance we shall set
+        */
+       protected final function getPackageHandlerInstance () {
+               return $this->packageHandlerInstance;
+       }
+
+}