]> git.mxchange.org Git - hub.git/commitdiff
Half-implemented quering DHT for node list
authorRoland Häder <roland@mxchange.org>
Tue, 12 Feb 2013 10:07:48 +0000 (10:07 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 12 Feb 2013 10:07:48 +0000 (10:07 +0000)
application/hub/config.php
application/hub/interfaces/distributable/class_Distributable.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php

index 4063d372b44d945deedec469a569444a6ee1987f..8faa8734cfcfe7ab3d1c64881f68cea87eb6e361 100644 (file)
@@ -48,6 +48,9 @@ $cfg->setConfigEntry('node_info_db_wrapper_class', 'NodeInformationDatabaseWrapp
 // CFG: NODE-DHT-DB-WRAPPER-CLASS
 $cfg->setConfigEntry('node_dht_db_wrapper_class', 'NodeDistributedHashTableDatabaseWrapper');
 
+// CFG: NODE-DHT-LIST-LIMIT
+$cfg->setConfigEntry('node_dht_list_limit', 20);
+
 // CFG: PEER-LOOKUP-DB-WRAPPER-CLASS
 $cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'PeerStateLookupDatabaseWrapper');
 
index ad031b4565cb10c9ee72abaed4692fb8f3c98a7b..e3511e7b88a5eaca35e30d30ee473c45507b8042 100644 (file)
@@ -45,12 +45,21 @@ interface Distributable extends FrameworkInterface {
         * - external-ip (hostname or IP number)
         * - listen-port (TCP/UDP listen port for inbound connections)
         *
-        * @param       $messageArray           An array with all minimum message data
+        * @param       $messageData            An array with all minimum message data
         * @param       $handlerInstance        An instance of a Handleable class
         * @param       $forceUpdate            Optionally force update, don't register (default: register if not found)
         * @return      void
         */
        function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE);
+
+       /**
+        * Queries the local DHT data(base) for a node list with all supported
+        * object types except the node by given session id.
+        *
+        * @param       $messageData    An array with message data from a node_list request
+        * @return      $nodeList               An array with all found nodes
+        */
+       function queryLocalNodeListExceptByMessageData (array $messageData);
 }
 
 // [EOF]
index c21dfc18f426d7c6cb022c002e1c6bd511e49644..87026c731170583024e4c5d73db00287f29df6a5 100644 (file)
@@ -149,6 +149,41 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Save last exception
                $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
        }
+
+       /**
+        * Queries the local DHT data(base) for a node list with all supported
+        * object types except the node by given session id.
+        *
+        * @param       $messageData    An array with message data from a node_list request
+        * @return      $nodeList               An array with all found nodes
+        * @todo        Implement exclusion/choise-inclusion criteria
+        */
+       public function queryLocalNodeListExceptByMessageData (array $messageData) {
+               // Get a search criteria class
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: messageData=' . print_r($messageData, true));
+
+               // Only X entries are fine
+               $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('node_dht_list_limit'));
+
+               // Run the query
+               $resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
+
+               // Get node list
+               $nodeList = array();
+               while ($resultInstance->next()) {
+                       // Add this entry
+                       array_push($nodeList, $resultInstance->current());
+               } // END - while
+
+               // Save last exception
+               $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
+
+               // Return node list (array)
+               return $nodeList;
+       }
 }
 
 // [EOF]
index 1c1f08b170d2f326dda20ca23b2d53bf8e9ba55a..39da3a168084adde19f0d0d5c73a29d6fdf27774 100644 (file)
@@ -130,6 +130,10 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha
                        $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
                } // END - foreach
 
+               // Query local DHT for nodes except given session id
+               $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData($messageData);
+               die('nodeList='.print_r($nodeList, true));
+
                // Translate last exception into a status code
                $statusCode = $this->getTranslatedStatusFromLastException();