]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 09:12:33 +0000 (10:12 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 09:12:33 +0000 (10:12 +0100)
- There was some mixing of recipient type (direct, dht, self, upper, ...)
  with the node's (recipient's) session id. This is now fixed and sorted out.
  So the recipient type remains that way and is never being changed to session
  id.

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php
application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/helper/class_BaseHubSystemHelper.php
application/hub/classes/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php
application/hub/classes/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php
application/hub/classes/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php

index ffa39519ba8760662d777fec40737e44b76e9d95..374ee0760a822ba7b557a203e34f847e4a8b8850 100644 (file)
@@ -101,7 +101,10 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
                // At least 2 entries must be found
                if (count($recipient) < 2) {
                        // Not valid
-                       throw new InvalidArgumentException(sprintf('packageInstance with recipientType=%s has no valid UNL=%s set.', $packageInstance->getRecipientType(), $packageInstance->getRecipientUnl()));
+                       throw new InvalidArgumentException(sprintf('packageInstance with recipientType=%s has no valid UNL=%s set.',
+                               $packageInstance->getRecipientType(),
+                               $packageInstance->getRecipientUnl()
+                       ));
                }
 
                // Now get the first part (protocol type) and make all lower-case
index 164792757f448e4a571c30abcc80d51b6e5c8632..0a29c885fbe8541cf14526b46aec4b8f8fcb3056 100644 (file)
@@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Discovery\Network\Recipient;
 use Org\Shipsimu\Hub\Discovery\Recipient\BaseRecipientDiscovery;
 use Org\Shipsimu\Hub\Discovery\Recipient\Node\DiscoverableNodeRecipient;
 use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
-use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException;
 use Org\Shipsimu\Hub\Tools\HubTools;
@@ -70,22 +69,16 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
         */
        public function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance) {
                // Init instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $recipientInstance = NULL;
 
                // First try out the direct recipient (session id)
                try {
-                       /*
-                        * Check if recipient is a valid UNL which indicates that the
-                        * recipient must be direct recipient then, otherwise a "virtual"
-                        * recipient.
-                        */
-                       if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientUnl())) {
-                               // Get instance (should not break)
-                               $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
-                       } else {
-                               // Try to find the right class
-                               $recipientInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_recipient_class', strtolower($packageInstance->getRecipientType())));
-                       }
+                       // Try to find the right class
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance->recipientType=%s', $packageInstance->getRecipientType()));
+                       $recipientInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_recipient_class',
+                               $packageInstance->getRecipientType()
+                       ));
 
                        // Try to solve it
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Calling recipientInstance->resolveRecipientByPackageInstance(%s, %s) ...', $packageInstance->__toString(), $this->getListInstance()->__toString()));
@@ -94,6 +87,9 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
                        // Could not find class, what ever failed
                        $this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage()));
                }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: EXIT!');
        }
 
        /**
@@ -106,6 +102,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
         */
        public function discoverRawRecipients (DeliverablePackage $packageInstance) {
                // First clear all recipients
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->clearRecipients();
 
                // Get a protocol handler back from decoded data
index b9cabf147033254b9d4ca234928e61f312d43bf0..a26fe0c69127ff2389def4b7e3b7c2fe94010d65 100644 (file)
@@ -66,7 +66,10 @@ class SocketFactory extends ObjectFactory {
                $socketInstance = NULL;
 
                // Construct registry key
-               $registryKey = sprintf('socket_%s_%s', $protocolInstance->getProtocolName(), $packageInstance->getRecipientType());
+               $registryKey = sprintf('socket_%s_%s',
+                       $protocolInstance->getProtocolName(),
+                       $packageInstance->getRecipientType()
+               );
 
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey);
index 9fd6ebf5374283fcefeaf9dd75187689fe32d0e6..34410e81af4f4cdc5b07c57c0bc9fc638962116b 100644 (file)
@@ -62,16 +62,12 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
         * @return      $isAvailable    Whether this feature is available
         */
        public function isFeatureAvailable () {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
                // Testing this feature is pretty simple:
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
                $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
-
                // Return status
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
                return $isAvailable;
        }
 
@@ -86,19 +82,15 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
         * @return      $hash   Finished hash
         */
        public function featureMethodGenerateHash ($data) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
-
                // Make sure the feature is available
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
                assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
 
                // Call inner class
                $hash = Scrypt::hashScrypt($data);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
-
                // Return generated hash
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
                return $hash;
        }
 
