* @return void
*/
function processMessage (array $messageData, Receivable $packageInstance);
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ function postProcessMessage (Receivable $packageInstance);
}
// [EOF]
* leads to an endless loop. You may wish to run the miner to get some
* reward ("HubCoins") for "mining" this hash.
*
- * @param $decodedDataArray Array with decoded message
+ * @param $messageData Array with message data
* @return void
*/
- function feedHashToMiner (array $decodedDataArray);
+ function feedHashToMiner (array $messageData);
}
// [EOF]
}
} // END - foreach
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Get all filters and "run" them
+ foreach ($this->getPostFilters() as $filterInstance) {
+ // Try to process it
+ try {
+ $filterInstance->postProcessMessage($packageInstance);
+ } catch (FilterChainException $e) {
+ // This exception can be thrown to just skip any further processing
+ self::createDebugInstance(__CLASS__)->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
+ break;
+ }
+ } // END - foreach
+ }
}
// [EOF]
// Add filter for handling hash to miner queue
$filterInstance = self::createObjectByConfiguredName('package_hash_to_miner_filter');
- // Add this filter to the chain
- $chainInstance->addFilter($filterInstance);
+ // Add this post-filter to the chain
+ $chainInstance->addPostFilter($filterInstance);
// Add the finished chain to the registry
Registry::getRegistry()->addInstance($registryKey, $chainInstance);
protected function genericProcessMessage ($messageType, array $messageData, Receivable $packageInstance) {
// Make sure the wanted element is there
assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_MESSAGE]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_SENDER]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_HASH]));
+ assert(isset($messageData[NetworkPackage::PACKAGE_CONTENT_TAGS]));
// Get a template instance from the factory
$templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_' . $messageType . '_template_class');
// Construct an array for pushing it on next stack
$messageArray = array(
// Message data itself
- NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes,
+ NetworkPackage::MESSAGE_ARRAY_DATA => $this->dataXmlNodes,
// Message type (which is $messageType)
- NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType
+ NetworkPackage::MESSAGE_ARRAY_TYPE => $messageType,
+ // Message sender
+ NetworkPackage::MESSAGE_ARRAY_SENDER => $messageData[NetworkPackage::PACKAGE_CONTENT_SENDER],
+ // Package hash
+ NetworkPackage::MESSAGE_ARRAY_SENDER => $messageData[NetworkPackage::PACKAGE_CONTENT_HASH],
+ // Package tags
+ NetworkPackage::MESSAGE_ARRAY_SENDER => $messageData[NetworkPackage::PACKAGE_CONTENT_TAGS],
);
// Push the processed message back on stack
}
/**
- * Processes the given raw message content. The method renderXmlContent
- * may throw (not the method itself) several exceptions:
- *
- * InvalidXmlNodeException - If an invalid XML node has been found (e.g.
- * wrong/out-dated template used)
- * XmlNodeMismatchException - Again might be caused by invalid XML node
- * usage
- * XmlParserException - If the XML message is damaged or not
- * well-formed
+ * Processes the given raw message content.
*
* @param $messageData Raw message data array
* @param $packageInstance An instance of a Receivable class
* @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
*/
public function processMessage (array $messageData, Receivable $packageInstance) {
- // Process message generic
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Post-processes the given raw message content. The method renderXmlContent
+ * may throw (not the method itself) several exceptions:
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Get current entry from stack
+ $messageData = $packageInstance->getStackInstance()->getNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE);
+
+ /*
+ * Feed hash to miner by handling over the whole array as also the
+ * sender and tags are needed.
+ */
$packageInstance->feedHashToMiner($messageData);
}
}
// Process message in generic way
$this->genericProcessMessage('announcement_answer', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process message in generic way
$this->genericProcessMessage('dht_bootstrap_answer', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process message in generic way
$this->genericProcessMessage('request_node_list_answer', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process message generic
$this->genericProcessMessage('announcement', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process message generic
$this->genericProcessMessage('dht_bootstrap', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process messasge generic
$this->genericProcessMessage('request_node_list', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
// Process generic
$this->genericProcessMessage('self_connect', $messageData, $packageInstance);
}
+
+ /**
+ * Post-processes the stacked message. Do not call popNamed() as then no
+ * other class can process the message.
+ *
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called, please use processMessage() instead!
+ */
+ public function postProcessMessage (Receivable $packageInstance) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
}
// [EOF]
/**
* Constants for message data array
*/
- const MESSAGE_ARRAY_DATA = 'message_data';
- const MESSAGE_ARRAY_TYPE = 'message_type';
+ const MESSAGE_ARRAY_DATA = 'message_data';
+ const MESSAGE_ARRAY_TYPE = 'message_type';
+ const MESSAGE_ARRAY_SENDER = 'message_sender';
+ const MESSAGE_ARRAY_HASH = 'message_hash';
+ const MESSAGE_ARRAY_TAGS = 'message_tags';
/**
* Generic answer status field
* @todo Implement verification of all sent tags here?
*/
public function handleNewlyArrivedMessage () {
+ // Make sure there is at least one message
+ assert($this->isNewMessageArrived());
+
// Get it from the stacker, it is the full array with the decoded message
$decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
* elements from $decodedContent are no longer needed.
*/
$chainInstance->processMessage($decodedContent, $this);
+
+ /*
+ * Post-processing of message data (this won't remote the message from
+ * the stack).
+ */
+ $chainInstance->postProcessMessage();
}
/**
* leads to an endless loop. You may wish to run the miner to get some
* reward ("HubCoins") for "mining" this hash.
*
- * @param $decodedDataArray Array with decoded message
+ * @param $messageData Array with message data
* @return void
* @todo ~10% done?
*/
- public function feedHashToMiner (array $decodedDataArray) {
+ public function feedHashToMiner (array $messageData) {
// Make sure the required elements are there
- assert(isset($decodedDataArray[self::PACKAGE_CONTENT_SENDER]));
- assert(isset($decodedDataArray[self::PACKAGE_CONTENT_HASH]));
- assert(isset($decodedDataArray[self::PACKAGE_CONTENT_TAGS]));
+ assert(isset($messageData[self::MESSAGE_ARRAY_SENDER]));
+ assert(isset($messageData[self::MESSAGE_ARRAY_HASH]));
+ assert(isset($messageData[self::MESSAGE_ARRAY_TAGS]));
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
// Resolve session id ('sender' is a session id) into node id
- $nodeId = HubTools::resolveNodeIdBySessionId($decodedDataArray[self::PACKAGE_CONTENT_SENDER]);
+ $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]);
// Is 'claim_reward' the message type?
- if (in_array('claim_reward', $decodedDataArray[self::PACKAGE_CONTENT_TAGS])) {
+ if (in_array('claim_reward', $messageData[self::MESSAGE_ARRAY_TAGS])) {
/*
* Then don't feed this message to the miner as this causes an
* endless loop of mining.
return;
} // END - if
- $this->partialStub('@TODO nodeId=' . $nodeId . ',decodedDataArray=' . print_r($decodedDataArray, TRUE));
+ $this->partialStub('@TODO nodeId=' . $nodeId . ',messageData=' . print_r($messageData, TRUE));
}
}
$nodeData = $selfInstance->getDhtInstance()->findNodeLocalBySessionId($sessionId);
// Make sure the node id is there
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ', nodeData[' . gettype($nodeData) . ']=' . print_r($nodeData, TRUE));
assert(isset($nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID]));
// Return it
-Subproject commit df57993ff615192c023c714c46dc5d52d3dffd89
+Subproject commit e10ada14e2f86607a9d165dac6f7fb154e0be4eb