From cb5ab5623479ef73e54ebda0ad1fdafd897a662e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 13 Feb 2013 01:07:42 +0000 Subject: [PATCH] Opps :( --- .../distributable/class_Distributable.php | 5 +++- .../hub/main/dht/node/class_NodeDhtFacade.php | 25 ++++++++++++++++--- ...lass_NodeMessageRequestNodeListHandler.php | 8 +++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index e3511e7b8..0c85f6d64 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -57,9 +57,12 @@ interface Distributable extends FrameworkInterface { * object types except the node by given session id. * * @param $messageData An array with message data from a node_list request + * @param $excludeKey Array key which should be excluded + * @param $andKey Array of $separator-separated list of elements which all must match + * @param $separator Sepator char (1st parameter for explode() call) * @return $nodeList An array with all found nodes */ - function queryLocalNodeListExceptByMessageData (array $messageData); + function queryLocalNodeListExceptByMessageData (array $messageData, $excludeKey, $andKey, $separator); } // [EOF] diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 87026c731..111b9ed9d 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -155,16 +155,33 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { * object types except the node by given session id. * * @param $messageData An array with message data from a node_list request + * @param $excludeKey Array key which should be excluded + * @param $andKey Array of $separator-separated list of elements which all must match + * @param $separator Sepator char (1st parameter for explode() call) * @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'); + public function queryLocalNodeListExceptByMessageData (array $messageData, $excludeKey, $andKey, $separator) { + // Make sure both keys are there + assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey]))); // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: messageData=' . print_r($messageData, true)); + // Get a search criteria class + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add all keys + foreach (explode($separator, $messageData[$andKey]) as $criteria) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria); + + // Add it and leave any 'my-' prefix out + $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria); + } // END - foreach + + // Add exclusion key + $searchInstance->addExcludeCriteria(str_replace('my-', '', $excludeKey), $messageData[$excludeKey]); + // Only X entries are fine $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('node_dht_list_limit')); 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 39da3a168..c52a4df43 100644 --- a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -130,15 +130,15 @@ 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(); // Set it in configuration (temporarily) $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode); + + // Query local DHT for nodes except given session id + $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData($messageData, XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID, XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES, ','); + die('nodeList='.print_r($nodeList, true)); } /** -- 2.39.5