]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/dht/node/class_NodeDhtFacade.php
Rewrites:
[hub.git] / application / hub / main / dht / node / class_NodeDhtFacade.php
index b71b7eaa36b8543e79d1c10c1eff2e080712a188..c21dfc18f426d7c6cb022c002e1c6bd511e49644 100644 (file)
@@ -100,10 +100,12 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
         * - listen-port (TCP/UDP listen port for inbound connections)
         *
         * @param       $messageArray           An array with all minimum message data
-        * @param       $handlerInstance        An instance of a HandleableMessage class
+        * @param       $handlerInstance        An instance of a Handleable class
+        * @param       $forceUpdate            Optionally force update, don't register (default: register if not found)
         * @return      void
+        * @throws      NodeSessionIdVerficationException       If the node was not found and update is forced
         */
-       public function registerNodeByMessageData (array $messageData, HandleableMessage $handlerInstance) {
+       public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE) {
                // Get a search criteria class
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
@@ -132,9 +134,16 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
                if ($resultInstance->next()) {
                        // Entry found, so update it
                        $this->getWrapperInstance()->updateNodeByMessageData($messageData, $handlerInstance, $searchInstance);
-               } else {
+               } elseif ($forceUpdate === FALSE) {
                        // Nothing found, so register it
                        $this->getWrapperInstance()->registerNodeByMessageData($messageData, $handlerInstance);
+               } else {
+                       /*
+                        * Do not register non-existent nodes here. This is maybe 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);
                }
 
                // Save last exception