]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
Continued with DHT stuff:
[hub.git] / application / hub / main / database / wrapper / node / class_NodeDistributedHashTableDatabaseWrapper.php
index 8c3a8a5e3f8bb81606988f39f95e3ba6f60b8c3a..08c8a77164778f7660debb5848e6a8d1ba28f5a8 100644 (file)
@@ -41,6 +41,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
        const DB_COLUMN_NODE_LIST          = 'node_list';
        const DB_COLUMN_PUBLICATION_STATUS = 'publication_status';
        const DB_COLUMN_ANSWER_STATUS      = 'answer_status';
+       const DB_COLUMN_ACCEPT_BOOTSTRAP   = 'accept_bootstrap';
 
        // Publication status'
        const PUBLICATION_STATUS_PENDING = 'PENDING';
@@ -519,12 +520,43 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
                // Assert on required array field
                assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
 
+               // Get max recipients
+               $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
+
                // First creata a search instance
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Then exclude 'sender' field as the sender is the current (*this*) node
                $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
 
+               // Set limit to maximum DHT recipients
+               $searchInstance->setLimit($maxRecipients);
+
+               // Get a result instance back from DHT database wrapper.
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+               // Return result instance
+               return $resultInstance;
+       }
+
+       /**
+        * Find recopients by given key/value pair. First look for the key and if it
+        * matches, compare the value.
+        *
+        * @param       $key                    Key to look for
+        * @param       $value                  Value to compare if key matches
+        * @return      $recipients             An indexed array with DHT recipients
+        */
+       public function getResultFromKeyValue ($key, $value) {
+               // Get max recipients
+               $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
+
+               // First creata a search instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Find the key/value pair
+               $searchInstance->addCriteria($key, $value);
+
                // Get a result instance back from DHT database wrapper.
                $resultInstance = $this->doSelectByCriteria($searchInstance);