]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 29 Oct 2020 11:56:01 +0000 (12:56 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 29 Oct 2020 11:56:21 +0000 (12:56 +0100)
- implemented NodeDhtWrapper::findNodeLocalByLocatorInstance()
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/exceptions.php
application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php
core

index b5479aa1911060272ee2d04844e9e6ce5c86dacc..55d52a8e63e86874c80f2491b05537daa3d59bdc 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\Dht;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Node\BaseHubNode;
 
@@ -224,7 +225,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                // Make sure the external address is set and not invalid
                // @TODO Bad check on UNL, better use a proper validator
                $externalUnl = $locatorInstance->getExternalUnl();
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $externalUnl));
                assert($externalUnl != 'invalid');
 
                // Add Universal Node Locator/node id as criteria
@@ -240,7 +241,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $isRegistered = $resultInstance->valid();
 
                // Return result
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: isRegistered=%d - EXIT!', intval($isRegistered)));
                return $isRegistered;
        }
 
@@ -304,7 +305,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
         * Finds a node locally by given session id
         *
         * @param       $sessionId      Session id to lookup
-        * @return      $nodeData       Node data array
+        * @return      $resultInstance         An instance of a SearchableResult class
         */
        public function findNodeLocalBySessionId ($sessionId) {
                // Get search criteria
@@ -319,7 +320,31 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $resultInstance = $this->doSelectByCriteria($searchInstance);
 
                // Return result instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid())));
+               return $resultInstance;
+       }
+
+       /**
+        * Finds a node locally by given UNL instance
+        *
+        * @param       $locatorInstance        An instance of a LocateableNode class
+        * @return      $resultInstance         An instance of a SearchableResult class
+        */
+       public function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance) {
+               // Get search criteria
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: locatorInstance=%s - CALLED!', $locatorInstance->__toString()));
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Search for session id and limit it to one entry
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $locatorInstance->getExternalUnl()));
+               $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $locatorInstance->getExternalUnl());
+               $searchInstance->setLimit(1);
+
+               // Query database and get a result instance back
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+               // Return result instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid())));
                return $resultInstance;
        }
 
index fd25b163b806b57d162923fcd85275f81ec5e59d..5e17db99aeca3c464e92c595223cf89b20c375c5 100644 (file)
@@ -202,13 +202,23 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                $nodeData = array();
 
                // Query database
-               $resultInstance = $this->getWrapperInstance()->findNodeLocalByUnlInstance($locatorInstance);
+               $resultInstance = $this->getWrapperInstance()->findNodeLocalByLocatorInstance($locatorInstance);
 
                // Make sure the result instance is valid
+               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: resultInstance=%s', __METHOD__, __LINE__, print_r($resultInstance, TRUE)));
                assert($resultInstance instanceof SearchableResult);
 
+               // Is the next entry valid?
+               if (($resultInstance->valid()) && ($resultInstance->next())) {
+                       /*
+                        * Then load the first entry (more entries are being ignored and
+                        * should not happen).
+                        */
+                       $nodeData = $resultInstance->current();
+               } // END - if
+
                // Return node data
-               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
+               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData)));
                return $nodeData;
        }
index af8b8a3b39aa38cbc4f5d0a4349f33c5985d1c30..11421344dc7240bb9a9672f2b201f2ba807289e8 100644 (file)
@@ -1024,7 +1024,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl(%d)=%s,recipientId(%d)=%s', strlen($packageInstance->getRecipientUnl()), $packageInstance->getRecipientUnl(), strlen($packageInstance->getRecipientId()), $packageInstance->getRecipientId()));
                if ($packageInstance->getRecipientUnl() != '' && $packageInstance->getRecipientId() == '') {
                        // Need to resolve UNL -> session id ("recipient id"), so prepare UNL instance
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl=%s is being solved into session id ...', $packageInstance->getRecipientUnl()));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl=%s is being solved into session id ...', $packageInstance->getRecipientUnl()));
                        $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
 
                        // Get session id and set it back
index 1b74a7286585166af56c643457ed355485c50976..a343589d815c83cfbe26d17bd28ccac6b79b8380 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Assertion\AssertionException;
+use Org\Mxchange\CoreFramework\Error\FatalErrorException;
 use Org\Mxchange\CoreFramework\Generic\FrameworkException;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
@@ -137,7 +138,7 @@ function hub_assert_handler ($file, $line, $code) {
 } // END - function
 
 // Set error handler
-set_error_handler('hub_error_handler');
+//set_error_handler('hub_error_handler');
 
 // Set the new handler
 set_exception_handler('hub_exception_handler');
index 237a24e821678adb943d6170d85791c8847b2413..54d46158e2486504c6bdf24698300ccba9e48bf1 100644 (file)
@@ -3,6 +3,7 @@
 namespace Org\Shipsimu\Hub\Database\Frontend\Node\Dht;
 
 // Import application-specific stuff
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 // Import framework stuff
@@ -67,10 +68,18 @@ interface NodeDhtWrapper extends DatabaseWrapper {
         * Finds a node locally by given session id
         *
         * @param       $sessionId      Session id to lookup
-        * @return      $nodeData       Node data array
+        * @return      $resultInstance         An instance of a SearchableResult class
         */
        function findNodeLocalBySessionId ($sessionId);
 
+       /**
+        * Finds a node locally by given UNL instance
+        *
+        * @param       $locatorInstance        An instance of a LocateableNode class
+        * @return      $resultInstance         An instance of a SearchableResult class
+        */
+       function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance);
+
        /**
         * Registeres a node by given message data.
         *
diff --git a/core b/core
index 22758e48b312f672167569bbe674476fc19769b2..b2ea555ca8062721bba3bc565770a3da27577ced 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 22758e48b312f672167569bbe674476fc19769b2
+Subproject commit b2ea555ca8062721bba3bc565770a3da27577ced