*/
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!');
}
/**
*/
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
$fragmenterInstance->setCryptoInstance($cryptoInstance);
// Return the prepared instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('PACKAGE-FRAGMENTER: fragmenterInstance=%s - EXIT!', $fragmenterInstance->__toString()));
return $fragmenterInstance;
}
*/
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!');
}
/**
*/
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!');
}
/**
*/
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;
}
/**
*/
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])
);
// 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;
}
*/
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!');
}
/**
* @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;
}
* 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;
}
/**
* @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!');
}
/**
*/
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) -
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;
}
* 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;
}
*/
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!');
}
/**
* @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!');
}
/**
*/
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
);
// 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] = [];
}
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('PACKAGE-FRAGMENTER: EXIT!');
}
/**
*/
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!');
}
/**
*
* @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;
}
*/
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(),
);
// 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
$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;
}
*/
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');
// 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;
}
*
* @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!');
}
}