]> git.mxchange.org Git - hub.git/commitdiff
DHT data registration/update added to NodeDhtFacade, now every DHT facade must implem...
authorRoland Häder <roland@mxchange.org>
Wed, 17 Jul 2013 22:10:43 +0000 (22:10 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 17 Jul 2013 22:10:43 +0000 (22:10 +0000)
application/hub/main/dht/class_
application/hub/main/dht/class_BaseDht.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/package/class_NetworkPackage.php

index 8fe8e538c32cd2bfde758be6803bb6b7d9f1c48f..5342bec91f6535e007b5bc71aaf4a8d49aef1704 100644 (file)
@@ -44,6 +44,19 @@ class ???DhtFacade extends BaseDht implements Distributable {
                // Return the prepared instance
                return $dhtInstance;
        }
+
+       /**
+        * Registers/updates an entry in the DHT with given data from $dhtData
+        * array. Different DHT implemtations may handle this differently as they
+        * may enrich the data with more meta data.
+        *
+        * @param       $dhtData        A valid array with DHT-related data (e.g. node/peer data)
+        * @return      void
+        * @todo        0% done
+        */
+       protected function insertDataIntoDht (array $dhtData) {
+               $this->partialStub('Please implement this method.');
+       }
 }
 
 // [EOF]
index 9b94558b0baae1b86b6be44f6694dcf0be0d4315..8ccf5b0817da9581cda29657d6b68deead9672ce 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 BaseDht extends BaseHubSystem {
+abstract class BaseDht extends BaseHubSystem {
        /**
         * Stacker name for "INSERT" node data
         */
@@ -59,16 +59,22 @@ class BaseDht extends BaseHubSystem {
         * @return      void
         */
        private function initStackers () {
-               // "Walk" through all (more will be added as needed
-               foreach (
-                       array(
-                               self::STACKER_NAME_INSERT_NODE,
-                       ) as $stackerName) {
-                               // Init this stack
-                               $this->getStackerInstance()->initStacker($stackerName);
-               } // END - foreach
+               // Initialize all stacker
+               $this->getStackerInstance()->initStackers(array(
+                       self::STACKER_NAME_INSERT_NODE,
+               ));
        }
 
+       /**
+        * Registers/updates an entry in the DHT with given data from $dhtData
+        * array. Different DHT implemtations may handle this differently as they
+        * may enrich the data with more meta data.
+        *
+        * @param       $dhtData        A valid array with DHT-related data (e.g. node/peer data)
+        * @return      void
+        */
+       protected abstract function insertDataIntoDht (array $dhtData);
+
        /**
         * Updates/refreshes DHT data (e.g. status).
         *
@@ -102,7 +108,8 @@ class BaseDht extends BaseHubSystem {
                // Get next node data from stack
                $nodeData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_INSERT_NODE);
 
-               die(__METHOD__ . ':nodeData=' . print_r($nodeData, TRUE));
+               // Insert the data
+               $this->insertDataIntoDht($nodeData);
        }
 }
 
index 940065902b58f5a80f079ab7acf5cb4390a6dc6c..23e3abfe13596c28d52146fd1e08a15d93c9bd9a 100644 (file)
@@ -51,6 +51,33 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                return $dhtInstance;
        }
 
+       /**
+        * Registers/updates an entry in the DHT with given data from $dhtData
+        * array. Different DHT implemtations may handle this differently as they
+        * may enrich the data with more meta data.
+        *
+        * @param       $dhtData        A valid array with DHT-related data (e.g. node/peer data)
+        * @return      void
+        * @todo        Does the data need to be enriched?
+        */
+       protected function insertDataIntoDht (array $dhtData) {
+               // Check if there is already an entry for given node_id
+               if ($this->getWrapperInstance()->isNodeRegisteredByNodeId($dhtData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID])) {
+                       /*
+                        * Update existing record. Please note that this step is not secure
+                        * (e.g. DHT poisoning) it would be good to implement some checks if
+                        * the both node owner trust each other (see sub-project 'DSHT').
+                        */
+                       $this->getWrapperInstance()->updateNodeEntry($nodeData);
+               } else {
+                       /*
+                        * Inserts given node data into the DHT. As above, this step does
+                        * currently not perform any security checks.
+                        */
+                       $this->getWrapperInstance()->registerNodeByData($nodeData);
+               }
+       }
+
        /**
         * Initializes the distributed hash table (DHT)
         *
index ba893bd89869f120708c79d1d332b42208568940..d7507b03fb6e1b32b7a5422c61df9049cf50686a 100644 (file)
@@ -282,22 +282,17 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        protected function initStackers ($forceReInit = FALSE) {
                // Initialize all
-               foreach (
-                       array(
-                               self::STACKER_NAME_UNDECLARED,
-                               self::STACKER_NAME_DECLARED,
-                               self::STACKER_NAME_OUTGOING,
-                               self::STACKER_NAME_DECODED_INCOMING,
-                               self::STACKER_NAME_DECODED_HANDLED,
-                               self::STACKER_NAME_DECODED_CHUNKED,
-                               self::STACKER_NAME_NEW_MESSAGE,
-                               self::STACKER_NAME_PROCESSED_MESSAGE,
-                               self::STACKER_NAME_BACK_BUFFER
-                       ) as $stackerName) {
-                               // Init this stacker
-                               //* DEBUG: */ print(__METHOD__ . ': stackerName=' . $stackerName . ',forceReInit=' . intval($forceReInit) . PHP_EOL);
-                               $this->getStackerInstance()->initStacker($stackerName, $forceReInit);
-               } // END - foreach
+               $this->getStackerInstance()->initStackers(array(
+                       self::STACKER_NAME_UNDECLARED,
+                       self::STACKER_NAME_DECLARED,
+                       self::STACKER_NAME_OUTGOING,
+                       self::STACKER_NAME_DECODED_INCOMING,
+                       self::STACKER_NAME_DECODED_HANDLED,
+                       self::STACKER_NAME_DECODED_CHUNKED,
+                       self::STACKER_NAME_NEW_MESSAGE,
+                       self::STACKER_NAME_PROCESSED_MESSAGE,
+                       self::STACKER_NAME_BACK_BUFFER
+               ));
        }
 
        /**