From: Roland Häder Date: Tue, 12 Feb 2013 10:07:48 +0000 (+0000) Subject: Half-implemented quering DHT for node list X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3096273ac8d8968b12b268756366063e5e0ff9d0;p=hub.git Half-implemented quering DHT for node list --- diff --git a/application/hub/config.php b/application/hub/config.php index 4063d372b..8faa8734c 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -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'); diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index ad031b456..e3511e7b8 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -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] diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index c21dfc18f..87026c731 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -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] diff --git a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php index 1c1f08b17..39da3a168 100644 --- a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -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();