* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
+class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
/**
* Protected constructor
*
*/
$resultInstance = $this->getWrapperInstance()->findNodeLocalBySessionId($sessionId);
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
// Is the next entry valid?
if (($resultInstance->valid()) && ($resultInstance->next())) {
/*
// Run the query
$resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
// Is there already an entry?
if ($resultInstance->valid()) {
// Entry found, so update it
// Run the query
$resultInstance = $this->getWrapperInstance()->doSelectByCriteria($searchInstance);
- // Get node list
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
+ // Init array
$nodeList = array();
+
+ // Get node list
while ($resultInstance->next()) {
// Get current element (it should be an array, and have at least 1 entry)
$current = $resultInstance->current();
* @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);
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
// Init array
$recipients = array();
// Add instance to recipient list
array_push($recipients, $current);
+ } // END - while
- // Has the maximum been reached?
- if (count($recipients) == $maxRecipients) {
- // Stop search here
- break;
- } // END - if
+ // Return filled array
+ return $recipients;
+ }
+
+ /**
+ * Finds DHT recipients by given key/value pair
+ *
+ * @param $key Key to search for
+ * @param $value Value to check on found key
+ * @return $recipiens Array with DHT recipients from given key/value pair
+ */
+ public function findRecipientsByKey ($key, $value) {
+ // Look for all suitable nodes
+ $resultInstance = $this->getWrapperInstance()->getResultFromKeyValue($key, $value);
+
+ // Make sure the result instance is valid
+ assert($resultInstance instanceof SearchableResult);
+ assert($resultInstance->valid());
+
+ // Init array
+ $recipients = array();
+
+ // "Walk" through all entries
+ while ($resultInstance->next()) {
+ // Get current entry
+ $current = $resultInstance->current();
+ } // END - while
+
+ // Add instance to recipient list
+ array_push($recipients, $current);
} // END - while
// Return filled array