From: Roland Häder Date: Thu, 7 Feb 2013 19:57:01 +0000 (+0000) Subject: Added wrapper, rewrites: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7b076b2eb413b1c28b7ce582bce5319da33e0bb3;p=hub.git Added wrapper, rewrites: - Added database wrapper for node DHT - Rewrote node_info_db wrapper to use special factory and not generic --- diff --git a/.gitattributes b/.gitattributes index 3289146a1..39f3e3323 100644 --- a/.gitattributes +++ b/.gitattributes @@ -163,6 +163,7 @@ application/hub/interfaces/visitor/tasks/class_TaskVisitor.php svneol=native#tex 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_NodeDhtWrapper.php svneol=native#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 @@ -216,6 +217,7 @@ application/hub/main/database/wrapper/.htaccess -text svneol=unset#text/plain application/hub/main/database/wrapper/cruncher/.htaccess svneol=native#text/plain application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php svneol=native#text/plain application/hub/main/database/wrapper/node/.htaccess svneol=native#text/plain +application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php svneol=native#text/plain application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php svneol=native#text/plain application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php svneol=native#text/plain application/hub/main/database/wrapper/states/.htaccess svneol=native#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 2df932355..853c88b02 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -48,6 +48,9 @@ $cfg->setConfigEntry('debug_class', 'DebugConsoleOutput'); // CFG: NODE-INFO-DB-WRAPPER-CLASS $cfg->setConfigEntry('node_info_db_wrapper_class', 'NodeInformationDatabaseWrapper'); +// CFG: NODE-DHT-DB-WRAPPER-CLASS +$cfg->setConfigEntry('node_dht_db_wrapper_class', 'NodeDistributedHashTableDatabaseWrapper'); + // CFG: PEER-LOOKUP-DB-WRAPPER-CLASS $cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'PeerStateLookupDatabaseWrapper'); diff --git a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php new file mode 100644 index 000000000..d3ac64c28 --- /dev/null +++ b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php @@ -0,0 +1,28 @@ + + * @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 NodeDhtWrapper extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php new file mode 100644 index 000000000..b9ea83a50 --- /dev/null +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -0,0 +1,56 @@ + + * @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 NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implements NodeDhtWrapper, Registerable { + // Constants for database table names + const DB_TABLE_NODE_DHT = 'node_dht'; + + /** + * 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 createNodeDistributedHashTableDatabaseWrapper () { + // Get a new instance + $wrapperInstance = new NodeDistributedHashTableDatabaseWrapper(); + + // Set (primary!) table name + $wrapperInstance->setTableName(self::DB_TABLE_NODE_DHT); + + // Return the instance + return $wrapperInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php index 9f4ab76c6..03447d81d 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 implements NodeInformationWrapper { +class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper, Registerable { // Constants for database table names const DB_TABLE_NODE_INFORMATION = 'node_data'; diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 5007c47f0..44efb9a1b 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -41,6 +41,12 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { // Get new instance $dhtInstance = new NodeDhtFacade(); + // Get a database wrapper instance + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_dht_db_wrapper_class'); + + // Set it in this class + $dhtInstance->setWrapperInstance($wrapperInstance); + // Return the prepared instance return $dhtInstance; } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 6af32bc73..8f3d1864d 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -77,6 +77,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Call parent constructor parent::__construct($className); + // Get a wrapper instance + $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_info_db_wrapper_class'); + + // Set it here + $this->setWrapperInstance($wrapperInstance); + // Get a crypto instance $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); @@ -136,11 +142,8 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString)); $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey())); - // Get a wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class'); - // Register the node id with our wrapper - $wrapperInstance->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance); + $this->getWrapperInstance()->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance); // Output message self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); @@ -274,9 +277,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * @return void */ public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) { - // Get a wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class'); - // Now get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -286,7 +286,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $searchInstance->setLimit(1); // Get a result back - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance); // Is it valid? if ($resultInstance->next()) { @@ -306,7 +306,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString))); // Register the node id with our wrapper - $wrapperInstance->registerNodeId($this, $this->getRequestInstance()); + $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance()); // Output message self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . ''); @@ -333,11 +333,8 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Hash and encrypt the string so we become a "node id" aka Hub-Id $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString))); - // Get a wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class'); - // Register the node id with our wrapper - $wrapperInstance->registerSessionId($this, $this->getRequestInstance(), $searchInstance); + $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance); // Output message self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . ''); @@ -352,9 +349,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * @return void */ public function bootstrapGeneratePrivateKey () { - // Get a wrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class'); - // Now get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -364,7 +358,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $searchInstance->setLimit(1); // Get a result back - $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance); // Is it valid? if ($resultInstance->next()) {