@@ -110,19 +102,15 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
         * @return      $isValid        Whether the given hash matches a new one from given data
         */
        public function featureMethodCheckHash ($data, $hash) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
-
                // Make sure the feature is available
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
                assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
 
                // Determine it
                $isValid = Scrypt::checkScrypt($data, $hash);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
-
                // Return status
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
                return $isValid;
        }
 
index 1a495ee3a148968e4229aab14dca6a48ee40f6d2..a0f49260a133300a56458963e5a24170f953251b 100644 (file)
@@ -192,6 +192,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        const NETWORK_TARGET_DHT = 'dht';
 
+       /**
+        * Network target (alias): 'direct'
+        */
+       const NETWORK_TARGET_DIRECT = 'direct';
+
        /**
         * TCP package size in bytes
         */
@@ -841,6 +846,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                // Set all data
                $packageInstance->setSenderAddress($this->getNodeInstance()->getSessionId());
                $packageInstance->setSenderPort('0');
+               $packageInstance->setRecipientId($helperInstance->getRecipientId());
                $packageInstance->setRecipientType($helperInstance->getRecipientType());
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Setting packageContent=%s ...', $packageContent));
                $packageInstance->setPackageContent($packageContent);
index 8dfc2b0b48fe657d07db0495fbc077f3cda2b955..d29e8c89ff6129e00fa0c7160a2effe610451751 100644 (file)
@@ -28,6 +28,11 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseHubSystemHelper extends BaseHubSystem implements HubHelper {
+       /**
+        * Recipient id
+        */
+       private $recipientId = '';
+
        /**
         * Recipient type
         */
@@ -49,6 +54,24 @@ class BaseHubSystemHelper extends BaseHubSystem implements HubHelper {
                parent::__construct($className);
        }
 
+       /**
+        * Setter for recipient id
+        *
+        * @return      $recipientId    Receipient id (mostly session id)
+        */
+       protected final function setRecipientId ($recipientId) {
+               $this->recipientId = $recipientId;
+       }
+
+       /**
+        * Getter for recipient id
+        *
+        * @return      $recipientId    Receipient id (mostly session id)
+        */
+       public final function getRecipientId () {
+               return $this->recipientId;
+       }
+
        /**
         * Setter for recipient type
         *
index 52efa0db1428c01d91fa13d49fbacee2ebd3da9e..49cb9191167aea5854e1836332ac6c95b24164c9 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Node\Helper\Answer\Announcement;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
 use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
 use Org\Shipsimu\Hub\Node\Node;
 use Org\Shipsimu\Hub\Template\Engine\Xml\Announcement\XmlAnnouncementTemplateEngine;
@@ -60,7 +61,8 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements
                $helperInstance = new NodeAnnouncementMessageAnswerHelper();
 
                // Set session id of other peer as recipient
-               $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
+               $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+               $helperInstance->setRecipientId($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
 
                // Set message data
                $helperInstance->setMessageData($messageData);
index c596fc77cf22a31f5c4e1c654144f50b73693055..0b3520e1044686778f00548731179553fd50211f 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Node\Helper\Answer\Dht\Bootstrap;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
 use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
 use Org\Shipsimu\Hub\Node\Node;
 use Org\Shipsimu\Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
@@ -60,7 +61,8 @@ class NodeDhtBootstrapMessageAnswerHelper extends BaseHubAnswerHelper implements
                $helperInstance = new NodeDhtBootstrapMessageAnswerHelper();
 
                // Set session id of other peer as recipient
-               $helperInstance->setRecipientType($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
+               $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+               $helperInstance->setRecipientId($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
 
                // Set message data
                $helperInstance->setMessageData($messageData);
index 09f675a53db1354d5622005ac306c7488e5b528e..77a7e86507d6fb7c7972b38edd4d8cafb27fddd1 100644 (file)
@@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Node\Helper\Answer\Request\NodeList;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
 use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
 use Org\Shipsimu\Hub\Node\Node;
 use Org\Shipsimu\Hub\Template\Engine\Xml\Request\NodeList\XmlRequestNodeListTemplateEngine;
@@ -60,7 +61,8 @@ class NodeRequestNodeListMessageAnswerHelper extends BaseHubAnswerHelper impleme
                $helperInstance = new NodeRequestNodeListMessageAnswerHelper();
 
                // Set session id of other peer as recipient
-               $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
+               $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+               $helperInstance->setRecipientId($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
 
                // Set message data
                $helperInstance->setMessageData($messageData);