]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/node/class_NodeDhtFacade.php
Continued with hub development:
[hub.git] / application / hub / main / dht / node / class_NodeDhtFacade.php
index 7b6535cda1f57c16872adfaf9d690db0b599397b..c9017ec7e8b1f5713cc2ae8970cf30ace588d332 100644 (file)
@@ -302,6 +302,42 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_INSERT_NODE, $nodeData);
                } // END - foreach
        }
+
+       /**
+        * Find recipients for given package data
+        *
+        * @param       $packageData    An array of valid package data
+        * @return      $recipients             An indexed array with DHT recipients
+        */
+       public function findRecipientsByPackageData (array $packageData) {
+               // Get max recipients
+               $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
+
+               // Query get a result instance back from DHT database wrapper.
+               $resultInstance = $this->getWrapperInstance()->getResultFromExcludedSender($packageData);
+
+               // Init array
+               $recipients = array();
+
+               // Search for all recipients
+               while ($resultInstance->next()) {
+                       // Get current entry
+                       $current = $resultInstance->current();
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: current=' . print_r($current, TRUE));
+
+                       // Add instance to recipient list
+                       array_push($recipients, $current);
+
+                       // Has the maximum been reached?
+                       if (count($recipients) == $maxRecipients) {
+                               // Stop search here
+                               break;
+                       } // END - if
+               } // END - while
+
+               // Return filled array
+               return $recipients;
+       }
 }
 
 // [EOF]