]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 15:31:58 +0000 (16:31 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 3 Dec 2020 15:31:58 +0000 (16:31 +0100)
- renamed NodeInformationDatabaseFrontend->ifNodeDataIsFound() to
  findFirstNodeData() and also changed return type from bool to $resultInstance
  (SearchableResult)
- changed type-hint from BaseHubNode (abstract class) to Node (interface)
- improved some debug messages

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php
application/hub/classes/handler/chunks/class_ChunkHandler.php
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/classes/streams/raw_data/output/class_RawDataOutputStream.php
application/hub/interfaces/database/frontend/node_information/class_NodeInformationFrontend.php

index dbba15fd3a853c8d0dbbdce88081d7649edc9c66..9b971a68705c174622a1b518eab99b33a3912091 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\Information;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseFrontend;
 use Org\Shipsimu\Hub\Database\Frontend\Node\NodeInformationFrontend;
-use Org\Shipsimu\Hub\Node\BaseHubNode;
 use Org\Shipsimu\Hub\Node\Node;
 
 // Import framework stuff
@@ -77,12 +76,11 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements
        }
 
        /**
-        * Checks whether there is an entry for given node instance
+        * Tries to find a node instance by it's nodeId field
         *
-        * @param       $nodeInstance   An instance of a Node class
-        * @return      $isFound                Whether a node id has been found for this node
+        * @return      $resultInstance         An instance of a SearchableResult class
         */
