From 11b36f339c5a97ec6afb6eb7244b825bc2812bf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 30 May 2012 21:02:55 +0000 Subject: [PATCH] Introduced (currently not used as type-hints) new interfaces: - Interface 'NodeInformationWrapper' introduced, this may help other developers to implement their own classes - Interface 'NodeListWrapper' introduced with same intension - TODOs.txt update --- .gitattributes | 3 + application/hub/interfaces/wrapper/.htaccess | 1 + .../wrapper/class_NodeInformationWrapper.php | 47 ++++++++++++++ .../wrapper/class_NodeListWrapper.php | 63 +++++++++++++++++++ .../class_NodeInformationDatabaseWrapper.php | 2 +- .../node/class_NodeListDatabaseWrapper.php | 23 ++++++- .../class_BaseMessageHandler.php | 5 +- docs/TODOs.txt | 7 ++- 8 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 application/hub/interfaces/wrapper/.htaccess create mode 100644 application/hub/interfaces/wrapper/class_NodeInformationWrapper.php create mode 100644 application/hub/interfaces/wrapper/class_NodeListWrapper.php diff --git a/.gitattributes b/.gitattributes index bfa2f9443..e50089001 100644 --- a/.gitattributes +++ b/.gitattributes @@ -145,6 +145,9 @@ application/hub/interfaces/visitor/tasks/.htaccess -text svneol=unset#text/plain application/hub/interfaces/visitor/tasks/class_TaskVisitor.php svneol=native#text/plain application/hub/interfaces/work_units/.htaccess svneol=native#text/plain application/hub/interfaces/work_units/class_UnitHelper.php svneol=native#text/plain +application/hub/interfaces/wrapper/.htaccess -text svneol=unset#text/plain +application/hub/interfaces/wrapper/class_NodeInformationWrapper.php svneol=native#text/plain +application/hub/interfaces/wrapper/class_NodeListWrapper.php svneol=native#text/plain application/hub/loader.php svneol=native#text/plain application/hub/main/.htaccess -text svneol=unset#text/plain application/hub/main/chat/.htaccess svneol=native#text/plain diff --git a/application/hub/interfaces/wrapper/.htaccess b/application/hub/interfaces/wrapper/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/wrapper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/wrapper/class_NodeInformationWrapper.php b/application/hub/interfaces/wrapper/class_NodeInformationWrapper.php new file mode 100644 index 000000000..df6fa7060 --- /dev/null +++ b/application/hub/interfaces/wrapper/class_NodeInformationWrapper.php @@ -0,0 +1,47 @@ + + * @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 . + */ +interface NodeInformationWrapper extends FrameworkInterface { + /** + * 'Registers' a new node id along with data provided in the node instance. + * This may sound confusing but avoids double code very nicely... + * + * @param $nodeInstance A node instance + * @param $requestInstance An instance of a Requestable class + * @return void + */ + function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance); + + /** + * 'Registers' a new session id along with data provided in the node instance. + * This may sound confusing but avoids double code very nicely... + * + * @param $nodeInstance A node instance + * @param $requestInstance An instance of a Requestable class + * @return void + */ + function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/wrapper/class_NodeListWrapper.php b/application/hub/interfaces/wrapper/class_NodeListWrapper.php new file mode 100644 index 000000000..702ff0d03 --- /dev/null +++ b/application/hub/interfaces/wrapper/class_NodeListWrapper.php @@ -0,0 +1,63 @@ + + * @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 . + */ +interface NodeListWrapper extends FrameworkInterface { + /** + * 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 + */ + function resolveIpPortBySessionId ($sessionId, $protocol); + + /** + * 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 + */ + function resolveSessionIdByIpPort ($ipPort, $protocol); + + /** + * 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 + */ + function registerNodeByMessageData (array $messageData, HandleableMessage $handlerInstance); + + /** + * Updates an existing entry in node list + * + * @param $messageData An array of all message data + * @param $handlerInstance An instance of a HandleableMessage class + * @return void + */ + function updateNodeByMessageData (array $messageData, HandleableMessage $handlerInstance); +} + +// [EOF] +?> diff --git a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php index 5f803f95b..86d14cece 100644 --- a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper { +class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper { // Constants for database table names const DB_TABLE_NODE_INFORMATION = 'node_data'; diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 4ec539e9c..6d4711446 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable { +class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements NodeListWrapper Registerable { // Table names const DB_TABLE_NODE_LIST = 'node_list'; @@ -183,6 +183,27 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl // 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 + * @return void + */ + public function updateNodeByMessageData (array $messageData, HandleableMessage $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 "UPDATE" query + $this->queryUpdateDataSet($dataSetInstance); + } } // [EOF] diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 5b2ff9ba2..4c8f30fc5 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -105,6 +105,7 @@ abstract class BaseMessageHandler extends BaseHandler { * * @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) { // Get a wrapper instance @@ -127,8 +128,8 @@ abstract class BaseMessageHandler extends BaseHandler { // Is there already an entry? if ($resultInstance->next()) { - // Entry found - $resultInstance->debugBackTrace('Entry found!'); + // Entry found, so update it + $wrapperInstance->updateNodeByMessageData($messageData, $this); } else { // Nothing found, so register it $wrapperInstance->registerNodeByMessageData($messageData, $this); diff --git a/docs/TODOs.txt b/docs/TODOs.txt index e5b432e1d..33c9dc9d3 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -50,6 +50,7 @@ ./application/hub/main/filter/task/chat/class_ChatTaskHandlerInitializerFilter.php:55: * @todo 5% done ./application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php:55: * @todo 5% done ./application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php:55: * @todo Maybe some more tasks needs to be added? +./application/hub/main/handler/message-types/class_BaseMessageHandler.php:108: * @todo Add something more, e.g. spreading information over DHT ./application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php:71: // @TODO Throw an exception here instead of dying ./application/hub/main/handler/network/class_BaseRawDataHandler.php:148: * @todo This method will be moved to a better place ./application/hub/main/handler/network/udp/class_UdpRawDataHandler.php:58: * @todo 0% @@ -138,7 +139,7 @@ ./application/hub/main/tasks/network/class_NetworkPackageWriterTask.php:59: * @todo Also visit some sub-objects? ./application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType() ./application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType() -./application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php:247: * @todo Find something useful with this! +./application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php:257: * @todo Find something useful with this! ./application/hub/main/template/connect/class_XmlSelfConnectTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType() ./application/hub/main/template/connect/class_XmlSelfConnectTemplateEngine.php:249: * @todo Find something useful with this! ./application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType() @@ -243,9 +244,9 @@ ./inc/classes/main/user/class_BaseUser.php:308: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem ./inc/classes/main/user/class_BaseUser.php:80: * @todo Find a way of casting here. "(int)" might destroy the user id > 32766 ./inc/classes/main/user/member/class_Member.php:84: * @todo Add more ways over creating user classes -./inc/classes/middleware/debug/class_DebugMiddleware.php:112: // @TODO Initialization phase +./inc/classes/middleware/debug/class_DebugMiddleware.php:113: // @TODO Initialization phase ./inc/classes.php:10: * @todo We should minimize these includes -./inc/config/class_FrameworkConfiguration.php:194: * @todo We have to add some more entries from $_SERVER here +./inc/config/class_FrameworkConfiguration.php:212: * @todo We have to add some more entries from $_SERVER here ./inc/database.php:11: * @todo We should minimize these includes ./inc/database.php:51:// @TODO Rewrite this ./inc/hooks.php:11: * @todo We should minimize these includes -- 2.39.5