]> git.mxchange.org Git - hub.git/commitdiff
Opps :(
authorRoland Häder <roland@mxchange.org>
Wed, 13 Feb 2013 01:07:42 +0000 (01:07 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 13 Feb 2013 01:07:42 +0000 (01:07 +0000)
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 e3511e7b88a5eaca35e30d30ee473c45507b8042..0c85f6d6415822abfc96ff4ff649d60098eaff50 100644 (file)
@@ -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]
index 87026c731170583024e4c5d73db00287f29df6a5..111b9ed9da36b2704a49bbdc71b4e8828516d913 100644 (file)
@@ -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'));
 
index 39da3a168084adde19f0d0d5c73a29d6fdf27774..c52a4df438c7d892ae69faa3f161e114b5f6a087 100644 (file)
@@ -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));
        }
 
        /**