* A general message handler, this class must be abstract to make the template
* method pattern working.
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
protected function getTranslatedStatusFromLastException () {
// Default is all fine
- $statusCode = self::MESSAGE_STATUS_CODE_OKAY;
+ $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
// Is the last exception not NULL?
if ($this->getLastException() instanceof FrameworkException) {
* following data must always be present:
*
* - session-id (for finding the node's record together with below data)
- * - external-ip (hostname or IP number)
- * - tcp-port (TCP port for inbound connections)
+ * - external-address (hostname or IP number)
+ * - listen-port (TCP/UDP listen port for inbound connections)
*
* @param $messageArray An array with all minimum message data
* @return void
- * @todo Add something more, e.g. spreading information over DHT
*/
protected function registerNodeByMessageData (array $messageData) {
// Check if searchData has entries
- assert(count($this->searchData) > 0);
- self::createDebugInstance(__CLASS__)->debugOutput('messageData=' . print_r($messageData, true));
+ assert(count($this->getSearchData()) > 0);
- // Get a wrapper instance
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
-
- // Get a search criteria class
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Search for the node's session id and external IP/hostname + TCP port
- foreach ($this->searchData as $key) {
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData=' . print_r($messageData,true));
-
- // Add criteria
- $searchInstance->addCriteria('node_' . str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
-
- // Only one entry is fine
- $searchInstance->setLimit(1);
-
- // Run the query
- $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
-
- // Is there already an entry?
- if ($resultInstance->next()) {
- // Entry found, so update it
- $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
- } else {
- // Nothing found, so register it
- $wrapperInstance->registerNodeByMessageData($messageData, $this);
- }
+ // Let the DHT facade do the work
+ $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
+ }
- // Save last exception
- $this->setLastException($wrapperInstance->getLastException());
+ /**
+ * Posty-handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
+ /*
+ * Feed hash to miner by handling over the whole array as also the
+ * sender and tags are needed.
+ */
+ $packageInstance->feedHashToMiner($messageData);
}
}