-       public function ifNodeDataIsFound (Node $nodeInstance) {
+       public function findFirstNodeData () {
                // Is there cache?
                if (!isset($GLOBALS[__METHOD__])) {
                        // Now get a search criteria instance
@@ -97,7 +95,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements
                        $resultInstance = $this->doSelectByCriteria($searchInstance);
 
                        // Is it valid?
-                       $GLOBALS[__METHOD__] = $resultInstance->next();
+                       $GLOBALS[__METHOD__] = ($resultInstance->next() ? $resultInstance : NULL);
                }
 
                // Return it
@@ -108,10 +106,10 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements
         * 'Registers' a new node id along with data provided in the node instance.
         * This may sound confusing but avoids double code very nicely...
         *
-        * @param       $nodeInstance           A node instance
+        * @param       $nodeInstance   An instance of a Node class
         * @return      void
         */
-       public function registerNodeId (BaseHubNode $nodeInstance) {
+       public function registerNodeId (Node $nodeInstance) {
                // Get a dataset instance
                $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
 
@@ -129,11 +127,11 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements
         * 'Registers' a new session id along with data provided in the node instance.
         * This may sound confusing but avoids double code very nicely...
         *
-        * @param       $nodeInstance           An instance of a BaseHubNode class
+        * @param       $nodeInstance           An instance of a Node class
         * @param       $searchInstance         An instance of a LocalSearchCriteria class
         * @return      void
         */
-       public function registerSessionId (BaseHubNode $nodeInstance, LocalSearchCriteria $searchInstance) {
+       public function registerSessionId (Node $nodeInstance, LocalSearchCriteria $searchInstance) {
                // Get a dataset instance
                $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
 
@@ -154,11 +152,11 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements
         * 'Registers' a private key along with data provided in the node instance.
         * This may sound confusing but avoids double code very nicely...
         *
-        * @param       $nodeInstance           An instance of a BaseHubNode class
+        * @param       $nodeInstance           An instance of a Node class
         * @param       $searchInstance         An instance of a LocalSearchCriteria class
         * @return      void
         */
-       public function registerPrivateKey (BaseHubNode $nodeInstance, LocalSearchCriteria $searchInstance) {
+       public function registerPrivateKey (Node $nodeInstance, LocalSearchCriteria $searchInstance) {
                // Get a dataset instance
                $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
 
index e2d0169140f45d98e5b7cc71cd796f3a3c4f5374..de5cac4188bb86fb8658c82bb4e7f5460bbe0151 100644 (file)
@@ -16,6 +16,9 @@ use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait;
 
+// Import SPL stuff
+use \UnexpectedValueException;
+
 /**
  * A Chunk handler
  *
@@ -152,25 +155,25 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
        private function initHandler () {
                // Init finalPackageChunks
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: Initializing handler - CALLED!');
-               $this->finalPackageChunks = array(
+               $this->finalPackageChunks = [
                        // Array for package content
-                       'content'        => array(),
+                       'content'        => [],
                        // ... and for the hashes
-                       'hashes'         => array(),
+                       'hashes'         => [],
                        // ... marker for that the final array is complete for assembling all chunks
                        'is_complete'    => FALSE,
                        // ... steps done to assemble all chunks
                        'assemble_steps' => 0,
-               );
+               ];
 
                // ... chunkHashes:
                $this->chunkHashes = [];
 
                // ... eopChunk:
-               $this->eopChunk = array(
+               $this->eopChunk = [
                        0 => 'INVALID',
                        1 => 'INVALID',
-               );
+               ];
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
@@ -186,8 +189,10 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                // Assert on some elements
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d - CALLED!', count($chunkSplits)));
                //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: chunkSplits=' . print_r($chunkSplits, TRUE));
-               assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]));
-               assert(isset($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]));
+               if (!isset($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]) || !isset($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH])) {
+                       // Missing array element
+                       ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: chunkSplits=%s', __METHOD__, __LINE__, print_r($chunkSplits, TRUE)));
+               }
 
                // Now hash the raw data again
                $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], FALSE);
@@ -234,7 +239,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
                        // Then throw an exception
                        throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
-               } // END - if
+               }
 
                // Add the chunk data (index 2) to the final array and use the serial number as index
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',hash=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH]);
@@ -351,8 +356,8 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                                // And re-request it with valid serial number (and hash chunk)
                                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s does not match nextSerial=%s, re-questing it ...', $serialNumber, $nextSerial));
                                $this->rerequestChunkBySerialNumber($nextSerial);
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
@@ -383,10 +388,10 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        // Is this chunk valid? This should be the case
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ',hashes=' . $this->finalPackageChunks['hashes'][$serialNumber] . ' - validating ...');
                        //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks, TRUE) . 'chunkHashes=' . print_r($this->chunkHashes, TRUE));
-                       assert($this->isChunkHashValid(array(
+                       assert($this->isChunkHashValid([
                                self::CHUNK_SPLITS_INDEX_HASH     => $this->finalPackageChunks['hashes'][$serialNumber],
                                self::CHUNK_SPLITS_INDEX_RAW_DATA => $content
-                       )));
+                       ]));
 
                        // ... and is also in the hash chunk?
                        assert(in_array($this->finalPackageChunks['hashes'][$serialNumber], $this->chunkHashes));
@@ -394,7 +399,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        // Verification okay, add it to the raw data
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Adding %d bytes as raw package data ...', strlen($content)));
                        $this->rawPackageData .= $content;
-               } // END - foreach
+               }
 
                // The last chunk hash must match with the one from eopChunk[1]
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk[1]=%s,index=%d,chunkHashes()=%d', $this->eopChunk[1], (count($this->chunkHashes) - 2), count($this->chunkHashes)));
@@ -452,18 +457,26 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         *
         * @param       $chunks         An array with chunks and (hopefully) a valid final chunk
         * @return      $isValid        Whether the final (last) chunk is valid
+        * @throws      UnexpectedValueException        If some unexpected value was found
         */
        private function isValidFinalChunk (array $chunks) {
                // Default is all fine
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunks()=%d - CALLED!', count($chunks)));
                $isValid = TRUE;
 
+               // Get EOP chunk
+               $chunk = $chunks[count($chunks) - 1];
+
                // Split the (possible) EOP chunk
-               $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
+               $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk);
 
                // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler)
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: eopChunk=%s,chunkSplits=%s', $chunks[count($chunks) - 1], print_r($chunkSplits, TRUE)));
-               assert(count($chunkSplits) == 3);
+               if (count($chunkSplits) != 3) {
+                       // Must be 3 elements exact
+                       throw new UnexpectedValueException(sprintf('chunk=%s has %d splits, must be exact 3.', $chunk, count($chunkSplits)));
+               }
 
                // Validate final chunk
                if (substr($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
@@ -502,14 +515,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        // Then get it first and add it before the EOP chunks
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: Popping entry from stack %s ...', self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
                        array_unshift($chunks, $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL));
-               } // END - while
+               }
 
                // Add all chunks to the FIFO stacker
                foreach ($chunks as $chunk) {
                        // Add the chunk
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
                        $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP, $chunk);
-               } // END - foreach
+               }
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
@@ -528,7 +541,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                        // Add the chunk
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
                        $this->getStackInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITHOUT_FINAL, $chunk);
-               } // END - foreach
+               }
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
@@ -555,15 +568,18 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
         * iterator.
         *
         * @return      void
+        * @throws      UnexpectedValueException        If some unexpected value was found
         */
        public function handleAvailableChunksWithFinal () {
                // First check if there are undhandled chunks available
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: CALLED!');
                assert($this->ifUnhandledChunksWithFinalAvailable());
 
                // Get an entry from the stacker
                $chunk = $this->getStackInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
 
                // Split the string with proper separator character
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunk=%s', $chunk));
                $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk);
 
                /*
@@ -572,7 +588,11 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                 * 1 = Serial number
                 * 2 = Raw data
                 */
-               assert(count($chunkSplits) == 3);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d', count($chunkSplits)));
+               if (count($chunkSplits) != 3) {
+                       // Must be 3 elements exact
+                       throw new UnexpectedValueException(sprintf('chunk=%s has %d splits, must be exact 3.', $chunk, count($chunkSplits)));
+               }
 
                // Is the generated hash from data same ("valid") as given hash?
                if (!$this->isChunkHashValid($chunkSplits)) {
@@ -593,7 +613,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
 
                        // Don't process this chunk
                        return;
-               } // END - if
+               }
 
                /*
                 * It is now known that (as long as the hash algorithm has no
@@ -609,7 +629,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera
                if ($this->getStackInstance()->isStackEmpty(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP)) {
                        // Then mark the final array as complete
                        $this->markFinalArrayAsCompleted();
-               } // END - if
+               }
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CHUNK-HANDLER: EXIT!');
index ec409c7960ae08de978220ba650d20a2ab69c8d7..7cb897007c09c5c6398fa636710f224f24d909cd 100644 (file)
@@ -270,7 +270,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
                        // Return the raw data
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: rawData()=' . strlen($chunkData[0]) . ' bytes.');
                        $rawData = $chunkData[0];
-               } // END - if
+               }
 
                // Return raw data
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawData(%d)=%s - EXIT!', strlen($rawData), $rawData));
@@ -301,10 +301,8 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
         * @return      void
         */
        public function sendRawPackageData (DeliverablePackage $packageInstance) {
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-
                // The helper's state must be 'connected'
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->getStateInstance()->validatePeerStateConnected();
 
                // Implode the package data array and fragement the resulting string, returns the final hash
@@ -312,11 +310,11 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
 
                // Is the final hash set?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
-               if ($finalHash !== TRUE) {
+               if (is_string($finalHash) && !empty($finalHash)) {
                        // Set final hash
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: Setting finalHash=%s,currentFinalHash[%s]=%s', $finalHash, gettype($this->currentFinalHash), $this->currentFinalHash));
                        $this->currentFinalHash = $finalHash;
-               } // END - if
+               }
 
                // Reset serial number
                $this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
@@ -337,12 +335,12 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
                                // Abort here
                                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-CONNECTION-HELPER: dataStream is now empty, exiting loop ...');
                                break;
-                       } // END - if
+                       }
 
                        // Add raw data
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: Adding %d bytes to the sending buffer ...', strlen($dataStream)));
                        $rawData .= $dataStream;
