]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php
Use array_push() instead of [] as array_push() checks if parameter 1 is really an...
[hub.git] / application / hub / main / handler / message-types / requests / class_NodeMessageRequestNodeListHandler.php
index 9110b6f67cb828fff6a23242f06262052d828478..fe39ae8491a05d2adeff80d2f06caf70520282c2 100644 (file)
@@ -36,6 +36,16 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha
 
                // Init message data array
                $this->messageDataElements = array(
+                       XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+               );
+
+               // Init config-copy array
+               $this->configCopy = array(
+               );
+
+               // Init search data array
+               $this->searchData = array(
+                       XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
                );
        }
 
@@ -88,14 +98,77 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha
         * @return      void
         */
        public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+               // Add generic first
+               parent::addArrayToDataSet($dataSetInstance, $messageData);
+
                // Add all ements
                foreach ($this->messageDataElements as $key) {
                        // Is it there?
                        assert(isset($messageData[$key]));
 
                        // Add it
-                       $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]);
+                       $dataSetInstance->addCriteria($key, $messageData[$key]);
+               } // END - foreach
+       }
+
+       /**
+        * Initializes configuration data from given message data array
+        *
+        * @param       $messageData    An array with all message data
+        * @return      void
+        */
+       protected function initMessageConfigurationData (array $messageData) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __LINE__ . ']: messageData=' . print_r($messageData, true));
+
+               // "Walk" throught the config-copy array
+               foreach ($this->configCopy as $targetKey => $sourceKey) {
+                       // Debug message
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __LINE__ . ']: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+                       // Copy from source to targetKey
+                       $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
                } // END - foreach
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('REQUEST-HANDLER[' . __LINE__ . ']: Got a node list of ' . count($nodeList) . ' entry/-ies back.');
+
+               // Query local DHT for nodes except given session id
+               $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData(
+                       $messageData,
+                       $this,
+                       XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
+                       XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+                       BaseHubNode::OBJECT_LIST_SEPARATOR
+               );
+
+               // Set it serialized in configuration (temporarily)
+               $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(serialize($nodeList)));
+
+               // Translate last exception into a status code
+               $statusCode = $this->getTranslatedStatusFromLastException();
+
+               // Set it in configuration (temporarily)
+               $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode);
+       }
+
+       /**
+        * Removes configuration data with given message data array from global
+        * configuration
+        *
+        * @param       $messageData    An array with all message data
+        * @return      void
+        */
+       protected function removeMessageConfigurationData (array $messageData) {
+               // "Walk" throught the config-copy array again
+               foreach ($this->configCopy as $configKey => $dummy) {
+                       // Now unset this configuration entry (to save some memory again)
+                       $this->getConfigInstance()->unsetConfigEntry($configKey);
+               } // END - foreach
+
+               // Remove answer status/node list as well
+               $this->getConfigInstance()->unsetConfigEntry('answer_status');
+               $this->getConfigInstance()->unsetConfigEntry('node_list');
        }
 }