]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 1 Nov 2020 20:29:44 +0000 (21:29 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 1 Nov 2020 20:29:44 +0000 (21:29 +0100)
- also allow senderAddress, not just senderId
- WIP: still a mismatching hash is generated
- $traceArray[args] might not be set

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/exceptions.php

index 548078ff5291e138fb2392196fc0f01802967472..b5dcc5c14413cb7c267252bc2f1d1c982040b734 100644 (file)
@@ -405,19 +405,31 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $hash                   Private key's hash
         * @throws      InvalidPrivateKeyHashException  If the private key's hash is not valid
+        * @throws      InvalidArgumentException        If $packageInstance does not contain senderId/senderAddress
         */
        private function determineSenderPrivateKeyHash (DeliverablePackage $packageInstance) {
                // Get DHT instance
                $dhtInstance = DhtObjectFactory::createDhtInstance('node');
 
-               // Ask DHT for session id
-               /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderId=%s ...', $packageInstance->getSenderId()));
-               $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderId());
-
-               // Debugging:
-               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: senderData=%s', __METHOD__, __LINE__, print_r($senderData, TRUE)));
+               // Init sender data array
+               $senderData = array();
+
+               // Ask DHT for sender's id or address (both session id)
+               if ($packageInstance->getSenderId() != '') {
+                       // Field senderId is given
+                       /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderId=%s ...', $packageInstance->getSenderId()));
+                       $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderId());
+               } elseif ($packageInstance->getSenderAddress() != '') {
+                       // Field senderAddress is given
+                       /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderAddress=%s ...', $packageInstance->getSenderAddress()));
+                       $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderAddress());
+               } else {
+                       // Invalid $packageInstance
+                       throw new InvalidArgumentException('packageInstance does not contain senderId/senderAddress');
+               }
 
                // Is an entry found?
+               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: senderData=%s', __METHOD__, __LINE__, print_r($senderData, TRUE)));
                if (count($senderData) > 0) {
                        // Make sure the element 'private_key_hash' is there
                        //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderData=' . print_r($senderData, TRUE));
index 3e15261f1649ae362de036d6a3f32703f7b63d47..8f48342b9448bb418e17082614d907a678daf0ea 100644 (file)
@@ -14,6 +14,9 @@ use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * This class contains static helper functions for our hub
  *
@@ -100,10 +103,17 @@ class HubTools extends BaseHubSystem {
         *
         * @param       $sessionId      A valid session id
         * @return      $recipientUniversalNodeLocator  Recipient as Universal Node Locator
+        * @throws      InvalidArgumentException        If $sessionId is not valid
         */
        protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
-               // Init variable
+               // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
+               if (empty($sessionId)) {
+                       // Throw exception
+                       throw new InvalidArgumentException('Parameter "sessionId" is empty');
+               }
+
+               // Init variable
                $recipientUniversalNodeLocator = 'invalid://invalid:invalid';
 
                // And ask it for Universal Node Locator by given session id
@@ -136,10 +146,17 @@ class HubTools extends BaseHubSystem {
         *
         * @param       $sessionId      Session id
         * @return      $nodeId         Node id
+        * @throws      InvalidArgumentException        If $sessionId is not valid
         */
        public static function resolveNodeIdBySessionId ($sessionId) {
-               // Get an own instance
+               // Validate parameter
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
+               if (empty($sessionId)) {
+                       // Throw exception
+                       throw new InvalidArgumentException('Parameter "sessionId" is empty');
+               }
+
+               // Get an own instance
                $selfInstance = self::getSelfInstance();
 
                // And ask it for session id by given Universal Node Locator
index a343589d815c83cfbe26d17bd28ccac6b79b8380..8051930bc16a5a6146546dc36950d6ba754c3deb 100644 (file)
@@ -39,11 +39,14 @@ function hub_exception_handler ($exceptionInstance) {
                        // Init argument string
                        $argsString = '';
 
-                       // Convert arguments type into human-readable
-                       foreach ($traceArray['args'] as $arg) {
-                               $argsString .= ', ' . gettype($arg);
-                       } // END - foreach
-                       $argsString = substr($argsString, 2);
+                       // Arguments given?
+                       if (isset($traceArray['args'])) {
+                               // Convert arguments type into human-readable
+                               foreach ($traceArray['args'] as $arg) {
+                                       $argsString .= ', ' . gettype($arg);
+                               } // END - foreach
+                               $argsString = substr($argsString, 2);
+                       }
 
                        // Set missing file/line
                        if (!isset($traceArray['file']))  $traceArray['file']  = 'unknown';