$unhandledDataLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(ChunkHandler::STACKER_NAME_ASSEMBLED_RAW_DATA));
// Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: unhandledDataLeft=' . intval($unhandledDataLeft));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: unhandledDataLeft=' . intval($unhandledDataLeft) . ' - EXIT!');
return $unhandledDataLeft;
}
*/
public function handleRawPackageData () {
// Assert on it to make sure the next popNamed() call won't throw an exception
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: CALLED!');
assert($this->ifUnhandledRawPackageDataLeft());
// "Pop" the next raw package content
*/
public function ifDeocedPackagesLeft () {
// Check it ...
- $ifRawPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
+ $ifDecodedPackagesLeft = (!$this->getHandlerInstance()->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
// ... return it
- return $ifRawPackagesLeft;
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: ifDecodedPackagesLeft=' . intval($ifDecodedPackagesLeft) . ' - EXIT!');
+ return $ifDecodedPackagesLeft;
}
/**
// Handle it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: packageInstance=' . $packageInstance->__toString() . ')=' . print_r($packageInstance, TRUE));
- $this->getPackageHandlerInstance()->handleRawData($packageInstance);
+ $this->getPackageHandlerInstance()->handleReceivedPackageInstance($packageInstance);
}
}
* 1: Raw package data
* 2: Tags, seperated by semicolons, no semicolon is required if only one tag is needed
* 3: Checksum
- * 0 1 2 3
*/
const PACKAGE_MASK = '%s%s%s%s%s%s%s';
/**
* Named array elements for decoded package content
*/
- const PACKAGE_CONTENT_EXTENSION = 'compressor';
+ const PACKAGE_CONTENT_COMPRESSOR = 'compressor';
const PACKAGE_CONTENT_MESSAGE = 'message';
const PACKAGE_CONTENT_TAGS = 'tags';
const PACKAGE_CONTENT_CHECKSUM = 'checksum';
const PACKAGE_STATUS_NEW = 'new';
const PACKAGE_STATUS_FAILED = 'failed';
const PACKAGE_STATUS_DECODED = 'decoded';
- const PACKAGE_STATUS_FAKED = 'faked';
/**
* Constants for message data array
*/
public function getHashFromContentSessionId (array $decodedContent, $sessionId) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]);
// Create the hash
// @TODO md5() is very weak, but it needs to be fast
self::PACKAGE_CHECKSUM_SEPARATOR .
$sessionId .
self::PACKAGE_CHECKSUM_SEPARATOR .
- $decodedContent[self::PACKAGE_CONTENT_EXTENSION]
+ $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]
);
// And return it
*/
public function decodeRawContent ($rawPackageContent) {
// Use the separator '#' to "decode" it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent(%d)=%s - CALLED!', strlen($rawPackageContent), $rawPackageContent));
$decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
// Assert on count (should be always 3)
$packageInstance->setSenderAddress($decodedArray[self::INDEX_PACKAGE_SENDER_ADDRESS]);
$packageInstance->setSenderPort($decodedArray[self::INDEX_PACKAGE_SENDER_PORT]);
$packageInstance->setRecipientId($decodedArray[self::INDEX_PACKAGE_RECIPIENT]);
+ $packageInstance->setRecipientType(self::NETWORK_TARGET_DIRECT);
$packageInstance->setPackageContent($decodedArray[self::INDEX_PACKAGE_CONTENT]);
$packageInstance->setStatus(self::PACKAGE_STATUS_DECODED);
$packageInstance->setContentHash($decodedArray[self::INDEX_PACKAGE_HASH]);
* @return void
* @throws InvalidDataChecksumException If the checksum doesn't match
*/
- public function handleRawData (DeliverablePackage $packageInstance) {
+ public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) {
/*
* "Decode" the package's content by a simple explode() call, for
* details of the array elements, see comments for constant
*/
$decodedContent = array(
// Compressor's extension used to compress the data
- self::PACKAGE_CONTENT_EXTENSION => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
+ self::PACKAGE_CONTENT_COMPRESSOR => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
// Package data (aka "message") in BASE64-decoded form but still compressed
self::PACKAGE_CONTENT_MESSAGE => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
// Tags as an indexed array for "tagging" the message
* @return void
*/
public function executeTask () {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
-
// Get package instance
- $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: packageInstance=%s', $packageInstance->__toString()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: CALLED!');
+ $handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
// Do we have something to handle?
- if ($packageInstance->isProcessedMessagePending()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleProcessedMessage() ...');
-
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-READER-TASK: handlerInstance=%s', $handlerInstance->__toString()));
+ if ($handlerInstance->isProcessedMessagePending()) {
/*
* A previously proccessed message is waiting for being
* "interpreted". This is done by trying to find a configuration
* entry based on 'message_type' element.
*/
- $packageInstance->handleProcessedMessage();
- } elseif ($packageInstance->isNewMessageArrived()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleNewlyArrivedMessage() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleProcessedMessage() ...');
+ $handlerInstance->handleProcessedMessage();
+ } elseif ($handlerInstance->isNewMessageArrived()) {
/*
* A fully "decoded" message has been received and added for being
* processed. Processing a message should not take long, so mostly
* as "XML variables" from the content (which must be a well-formed
* XML) and then pushing it on the next stack "processed messages".
*/
- $packageInstance->handleNewlyArrivedMessage();
- } elseif ($packageInstance->isIncomingRawDataHandled()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->assembleDecodedDataToPackage() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleNewlyArrivedMessage() ...');
+ $handlerInstance->handleNewlyArrivedMessage();
+ } elseif ($handlerInstance->isIncomingRawDataHandled()) {
/*
* Incoming decoded data has been handled (see below) so it needs to
- * be assembled back to a "package array". Please see NetworkPackage
- * for further details (what array elements are required et cetera).
+ * be assembled back to a package data instance. Please see
+ * PackageData for further details (what array elements are
+ * required et cetera).
*/
- $packageInstance->assembleDecodedDataToPackage();
- } elseif ($packageInstance->ifMultipleMessagesPending()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleMultipleMessages() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->assembleDecodedDataToPackage() ...');
+ $handlerInstance->assembleDecodedDataToPackage();
+ } elseif ($handlerInstance->ifMultipleMessagesPending()) {
/*
* Some raw data contained multiple messages which where now splitted.
*/
- $packageInstance->handleMultipleMessages();
- } elseif ($packageInstance->isNewRawDataPending()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleIncomingDecodedData() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleMultipleMessages() ...');
+ $handlerInstance->handleMultipleMessages();
+ } elseif ($handlerInstance->isNewRawDataPending()) {
// Raw, decoded data has been received
- $packageInstance->handleIncomingDecodedData();
- } elseif ($packageInstance->ifAssemblerHasPendingDataLeft()) {
- // Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling packageInstance->handleAssemblerPendingData() ...');
-
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleIncomingDecodedData() ...');
+ $handlerInstance->handleIncomingDecodedData();
+ } elseif ($handlerInstance->ifAssemblerHasPendingDataLeft()) {
// Handle any pending data from the package assembler
- $packageInstance->handleAssemblerPendingData();
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-READER-TASK: Calling handlerInstance->handleAssemblerPendingData() ...');
+ $handlerInstance->handleAssemblerPendingData();
}
// Trace message
$decoderInstance = DecoderFactory::createPackageDecoderInstance();
// Check if the stacker has some entries left
- if ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
- // Then handle it
- $decoderInstance->handleRawPackageData();
- } elseif ($decoderInstance->ifDeocedPackagesLeft()) {
- // Some decoded packages have arrived (for this peer)
+ if ($decoderInstance->ifDeocedPackagesLeft()) {
+ // Some decoded packages have arrived (for this node)
$decoderInstance->handleDecodedPackage();
+ } elseif ($decoderInstance->ifUnhandledRawPackageDataLeft()) {
+ // Handle raw data as last option to prevent that the stack runs full
+ $decoderInstance->handleRawPackageData();
}
}
function handleAssemblerPendingData ();
/**
- * Handles decoded data for this node
+ * Handles received package instance
*
* @param $packageInstance An instance of a DeliverablePackage class
* @return void
*/
- function handleRawData (DeliverablePackage $packageInstance);
+ function handleReceivedPackageInstance (DeliverablePackage $packageInstance);
/**
* Checks whether the assembler has multiple messages pending