// Set the stacker in this handler
$handlerInstance->setStackerInstance($stackerInstance);
+ // Get a crypto instance ...
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+
+ // ... and set it in this handler
+ $handlerInstance->setCryptoInstance($cryptoInstance);
+
// Return the prepared instance
return $handlerInstance;
}
assert($this->ifUnhandledChunksAvailable());
// Get an entry from the stacker
- $chunk = $this->getStackerInstance()->getNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
+ $chunk = $this->getStackerInstance()->popNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP);
+
+ // Split the string with proper separator character
+ $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunk);
+
+ /*
+ * Make sure three elements are always found:
+ * 0 = Hash
+ * 1 = Serial number
+ * 2 = Raw data
+ */
+ assert(count($chunkSplits) == 3);
+
+ // Now hash the raw data again
+ $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[2], $chunkSplits[0], false);
+
+ // Debug output
+ /* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',chunkSplits[0]=' . $chunkSplits[0] . ',chunkSplits[1]=' . $chunkSplits[1]);
+
+ // Is it the same?
+ if ($chunkSplits[0] != $chunkHash) {
+ // Re-request this chunk (trust the hash in index # 0)
+ $this->rerequestChunkBySplitsArray($chunkSplits);
+
+ // Don't process this chunk
+ return;
+ } // END - if
die('chunk=' . $chunk . chr(10));
}
}
$this->getListInstance()->addEntry('tasks', $taskEntry);
// Debug message
- $this->debugOutput('TASK-HANDLER: Task ' . $taskName .
+ $this->debugOutput('TASK-HANDLER: Task registered: taskName=' . $taskName .
' (taskInstance=' . $taskInstance->__toString() . ')' .
', startupDelay=' . $taskEntry['task_startup_delay'] . 'ms' .
', intervalDelay=' . $taskEntry['task_interval_delay'] . 'ms' .
- ', maxRuns=' . $taskEntry['task_max_runs'] . ' times registered.'
+ ', maxRuns=' . $taskEntry['task_max_runs'] . ' ...'
);
}
* @return void
*/
public function doShutdown () {
- // Should we rewind?
- if (!$this->getIteratorInstance()->valid()) {
- // Rewind to the beginning for next loop
- $this->getIteratorInstance()->rewind();
- } // END - if
+ // Always rewind to the beginning for next loop
+ $this->getIteratorInstance()->rewind();
// Debug message
$this->debugOutput('TASK-HANDLER: Shutting down all ' . $this->getListInstance()->count() . ' tasks...');
* @return $hash Hash from the raw data
*/
private function generateHashFromRawData ($rawData) {
- // Get the crypto instance and hash the data
- $hash = $this->getCryptoInstance()->hashString($rawData);
+ /*
+ * Get the crypto instance and hash the data with no extra salt because
+ * the other peer doesn't have *this* peer's salt.
+ */
+ $hash = $this->getCryptoInstance()->hashString($rawData, '', false);
// Return it
return $hash;
$chunk = substr($rawData, $idx, $dataChunkSize);
// Hash it and remember it in seperate array
- $chunkHash = $this->getCryptoInstance()->hashString($chunk);
+ $chunkHash = $this->getCryptoInstance()->hashString($chunk, '', false);
$this->chunkHashes[$finalHash][] = $chunkHash;
// Prepend the hash to the chunk
$chunk = substr($rawData, $idx, $dataChunkSize);
// Hash it and remember it in seperate array
- $chunkHash = $this->getCryptoInstance()->hashString($chunk);
+ $chunkHash = $this->getCryptoInstance()->hashString($chunk, '', false);
array_unshift($this->chunkHashes[$finalHash], $chunkHash);
// Prepend the hash to the chunk