From e9dc00de46c8a00a5f1a05956f012d61eb1c1918 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 31 Jan 2013 15:44:05 +0000 Subject: [PATCH] Clear redundant database wrapper class as it is now done in DHT --- application/hub/config.php | 3 - .../node/class_NodeListDatabaseWrapper.php | 217 +----------------- .../class_AnnouncementAnswerOkayHandler.php | 1 + .../class_BaseAnserStatusHandler.php | 3 + ...class_RequestNodeListAnswerOkayHandler.php | 1 + .../class_BaseMessageHandler.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 26 +-- application/hub/main/tools/class_HubTools.php | 2 + 8 files changed, 10 insertions(+), 245 deletions(-) diff --git a/application/hub/config.php b/application/hub/config.php index 9e0d41805..47f92d0a2 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -48,9 +48,6 @@ $cfg->setConfigEntry('debug_class', 'DebugConsoleOutput'); // CFG: NODE-INFO-DB-WRAPPER-CLASS $cfg->setConfigEntry('node_info_db_wrapper_class', 'NodeInformationDatabaseWrapper'); -// CFG: NODE-LIST-DB-WRAPPER-CLASS -$cfg->setConfigEntry('node_list_db_wrapper_class', 'NodeListDatabaseWrapper'); - // CFG: PEER-LOOKUP-DB-WRAPPER-CLASS $cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'PeerStateLookupDatabaseWrapper'); diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 8b55018a1..f551ef47b 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -1,218 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements NodeListWrapper, Registerable { - // Table names - const DB_TABLE_NODE_LIST = 'node_list'; - - // Table columns - const DB_COLUMN_ANSWER_STATUS = 'last_answer_status'; - const DB_COLUMN_MESSAGE_TYPE = 'last_message_type'; - - // Other constants - const INVALID_IP_PORT = 'invalid:invalid'; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this database wrapper by a provided user class - * - * @return $wrapperInstance An instance of the created wrapper class - */ - public static final function createNodeListDatabaseWrapper () { - // Get a new instance - $wrapperInstance = new NodeListDatabaseWrapper(); - - // Set (primary!) table name - $wrapperInstance->setTableName(self::DB_TABLE_NODE_LIST); - - // Return the instance - return $wrapperInstance; - } - - /** - * Resolves a session id into an ip:port combination - * - * @param $sessionId A valid session id - * @param $protocol Name of the protocol (TCP/UDP) - * @return $recipient Recipient as ip:port combination - */ - public function resolveIpPortBySessionId ($sessionId, $protocol) { - // Set invalid ip:port combination - $recipient = self::INVALID_IP_PORT; - - // Now get a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Search for the node session id - $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, $sessionId); - $searchInstance->setLimit(1); - - // Get a result back - $resultInstance = $this->doSelectByCriteria($searchInstance); - - // Is it valid? - if ($resultInstance->next()) { - // Save the result instance in this class - $this->setResultInstance($resultInstance); - - // Get the node id from result and set it - $recipientIp = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP); - - // Which protocol? - switch ($protocol) { - case NetworkPackage::PROTOCOL_TCP: // Transmission Control Protocol has been used - $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT); - break; - - case NetworkPackage::PROTOCOL_UDP: // User Datagram Protocol has been used - $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT); - break; - - default: // Unsupported protocol detected! - $this->debugBackTrace('Unsupported protocol ' . $protocol . ' specified!'); - break; - } // END - switch - - // Now put both together - $recipient = $recipientIp . ':' . $recipientPort; - - // Debug message - self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: sessionId[' . $protocol . ']=' . $sessionId . ' resolved as recipient=' . $recipient); - } // END - if - - // Return result - return $recipient; - } - - /** - * Resolves a ip:port combination into a session id - * - * @param $ipPort Ip:port combination - * @param $protocol Name of the used protocol (TCP/UDP) - * @return $sessionId A valid session id - */ - public function resolveSessionIdByIpPort ($ipPort, $protocol) { - // Set invalid session id as default - $sessionId = 'invalid'; - - // Split ip:port - $ipPortArray = explode(':', $ipPort); - - // Now get a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Search for the node session id - $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, $ipPortArray[0]); - - // Which protocol? - switch ($protocol) { - case NetworkPackage::PROTOCOL_TCP: // Transmission Control Procol has been used - $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, $ipPortArray[1]); - break; - - case NetworkPackage::PROTOCOL_UDP: // User Datagram Protocol has been used - $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT, $ipPortArray[1]); - break; - - default: // Unsupported protocol detected! - $this->debugBackTrace('Unsupported protocol ' . $protocol . ' specified!'); - break; - } // END - switch - - // Only one record - $searchInstance->setLimit(1); - - // Get a result back - $resultInstance = $this->doSelectByCriteria($searchInstance); - - // Is it valid? - if ($resultInstance->next()) { - // Save the result instance in this class - $this->setResultInstance($resultInstance); - - // Get the session from result - $sessionId = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID); - } // END - if - - // Return result - return $sessionId; - } - - /** - * Registeres a node by given message data. - * - * @param $messageData An array of all message data - * @param $handlerInstance An instance of a HandleableMessage class - * @return void - */ - public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance) { - // Get a data set instance - $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_LIST)); - - // Set primary key (session id) - $dataSetInstance->setUniqueKey('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID); - - // Add all array elements - $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData); - - // Run the "INSERT" query - $this->queryInsertDataSet($dataSetInstance); - } - - /** - * Updates an existing entry in node list - * - * @param $messageData An array of all message data - * @param $handlerInstance An instance of a HandleableMessage class - * @param $searchInstance An instance of LocalSearchCriteria class - * @return void - */ - public function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance) { - // Get a data set instance - $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_LIST)); - - // Add search instance - $dataSetInstance->setSearchInstance($searchInstance); - - // Set primary key (session id) - $dataSetInstance->setUniqueKey('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID); - - // Add all array elements - $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData); - - // Run the "UPDATE" query - $this->queryUpdateDataSet($dataSetInstance); - } -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 05dbf779a..e0f708e4f 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -56,6 +56,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha * @return void * @throws NodeSessionIdVerficationException If the provided session id is not matching * @todo Do some more here: Handle karma, et cetera? + * @todo Rewrite this to use DHT */ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { // Get a database wrapper instance diff --git a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php index a4b198ae5..e3c81adaa 100644 --- a/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php +++ b/application/hub/main/handler/answer-status/class_BaseAnserStatusHandler.php @@ -50,11 +50,14 @@ abstract class BaseAnserStatusHandler extends BaseDataHandler { * @param $dataSetInstance An instance of a StoreableCriteria class * @param $messageData An array with all message data * @return void + * @todo Rewrite this to use DHT */ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) { // Add some generic data all messageData arrays provide + /* $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]); $dataSetInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_MESSAGE_TYPE , $messageData[NetworkPackage::MESSAGE_ARRAY_TYPE]); + */ } } diff --git a/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php b/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php index 0d4fd9b88..c3f775789 100644 --- a/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php @@ -56,6 +56,7 @@ class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements * @return void * @throws NodeSessionIdVerficationException If the provided session id is not matching * @todo Do some more here: Handle karma, et cetera? + * @todo Rewrite this to use DHT */ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) { // Get a database wrapper instance diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 7770d236b..864c3d37f 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -63,7 +63,7 @@ abstract class BaseMessageHandler extends BaseDataHandler { * * @param $messageArray An array with all minimum message data * @return void - * @todo Add something more, e.g. spreading information over DHT + * @todo Rewrite this to use DHT */ protected function registerNodeByMessageData (array $messageData) { // Check if searchData has entries diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index f207147bf..3795850ca 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -656,36 +656,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * Restores a previously stored node list from database * * @return void + * @todo Rewrite this to use DHT instead */ public function bootstrapRestoreNodeList () { // Debug output self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: START'); - // Get a wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class'); - - // Now get a search criteria instance - $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); - - // Search for the node number zero which is hard-coded the default - // @TODO Add some criteria, e.g. if the node is active or so - //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_NR, 1); - //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode')); - //$searchInstance->setLimit(1); - - // Get a result back - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); - - // Is it valid? - if ($resultInstance->next()) { - $this->partialStub('Do something for restoring the list.'); - // Output message - //self::createDebugInstance(__CLASS__)->debugOutput('HUB: '); - } else { - // No previously saved node list found! - self::createDebugInstance(__CLASS__)->debugOutput('HUB: No previously saved node list found. This is fine.'); - } - // Debug output self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: FINISHED.'); } diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 0d8b4f0d9..f0d1baf55 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -85,6 +85,7 @@ class HubTools extends BaseHubSystem { * @param $sessionId A valid session id * @param $protocol Name of the used protocol: TCP/UDP * @return $recipient Recipient as ip:port combination + * @todo Rewrite this to use DHT */ protected function resolveIpPortBySessionId ($sessionId, $protocol) { // Get a wrapper instance @@ -115,6 +116,7 @@ class HubTools extends BaseHubSystem { * @param $ipPort Ip:port combination * @param $protocol Name of used protocol (TCP/UDP) * @return $sessionId Valid session id + * @todo Rewrite this to use DHT */ public static function resolveSessionIdByIpPort ($ipPort, $protocol) { // Get a wrapper instance -- 2.39.5