// 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
}
/**
- * 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
$resultInstance = $this->doSelectByCriteria($searchInstance);
// Is it valid?
- $GLOBALS[__METHOD__] = $resultInstance->next();
+ $GLOBALS[__METHOD__] = ($resultInstance->next() ? $resultInstance : NULL);
}
// Return it
* '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));
* '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));
* '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));
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait;
+// Import SPL stuff
+use \UnexpectedValueException;
+
/**
* A Chunk handler
*
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!');
// 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);
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]);
// 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!');
// 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));
// 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)));
*
* @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) {
// 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!');
// 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!');
* 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);
/*
* 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)) {
// Don't process this chunk
return;
- } // END - if
+ }
/*
* It is now known that (as long as the hash algorithm has no
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!');
// 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));
* @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
// 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);
// 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)));
// 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);
* @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() . '');
* @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
$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() . '');
* @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
*/
private $processedPackages = [];
+ /**
+ * Array for markers (TRUE) of processed packages, same index position as
+ * above array.
+ */
+ private $isProcessedPackage = [];
+
/**
* Serial numbers (array key is final hash)
*/
// Is the array index there?
$isProcessed = (
(
- isset($this->processedPackages[$index])
+ isset($this->isProcessedPackage[$index])
) && (
- $this->processedPackages[$index] === TRUE
+ $this->isProcessedPackage[$index] === TRUE
)
);
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;
}
/**
*/
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;
}
/**
$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
// 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
use Org\Mxchange\CoreFramework\Stream\BaseStream;
use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A RawDataOutputStream class
*
*
* @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":
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;
* '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.
* @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.
* @param $searchInstance An instance of a LocalSearchCriteria class
* @return void
*/
- function registerPrivateKey (BaseHubNode $nodeInstance, LocalSearchCriteria $searchInstance);
+ function registerPrivateKey (Node $nodeInstance, LocalSearchCriteria $searchInstance);
}