]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/class_BaseDht.php
Continued:
[hub.git] / application / hub / main / dht / class_BaseDht.php
index fecc18cd76c8a0d6f7d03e5416aebc010d528b7b..f4e4a0344acea228ad57b7786fcda5690741c393 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-abstract class BaseDht extends BaseHubSystem {
+abstract class BaseDht extends BaseHubSystem implements Distributable {
        /**
         * "Cached" instance of a publish helper
         */
@@ -150,7 +150,8 @@ abstract class BaseDht extends BaseHubSystem {
                // Get result instance
                $resultInstance = $this->getWrapperInstance()->getUnpublishedEntriesInstance();
 
-               // Must still be valid
+               // Make sure the result instance is valid
+               assert($resultInstance instanceof SearchableResult);
                assert($resultInstance->valid());
 
                // "Walk" through all entries
@@ -163,7 +164,7 @@ abstract class BaseDht extends BaseHubSystem {
                        assert(is_array($current));
 
                        // ... and push it to the next stack
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] Pushing entry with ' . count($current) . ' elements to stack ' . self::STACKER_NAME_PENDING_PUBLISHING . ' ...');
                        $this->getStackerInstance()->pushNamed(self::STACKER_NAME_PENDING_PUBLISHING, $current);
                } // END - while
        }
@@ -178,10 +179,24 @@ abstract class BaseDht extends BaseHubSystem {
                $isPending = ($this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_PENDING_PUBLISHING) === FALSE);
 
                // Return status
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isPending=' . intval($isPending));
                return $isPending;
        }
 
+       /**
+        * Whether this DHT's state is 'booting'
+        *
+        * @return      $isBooting      Whether this DHT is currently booting
+        */
+       public function ifDhtIsBooting () {
+               // Call state instance
+               $isBooting = $this->getStateInstance()->ifDhtIsBooting();
+
+               // Return status
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-DHT[' . __METHOD__ . ':' . __LINE__ . '] isBooting=' . intval($isBooting));
+               return $isBooting;
+       }
+
        /**
         * Publishes next entry found in stack. This method shall also update the
         * corresponding dabase entry.
@@ -202,12 +217,48 @@ abstract class BaseDht extends BaseHubSystem {
                // Load the announcement descriptor
                $this->publishHelperInstance->loadDescriptorXml($this);
 
-               // Compile all variables
-               $this->publishHelperInstance->getTemplateInstance()->compileConfigInVariables();
+               // "Pop" next entry
+               $entry = $this->getStackerInstance()->popNamed(self::STACKER_NAME_PENDING_PUBLISHING);
+
+               // Some sanity-checks
+               assert(is_array($entry));
+
+               // Remove any non-public data the database layer desires
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: Calling this->getWrapperInstance()->removeNonPublicDataFromArray(data) ...');
+               $entry = $this->getWrapperInstance()->removeNonPublicDataFromArray($entry);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT[' . __METHOD__ . ':' . __LINE__ . ']: entry[]=' . gettype($entry));
+
+               // Some sanity-checks again
+               assert(is_array($entry));
+
+               // Inject variables
+               $this->publishHelperInstance->getTemplateInstance()->injectConfigVariables($entry);
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
                $this->publishHelperInstance->sendPackage($this);
        }
+
+       /**
+        * Whether the DHT has fully bootstrapped (after state 'booting')
+        *
+        * @return      $isFullyBooted  Whether the DHT is fully booted
+        * @todo        0% done
+        */
+       public function hasFullyBootstrapped () {
+               // Get state and check it
+               $this->partialStub('Please implement this method.');
+       }
+
+       /**
+        * Enable DHT bootstrap request acceptance for local node
+        *
+        * @return      void
+        * @todo        Switch flag 'accept_bootstrap'
+        */
+       public function enableAcceptDhtBootstrap () {
+               // Call method on database wrapper
+               $this->getWrapperInstance()->enableAcceptDhtBootstrap();
+       }
 }
 
 // [EOF]