-               } // END - while
+               }
 
                // Calculate buffer size
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: rawData()=%d - after loop ...', strlen($rawData)));
@@ -354,14 +352,14 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
 
                // Init array
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: socketResource[%s]=%s', gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource()));
-               $encodedDataArray = array(
+               $encodedDataArray = [
                        NetworkPackageHandler::RAW_INDEX_FINAL_HASH      => $this->currentFinalHash,
                        NetworkPackageHandler::RAW_INDEX_ENCODED_DATA    => $encodedData,
                        NetworkPackageHandler::RAW_INDEX_SENT_BYTES      => 0,
                        NetworkPackageHandler::RAW_INDEX_SOCKET_INSTANCE => $this->getSocketInstance(),
                        NetworkPackageHandler::RAW_INDEX_BUFFER_SIZE     => $bufferSize,
                        NetworkPackageHandler::RAW_INDEX_DIFF            => ($bufferSize - strlen($encodedData)),
-               );
+               ];
 
                // Push raw data to the package's outgoing stack
                $this->getPackageHandlerInstance()->getStackInstance()->pushNamed(NetworkPackageHandler::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
index fe2cfc915e42bd750511c21e30f071be339834a3..8d58abffe77612dd37c480d27c0fa230841f2127 100644 (file)
@@ -336,10 +336,17 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
         * @return      void
         */
        public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
+               // Find node by id
+               $resultInstance = $this->getFrontendInstance()->findFirstNodeData();
+
                // Is there a node id?
-               if ($this->getFrontendInstance()->ifNodeDataIsFound($this)) {
+               if ($resultInstance->valid()) {
+                       // Get current record
+                       $nodeData = $resultInstance->current();
+
                        // Get the node id from result and set it
-                       $this->setNodeId($this->getField(NodeInformationDatabaseFrontend::DB_COLUMN_NODE_ID));
+                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
+                       $this->setNodeId($resultInstance->getField(NodeInformationDatabaseFrontend::DB_COLUMN_NODE_ID));
 
                        // Output message
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
@@ -401,10 +408,13 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
         * @return      void
         */
        public function bootstrapGeneratePrivateKey () {
+               // Find node by id
+               $resultInstance = $this->getFrontendInstance()->findFirstNodeData();
+
                // Is it valid?
-               if ($this->getFrontendInstance()->ifNodeDataIsFound($this)) {
+               if ($resultInstance->valid()) {
                        // Is the element set?
-                       if (is_null($this->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY))) {
+                       if (is_null($this->getFrontendInstance()->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY))) {
                                /*
                                 * Auto-generate the private key for e.g. out-dated database
                                 * "tables". This allows a smooth update for the underlaying
@@ -413,8 +423,8 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                                $this->generatePrivateKeyAndHash($this->getSearchInstance());
                        } else {
                                // Get the node id from result and set it
-                               $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY)));
-                               $this->setNodePrivateKeyHash($this->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY_HASH));
+                               $this->setPrivateKey(base64_decode($this->getFrontendInstance()->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY)));
+                               $this->setNodePrivateKeyHash($this->getFrontendInstance()->getField(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY_HASH));
 
                                // Output message
                                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getNodePrivateKeyHash() . '');
index c27fcb807b59242d5113b5c59223c3ba79cb753c..7274760bdf1bcb34174acf605dd5a3a488201458 100644 (file)
@@ -399,10 +399,8 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable,
         * @return      $isset  Whether start/end marker are set
         */
        private function ifStartEndMarkersSet (string $data) {
-               // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: data()=%d - CALLED!', strlen($data)));
-
                // Determine it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: data()=%d - CALLED!', strlen($data)));
                $isset = (
                        (
                                substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER
index fb99c473d9349fdebc0cb32f44a0bcff7b03d034..0b180dd57863f8fe627ba3eccb18d9779fef60d8 100644 (file)
@@ -77,6 +77,12 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private $processedPackages = [];
 
+       /**
+        * Array for markers (TRUE) of processed packages, same index position as
+        * above array.
+        */
+       private $isProcessedPackage = [];
+
        /**
         * Serial numbers (array key is final hash)
         */
@@ -212,9 +218,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // Is the array index there?
                $isProcessed = (
                        (
-                               isset($this->processedPackages[$index])
+                               isset($this->isProcessedPackage[$index])
                        ) && (
-                               $this->processedPackages[$index] === TRUE
+                               $this->isProcessedPackage[$index] === TRUE
                        )
                );
 
@@ -232,7 +238,7 @@ 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()));
-               $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = TRUE;
+               $this->isProcessedPackage[$this->getProcessedPackagesIndex($packageInstance)] = TRUE;
        }
 
        /**
@@ -243,11 +249,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        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()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)]));
 
                // Return it
-               return $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)];
+               $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));
+               return $finalHash;
        }
 
        /**
@@ -533,7 +543,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        $finalHash = $this->generateHashFromRawData($rawData);
 
                        // Remember it
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
                        $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash;
 
                        // Init pointer and reset serial number
@@ -552,7 +562,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        // Get the final hash from the package data
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('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', $finalHash));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
                }
 
                // Return final hash
index 68a4243c9afd0d912b8e27427ea067dec2bef2a0..91870c868665353a1d4cb768ddb9c1c0cb77e635 100644 (file)
@@ -9,6 +9,9 @@ use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData;
 use Org\Mxchange\CoreFramework\Stream\BaseStream;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A RawDataOutputStream class
  *
@@ -60,10 +63,15 @@ class RawDataOutputStream extends BaseStream implements OutputStream {
         *
         * @param       $data   The data (string mostly) to "stream"
         * @return      $data   The data (string mostly) to "stream"
+        * @throws      InvalidArgumentException        If the parameter is invalid
         */
        public function streamData (string $data) {
-               // Trace message
+               // Is it not empty?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-OUTPUT-STREAM: data()=%d - CALLED!', strlen($data)));
+               if (empty($data)) {
+                       // Invalid parameter
+                       throw new InvalidArgumentException('Parameter "data" is empty');
+               }
 
                /*
                 * Encode the data with BASE64 encoding and put it in a "frame":
index b03d17188fa42bb49261b938cc87928f58f10a25..cdcd5a15a52ee62a8f48c86d6bf4639e1944d9c7 100644 (file)
@@ -3,7 +3,7 @@
 namespace Org\Shipsimu\Hub\Database\Frontend\Node;
 
 // Import application-specific stuff
-use Org\Shipsimu\Hub\Node\BaseHubNode;
+use Org\Shipsimu\Hub\Node\Node;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria;
@@ -36,10 +36,10 @@ interface NodeInformationFrontend extends DatabaseFrontend {
         * 'Registers' a new node id along with data provided in the node instance.
         * This may sound confusing but avoids double code very nicely...
         *
-        * @param       $nodeInstance           A node instance
+        * @param       $nodeInstance           An instance of a Node class
         * @return      void
         */
-       function registerNodeId (BaseHubNode $nodeInstance);
+       function registerNodeId (Node $nodeInstance);
 
        /**
         * 'Registers' a new session id along with data provided in the node instance.
@@ -49,7 +49,7 @@ interface NodeInformationFrontend extends DatabaseFrontend {
         * @param       $searchInstance         An instance of a LocalSearchCriteria class
         * @return      void
         */
-       function registerSessionId (BaseHubNode $nodeInstance, LocalSearchCriteria $searchInstance);
+       function registerSessionId (Node $nodeInstance, LocalSearchCriteria $searchInstance);
 
        /**
         * 'Registers' a private key  along with data provided in the node instance.
@@ -60,6 +60,6 @@ interface NodeInformationFrontend extends DatabaseFrontend {
         * @param       $searchInstance         An instance of a LocalSearchCriteria class
         * @return      void
         */
-       function registerPrivateKey (BaseHubNode $nodeInstance, LocalSearchCriteria $searchInstance);
+       function registerPrivateKey (Node $nodeInstance, LocalSearchCriteria $searchInstance);
 
 }