]> git.mxchange.org Git - hub.git/commitdiff
Added stub method insertNodeList()
authorRoland Häder <roland@mxchange.org>
Wed, 13 Feb 2013 20:01:58 +0000 (20:01 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 13 Feb 2013 20:01:58 +0000 (20:01 +0000)
application/hub/interfaces/distributable/class_Distributable.php
application/hub/main/dht/node/class_NodeDhtFacade.php
application/hub/main/handler/answer-status/requests/class_RequestNodeListAnswerOkayHandler.php

index c90430f91d03ddc361aab2faf1e47cafba24ead0..ea20f871aab0de5fb065c788630577d7c495daec 100644 (file)
@@ -64,6 +64,16 @@ interface Distributable extends FrameworkInterface {
         * @return      $nodeList                       An array with all found nodes
         */
        function queryLocalNodeListExceptByMessageData (array $messageData, Handleable $handlerInstance, $excludeKey, $andKey, $separator);
+
+       /**
+        * Inserts given node list array (from earlier database result produced by
+        * an other node) into the DHT. This array origins from above method
+        * queryLocalNodeListExceptByMessageData().
+        *
+        * @param       $nodeList       An array from an earlier database result instance
+        * @return      void
+        */
+       function insertNodeList (array $nodeList);
 }
 
 // [EOF]
index 49434e1035f34c43ae2da27dcf7bedd8cdd13199..5572d0b22633c070e9ea7b6a02053b85ffbf31aa 100644 (file)
@@ -202,6 +202,25 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                // Return node list (array)
                return $nodeList;
        }
+
+       /**
+        * Inserts given node list array (from earlier database result produced by
+        * an other node) into the DHT. This array origins from above method
+        * queryLocalNodeListExceptByMessageData().
+        *
+        * @param       $nodeList       An array from an earlier database result instance
+        * @return      void
+        */
+       public function insertNodeList (array $nodeList) {
+               // If no node is given, skip this method silently
+               if (count($nodeList) == 0) {
+                       // Skip it silently
+                       return;
+               } // END - if
+
+               // @TODO Not finish yet
+               $this->partialStub('DHT: Needs implementing to insert ' . count($nodeList) . ' entry(-ies) into DHT.');
+       }
 }
 
 // [EOF]
index cca50dab4946c2ef0af09c4fb966053169228376..e95ba474ca5259257645937c3d0ecb4eac9d34bb 100644 (file)
@@ -56,29 +56,28 @@ class RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements
         * @return      void
         * @throws      NodeSessionIdVerficationException       If the provided session id is not matching
         * @todo        Do some more here: Handle karma, et cetera?
-        * @todo        Rewrite this to use DHT
         */
        public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
-               // Get a database wrapper instance
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
+               // Make sure node-list is found in array
+               assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
 
-               // Get also a search criteria instance
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               // Save node list
+               $nodeList = unserialize(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
 
-               // Lookup external session id/external IP/port
-               $searchInstance->addCriteria('session_id' , $messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID]);
+               // Make sure it is completely decoded
+               assert(is_array($nodeList));
 
-               // Only one entry is fine
-               $searchInstance->setLimit(1);
+               // ... and remove it as it should not be included now
+               unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
 
-               // Run the query
-               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
+               // Write node list to DHT
+               $this->getDhtInstance()->insertNodeList($nodeList);
 
-               // Is there an try?
-               if (!$resultInstance->next()) {
-                       // This is fatal, caused by "stolen" session id and/or not matching IP number/port combination
-                       throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
-               } // END - if
+               /*
+                * Query DHT and force update (which will throw an exception if the
+                * node is not found).
+                */
+               $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
 
                // Get the node instance
                $nodeInstance = Registry::getRegistry()->getInstance('node');