]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/node/class_NodeDhtFacade.php
Expanded debug lines, renamed 'node_type' to 'node_mode' (which makes your DHT databa...
[hub.git] / application / hub / main / dht / node / class_NodeDhtFacade.php
index 56c69efe21efe1a255ea3160444ba090be31dab8..9c00f7127600d601f11f9e1b91e58ba36062aff1 100644 (file)
@@ -65,6 +65,9 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                        // No, so register it
                        $this->getWrapperInstance()->registerLocalNode();
                }
+
+               // Change state
+               $this->getStateInstance()->dhtHasInitialized();
        }
 
        /**
@@ -75,6 +78,20 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
         * @return      void
         */
        public function bootstrapDht () {
+               // Get a helper instance
+               $helperInstance = ObjectFactory::createObjectByConfiguredName('dht_bootstrap_helper_class');
+
+               // Load the announcement descriptor
+               $helperInstance->loadDescriptorXml($this);
+
+               // Compile all variables
+               $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+               // "Publish" the descriptor by sending it to the bootstrap/list nodes
+               $helperInstance->sendPackage($this);
+
+               // Change state
+               $this->getStateInstance()->dhtHasBooted();
        }
 
        /**
@@ -125,12 +142,12 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: messageData=' . print_r($messageData, true));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, true) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
 
                // Search for the node's session id and external IP/hostname + TCP/UDP listen port
                foreach ($handlerInstance->getSearchData() as $key) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADEmessageData[' . $key . ']=' . $messageData[$key]);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
 
                        // Is it there?
                        assert(isset($messageData[$key]));
@@ -181,7 +198,7 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADEmessageData=' . print_r($messageData, true));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, true));
 
                // Get a search criteria class
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
@@ -189,7 +206,7 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Add all keys
                foreach (explode($separator, $messageData[$andKey]) as $criteria) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: andKey=' . $andKey . ',criteria=' . $criteria);
 
                        // Add it and leave any 'my-' prefix out
                        $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria);
@@ -207,8 +224,16 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Get node list
                $nodeList = array();
                while ($resultInstance->next()) {
+                       // Get current element (it should be an array, and have at least 1 entry)
+                       $current = $resultInstance->current();
+                       assert(is_array($current));
+                       assert(count($current) > 0);
+
+                       // Debug message
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE));
+
                        // Add this entry
-                       array_push($nodeList, $resultInstance->current());
+                       array_push($nodeList, $current);
                } // END - while
 
                // Save last exception
@@ -225,12 +250,13 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
         *
         * @param       $nodeList       An array from an earlier database result instance
         * @return      void
+        * @todo        ~10% done
         */
        public function insertNodeList (array $nodeList) {
-               // If no node is in the list (array), skip the rest of this method silently
+               // If no node is in the list (array), skip the rest of this method
                if (count($nodeList) == 0) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE: No node record has been returned.');
+                       self::createDebugInstance(__CLASS__)->debugOutput('DHT-FACADE[' . __LINE__ . ']: No node record has been returned.');
 
                        // Abort here
                        return;