// CFG: STACKER-INCOMING-QUEUE-MAX-SIZE
$cfg->setConfigEntry('stacker_incoming_queue_max_size', 100000);
-// CFG: STACKER-DECODED-DATA-MAX-SIZE
-$cfg->setConfigEntry('stacker_decoded_data_max_size', 100);
+// CFG: STACKER-RAW-DATA-MAX-SIZE
+$cfg->setConfigEntry('stacker_raw_data_max_size', 100);
// CFG: STACKER-FINAL-CHUNKS-MAX-SIZE
$cfg->setConfigEntry('stacker_final_chunks_max_size', 100);
/**
* Checks whether decoded packages have arrived (for this peer)
*
- * @return $ifDecodedPackagesLeft Whether decoded packages have arrived
+ * @return $ifRawPackagesLeft Whether decoded packages have arrived
*/
function ifDeocedPackagesLeft ();
/**
* Tries to discover all recipients by given decoded package data.
*
- * @param $decodedData Decoded raw package data array
+ * @param $decodedData Raw raw package data array
* @return void
*/
- function discoverDecodedRecipients (array $decodedData);
+ function discoverRawRecipients (array $decodedData);
/**
* "Getter" for recipient iterator
*
* @return $isPending Whether decoded data is pending
*/
- function isDecodedDataPending ();
+ function isRawDataPending ();
/**
* "Getter" for next decoded data from the stacker
*
- * @return $decodedData Decoded data from the stacker
+ * @return $decodedData Raw data from the stacker
*/
- function getNextDecodedData ();
+ function getNextRawData ();
}
// [EOF]
*
* @return void
*/
- function handleIncomingDecodedData ();
+ function handleIncomingRawData ();
/**
* Checks whether incoming decoded data is handled.
*
* @return $isHandled Whether incoming decoded data is handled
*/
- function isIncomingDecodedDataHandled ();
+ function isIncomingRawDataHandled ();
/**
* Assembles incoming decoded data so it will become an abstract network
*
* @return void
*/
- function assembleDecodedDataToPackage ();
+ function assembleRawDataToPackage ();
/**
* Checks whether a new message has arrived
* @param $handlerInstance An instance of a Networkable class
* @return void
*/
- function addDecodedDataToIncomingStack (Networkable $handlerInstance);
+ function addRawDataToIncomingStack (Networkable $handlerInstance);
/**
* "Decode" the package content. This method does also verify the attached hash
* @param $decodedData An array with decoded raw package data
* @return void
*/
- function handleDecodedData (array $decodedData);
+ function handleRawData (array $decodedData);
}
// [EOF]
$discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
// ... then disover all recipient (might be only one), this package may shall be forwarded
- $discoveryInstance->discoverDecodedRecipients($decodedData);
+ $discoveryInstance->discoverRawRecipients($decodedData);
// Check for 'recipient' field (the 'sender' field and others are ignored here)
if ($discoveryInstance->isRecipientListEmpty()) {
$this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_PACKAGE, $decodedData);
} else {
// Forward the package to the next node
- $this->getPackageInstance()->forwardDecodedPackage($decodedData);
+ $this->getPackageInstance()->forwardRawPackage($decodedData);
}
}
/**
* Checks whether decoded packages have arrived (for this peer)
*
- * @return $ifDecodedPackagesLeft Whether decoded packages have arrived
+ * @return $ifRawPackagesLeft Whether decoded packages have arrived
*/
public function ifDeocedPackagesLeft () {
// Check it ...
- $ifDecodedPackagesLeft = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
+ $ifRawPackagesLeft = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_PACKAGE));
// ... return it
- return $ifDecodedPackagesLeft;
+ return $ifRawPackagesLeft;
}
/**
$decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_PACKAGE);
// Handle it
- $this->getPackageInstance()->handleDecodedData($decodedData);
+ $this->getPackageInstance()->handleRawData($decodedData);
}
}
/**
* Tries to discover all recipients by given decoded package data.
*
- * @param $decodedData Decoded raw package data array
+ * @param $decodedData Raw raw package data array
* @return void
* @todo Add some validation of recipient field, e.g. ip:port is found
* @todo The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
*/
- public function discoverDecodedRecipients (array $decodedData) {
+ public function discoverRawRecipients (array $decodedData) {
// First clear all recipients
$this->clearRecipients();
const PACKAGE_ERROR_CODE = 'error_code';
/**
- * Stacker for decoded data
+ * Stacker for raw data
*/
- const STACKER_NAME_DECODED_DATA = 'decoded_data';
+ const STACKER_NAME_RAW_DATA = 'raw_data';
/**
* Error code from socket
// Set error code to 'unknown'
$this->setErrorCode(self::SOCKET_ERROR_UNKNOWN);
- // Get an input stream instance
- $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
-
- // Set it in this network-package handler
- $this->setInputStreamInstance($streamInstance);
-
// Init stacker instance for processed raw data
$stackerInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
* @return void
*/
protected function initStacker () {
- $this->getStackerInstance()->initStacker(self::STACKER_NAME_DECODED_DATA);
+ $this->getStackerInstance()->initStacker(self::STACKER_NAME_RAW_DATA);
}
/**
- * Adds given decoded data to the raw data stacker
+ * Adds given raw data to the raw data stacker
*
- * @param $decodedData Decoded data from the socket resource
+ * @param $rawData raw data from the socket resource
* @return void
*/
- protected function addDecodedDataToStacker ($decodedData) {
+ protected function addRawDataToStacker ($rawData) {
/*
* Add the deocoded data and error code to the stacker so other classes
* (e.g. NetworkPackage) can "pop" it from the stacker.
*/
- $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_DATA, array(
- self::PACKAGE_DECODED_DATA => $decodedData,
- self::PACKAGE_ERROR_CODE => $this->getErrorCode()
+ $this->getStackerInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array(
+ self::PACKAGE_RAW_DATA => $rawData,
+ self::PACKAGE_ERROR_CODE => $this->getErrorCode()
));
}
/**
- * Checks whether decoded data is pending for further processing.
+ * Checks whether raw data is pending for further processing.
*
- * @return $isPending Whether decoded data is pending
+ * @return $isPending Whether raw data is pending
*/
- public function isDecodedDataPending () {
+ public function isRawDataPending () {
// Does the stacker have some entries (not empty)?
- $isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_DATA));
+ $isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
// Return it
return $isPending;
}
/**
- * "Getter" for next decoded data from the stacker
+ * "Getter" for next raw data from the stacker
*
- * @return $decodedData Decoded data from the stacker
+ * @return $rawData Raw data from the stacker
*/
- public function getNextDecodedData () {
- // "Pop" the decoded data from the stacker
- $decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_DATA);
+ public function getNextRawData () {
+ // "Pop" the raw data from the stacker
+ $rawData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
// And return it
- return $decodedData;
+ return $rawData;
}
/**
// Reset error code to unhandled
$this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
- // Init variables
- $decodedData = false;
-
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $socketArray[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror(socket_last_error($socketArray[BasePool::SOCKET_ARRAY_RESOURCE])));
} elseif (empty($rawData)) {
// The peer did send nothing to us which is now being ignored
return;
- } else {
- /*
- * Low-level checks of the raw data went all fine, now decode the
- * raw data. This may still fail because of invalid encoded data.
- */
- try {
- $decodedData = $this->getInputStreamInstance()->streamData($rawData);
- } catch (AssertionException $e) {
- /*
- * This may happen with a multi-chunk stream (more data sent
- * than output/input buffers can handle) so the raw data needs
- * to be handled somewhere else.
- */
- $decodedData = $rawData;
- }
}
- // Add the (maybe above decoded) data to the stacker
- $this->addDecodedDataToStacker($decodedData);
+ // Add the raw data to the stacker
+ $this->addRawDataToStacker($rawData);
}
}
} // END - if
// Does the handler have some decoded data pending?
- if (!$handlerInstance->isDecodedDataPending()) {
+ if (!$handlerInstance->isRawDataPending()) {
// No data is pending so skip further code silently
return;
} // END - if
* if the decoded data origins from a TCP or UDP connection so we can
* just pass it over to the network package receiver
*/
- $receiverInstance->addDecodedDataToIncomingStack($handlerInstance);
+ $receiverInstance->addRawDataToIncomingStack($handlerInstance);
}
}
/**
* "Getter" for hash from given content and sender's session id
*
- * @param $decodedContent Decoded package content
+ * @param $decodedContent Raw package content
* @param $sessionId Session id of the sender
* @return $hash Hash for given package content
*/
*
* @return $isPending Whether decoded raw data is pending
*/
- private function isDecodedDataPending () {
+ private function isRawDataPending () {
// Just return whether the stack is not empty
$isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
$poolInstance->accept($this->getVisitorInstance());
// Check for new data arrival
- $hasArrived = $this->isDecodedDataPending();
+ $hasArrived = $this->isRawDataPending();
// Return the status
return $hasArrived;
*
* @return void
*/
- public function handleIncomingDecodedData () {
+ public function handleIncomingRawData () {
/*
* This method should only be called if decoded raw data is pending,
* so check it again.
*/
- if (!$this->isDecodedDataPending()) {
+ if (!$this->isRawDataPending()) {
// This is not fatal but should be avoided
// @TODO Add some logging here
return;
* @param $handlerInstance An instance of a Networkable class
* @return void
*/
- public function addDecodedDataToIncomingStack (Networkable $handlerInstance) {
+ public function addRawDataToIncomingStack (Networkable $handlerInstance) {
/*
* Get the decoded data from the handler, this is an array with
* 'decoded_data' and 'error_code' as elements.
*/
- $decodedData = $handlerInstance->getNextDecodedData();
+ $decodedData = $handlerInstance->getNextRawData();
// Very noisy debug message:
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true));
*
* @return $isHandled Whether incoming decoded data is handled
*/
- public function isIncomingDecodedDataHandled () {
+ public function isIncomingRawDataHandled () {
// Determine if the stack is not empty
$isHandled = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED));
*
* @return void
*/
- public function assembleDecodedDataToPackage () {
+ public function assembleRawDataToPackage () {
// Make sure the raw decoded package data is handled
- assert($this->isIncomingDecodedDataHandled());
+ assert($this->isIncomingRawDataHandled());
- // Get current package content (an array with two elements; see handleIncomingDecodedData() for details)
+ // Get current package content (an array with two elements; see handleIncomingRawData() for details)
$packageContent = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECODED_HANDLED);
// Start assembling the raw package data array by chunking it
* @return void
* @throws InvalidDataChecksumException If the checksum doesn't match
*/
- public function handleDecodedData (array $decodedData) {
+ public function handleRawData (array $decodedData) {
/*
* "Decode" the package's content by a simple explode() call, for
* details of the array elements, see comments for constant
* XML) and then pushing it on the next stack "processed messages".
*/
$this->getPackageInstance()->handleNewlyArrivedMessage();
- } elseif ($this->getPackageInstance()->isIncomingDecodedDataHandled()) {
+ } elseif ($this->getPackageInstance()->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).
*/
- $this->getPackageInstance()->assembleDecodedDataToPackage();
+ $this->getPackageInstance()->assembleRawDataToPackage();
} elseif ($this->getPackageInstance()->isNewRawDataPending($this->getListenerPoolInstance())) {
// Raw, decoded data has been received
- $this->getPackageInstance()->handleIncomingDecodedData();
+ $this->getPackageInstance()->handleIncomingRawData();
} elseif ($this->getPackageInstance()->ifAssemblerHasPendingDataLeft()) {
// Handle any pending data from the package assembler
$this->getPackageInstance()->handleAssemblerPendingData();