]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/node/class_NodeDhtFacade.php
DHT data registration/update added to NodeDhtFacade, now every DHT facade must implem...
[hub.git] / application / hub / main / dht / node / class_NodeDhtFacade.php
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)
         *