]> git.mxchange.org Git - hub.git/commitdiff
Added wrapper, rewrites:
authorRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 19:57:01 +0000 (19:57 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 7 Feb 2013 19:57:01 +0000 (19:57 +0000)
- Added database wrapper for node DHT
- Rewrote node_info_db wrapper to use special factory and not generic

.gitattributes
application/hub/config.php
application/hub/interfaces/wrapper/class_NodeDhtWrapper.php [new file with mode: 0644]
application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/nodes/class_BaseHubNode.php

index 3289146a10b9ba0d12bd87e88374d90af989e0e4..39f3e3323a581d93d90bd669f25caeb054a89128 100644 (file)
@@ -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
index 2df9323551aa72944a11bf31c0e052b7113cd0f1..853c88b02edd6307ecdfd68964b575a2897f5499 100644 (file)
@@ -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 (file)
index 0000000..d3ac64c
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for distributed hash tables for nodes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..b9ea83a
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * A database wrapper for distributed hash tables
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 9f4ab76c6df6cd79bc34210d8503b1bdb9696cb6..03447d81d5b9815499dc9406bdffe1693c26d53e 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-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';
 
index 5007c47f0ef041cf485e5da4db07ce2fecf58147..44efb9a1b92cc5971eb4ee50ddbfcc9a582dc66f 100644 (file)
@@ -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;
        }
index 6af32bc7323504571d3f5cace154e52ec591f0f0..8f3d1864dae58a8d8f9031beadfe1a56ca9361d1 100644 (file)
@@ -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()) {