From: Roland Häder Date: Tue, 27 Oct 2020 09:12:33 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2fe09f580f8573249e864bf7af474ef4c90437a1;p=hub.git Continued: - 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 --- diff --git a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php index ffa39519b..374ee0760 100644 --- a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php +++ b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php @@ -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 diff --git a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php index 164792757..0a29c885f 100644 --- a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php +++ b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -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 diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index b9cabf147..a26fe0c69 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -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); diff --git a/application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php b/application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php index 9fd6ebf53..34410e81a 100644 --- a/application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php +++ b/application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php @@ -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; } diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 1a495ee3a..a0f49260a 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -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); diff --git a/application/hub/classes/helper/class_BaseHubSystemHelper.php b/application/hub/classes/helper/class_BaseHubSystemHelper.php index 8dfc2b0b4..d29e8c89f 100644 --- a/application/hub/classes/helper/class_BaseHubSystemHelper.php +++ b/application/hub/classes/helper/class_BaseHubSystemHelper.php @@ -28,6 +28,11 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; * along with this program. If not, see . */ 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 * diff --git a/application/hub/classes/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php b/application/hub/classes/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php index 52efa0db1..49cb91911 100644 --- a/application/hub/classes/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php +++ b/application/hub/classes/helper/node/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php @@ -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); diff --git a/application/hub/classes/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php b/application/hub/classes/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php index c596fc77c..0b3520e10 100644 --- a/application/hub/classes/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php +++ b/application/hub/classes/helper/node/answer/dht/class_NodeDhtBootstrapMessageAnswerHelper.php @@ -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); diff --git a/application/hub/classes/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php b/application/hub/classes/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php index 09f675a53..77a7e8650 100644 --- a/application/hub/classes/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php +++ b/application/hub/classes/helper/node/answer/requests/class_NodeRequestNodeListMessageAnswerHelper.php @@ -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);