]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 12 Dec 2021 09:39:22 +0000 (10:39 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 12 Dec 2021 10:00:54 +0000 (11:00 +0100)
- cached determined external/internal addresses
- avoid setting $GLOBALS[<something>] (e.g. wrong "in-method cache")
- added some missing config entries for stacks
- updated 'core' framework

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/factories/handler/class_MessageTypeHandlerFactory.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/config.php
core

index c5296422bb32218032f5557b5352eda647ef11cf..e610ca37d936aa925ef65f9d6503ceb5bf52cc31 100644 (file)
@@ -59,7 +59,7 @@ class MessageTypeHandlerFactory extends BaseFactory {
                }
 
                // Init registry key
-               $registryKey = 'message_type_' . $messageType . '_handler';
+               $registryKey = sprintf('message_type_%s_handler', $messageType);
 
                // Do we have an instance in the registry?
                if (GenericRegistry::getRegistry()->instanceExists($registryKey)) {
@@ -67,7 +67,7 @@ class MessageTypeHandlerFactory extends BaseFactory {
                        $handlerInstance = GenericRegistry::getRegistry()->getInstance($registryKey);
                } else {
                        // Now prepare the tags instance
-                       $handlerInstance = ObjectFactory::createObjectByConfiguredName('message_type_' . $messageType . '_handler_class');
+                       $handlerInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class');
 
                        // Set the instance in registry for further use
                        GenericRegistry::getRegistry()->addInstance($registryKey, $handlerInstance);
index 34f007976d1e0500d4d2ce07e9ab33c91bb6cef4..cfe20d60b9dfc90ed127fd7202a5da4a7a9d3b4c 100644 (file)
@@ -46,19 +46,20 @@ class HubTools extends BaseHubSystem {
        const EXCEPTION_HOSTNAME_NOT_FOUND    = 0x201;
 
        /**
-        * Cache for session ids
+        * Cache for determined internal/external addresses to avoid "expensive"
+        * invocations on FrameworkConfiguration->getConfigEntry().
         */
-       private $sessionIdCache = [];
+       private static $cachedAddresses = [];
 
        /**
-        * Length for session id (should be 32+salt_length
+        * Self instance
         */
-       private $sessionIdLength = 0;
+       private static $selfInstance = NULL;
 
        /**
-        * Self instance
+        * Length for session id (should be 32+salt_length
         */
-       private static $selfInstance = NULL;
+       private $sessionIdLength = 0;
 
        /**
         * Protected constructor
@@ -119,9 +120,9 @@ class HubTools extends BaseHubSystem {
 
                // And ask it for Universal Node Locator by given session id
                $recipient = DhtObjectFactory::createDhtInstance('node')->findNodeLocalBySessionId($sessionId);
-               //* DEBUG-DIE: */ die(__METHOD__ . ': UNFINISHED: recipient[' . gettype($recipient) . ']=' . print_r($recipient, TRUE) . ',sessionId=' . $sessionId . PHP_EOL);
 
                // Is the recipient valid?
+               //* DEBUG-DIE: */ die(__METHOD__ . ': UNFINISHED: recipient[' . gettype($recipient) . ']=' . print_r($recipient, TRUE) . ',sessionId=' . $sessionId . PHP_EOL);
                if (isset($recipient[NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_EXTERNAL_ADDRESS])) {
                        // Then use this
                        $recipientUnl = $recipient[NodeDistributedHashTableDatabaseFrontend::DB_COLUMN_EXTERNAL_ADDRESS];
@@ -208,10 +209,17 @@ class HubTools extends BaseHubSystem {
         *
         * @param       $address        Session id or Universal Node Locator
         * @return      $recipient      Recipient as Universal Node Locator
+        * @throws      InvalidArgumentException        If a paramter is invalid
         * @throws      InvalidSessionIdException       If the provided session id is invalid (and no Universal Node Locator)
         * @throws      NoValidHostnameException        If the provided hostname cannot be resolved into an IP address
         */
        public static function resolveSessionIdToUnl (string $address) {
+               // Is the parameter valid?
+               if (empty($address)) {
+                       // No empty address
+                       throw new InvalidArgumentException('Parameter "address" cannot be empty');
+               }
+
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
@@ -223,15 +231,6 @@ class HubTools extends BaseHubSystem {
                        // @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})
                        // Direct Universal Node Locator found
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Direct Universal Node Locator ' . $address . ' detected.');
-               } elseif (isset($selfInstance->sessionIdCache[$address])) {
-                       // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Using entry from sessionIdCache[] array.');
-
-                       // Found in cache!
-                       $recipient = $selfInstance->sessionIdCache[$address];
-
-                       // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: sessionIdCache[' . $address . ']=' . $recipient);
                } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $address)) {
                        // Debug message
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Using internal session id resolver.');
@@ -257,15 +256,25 @@ class HubTools extends BaseHubSystem {
         */
        public static function determineOwnExternalAddress () {
                // Is the external_address config entry set?
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address') != '') {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
+               if (isset(self::$cachedAddresses['external'])) {
+                       // Get entry from cache
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting external address from cache ...');
+                       $unl = self::$cachedAddresses['external'];
+               } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address') != '') {
                        // Use it as external address
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry external_address ...');
                        $unl = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address');
+                       self::$cachedAddresses['external'] = $unl;
                } else {
-                       // Determine own external address by connecting to my (coder) server at 188.138.90.169
+                       // Determine own external address by connecting to home server at 188.138.90.169
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineExternalUniversalNodeLocator() ...');
                        $unl = self::determineExternalUniversalNodeLocator();
+                       self::$cachedAddresses['external'] = $unl;
                }
 
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
                return $unl;
        }
 
@@ -275,34 +284,31 @@ class HubTools extends BaseHubSystem {
         * @return      $unl    The determined internal UNL of this node
         */
        public static function determineOwnInternalAddress () {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
-
                // Is the internal_address config entry set?
-               if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
-
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
+               if (isset(self::$cachedAddresses['internal'])) {
+                       // Get entry from cache
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting internal address from cache ...');
+                       $unl = self::$cachedAddresses['internal'];
+               } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
                        // Not allowed to publish internal address, so use external
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
                        $unl = self::determineOwnExternalAddress();
+                       self::$cachedAddresses['internal'] = $unl;
                } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address') != '') {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry internal_address ...');
-
                        // Use it as internal address
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry internal_address ...');
                        $unl = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address');
+                       self::$cachedAddresses['internal'] = $unl;
                } else {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineInternalUniversalNodeLocator() ...');
-
                        // Determine own internal address
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineInternalUniversalNodeLocator() ...');
                        $unl = self::determineInternalUniversalNodeLocator();
+                       self::$cachedAddresses['internal'] = $unl;
                }
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
                return $unl;
        }
 
@@ -312,26 +318,17 @@ class HubTools extends BaseHubSystem {
         * @return      $internalUnl    Internal UNL
         */
        public static function determineInternalUniversalNodeLocator () {
-               // Debug message
+               // Determine UNL based on this node:
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
+               // 1) Get discovery class
+               $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
 
-               // Is there cache? (This shortens a lot calls)
-               if (!isset($GLOBALS[__METHOD__])) {
-                       // Determine UNL based on this node:
-                       // 1) Get discovery class
-                       $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
-                       // 2) "Determine" it
-                       $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
-
-                       // Make sure it is valid
-                       // @TODO Find a better validation than empty()
-                       assert(!empty($GLOBALS[__METHOD__]));
-               }
+               // 2) "Determine" it
+               $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
-               return $GLOBALS[__METHOD__];
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
+               return $unl;
        }
 
        /**
@@ -340,26 +337,17 @@ class HubTools extends BaseHubSystem {
         * @return      $externalUnl    External UNL
         */
        public static function determineExternalUniversalNodeLocator () {
-               // Debug message
+               // Determine UNL based on this node:
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
+               // 1) Get discovery class
+               $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
 
-               // Is there cache? (This shortens a lot calls)
-               if (!isset($GLOBALS[__METHOD__])) {
-                       // Determine UNL based on this node:
-                       // 1) Get discovery class
-                       $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
-                       // 2) "Determine" it
-                       $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
-
-                       // Make sure it is valid
-                       // @TODO Find a better validation than empty()
-                       assert(!empty($GLOBALS[__METHOD__]));
-               }
+               // 2) "Determine" it
+               $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
-               return $GLOBALS[__METHOD__];
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
+               return $unl;
        }
 
 }
index d1c118f4e0d27805c0412fd99bf7b810ae5139b3..645baa12088b8625257fc0fd3d5d0ceba9129f70 100644 (file)
@@ -501,6 +501,12 @@ $cfg->setConfigEntry('stacker_dht_pending_publish_max_size', 100);
 // CFG: STACKER-MULTIPLE-MESSAGE-MAX-SIZE
 $cfg->setConfigEntry('stacker_multiple_message_max_size', 10);
 
+// CFG: STACKER-MESSAGE-NEW-MAX_SIZE
+$cfg->setConfigEntry('stacker_message_new_max_size', 10);
+
+// CFG: STACKER-MESSAGE-PROCESSED-MAX_SIZE
+$cfg->setConfigEntry('stacker_message_processed_max_size', 10);
+
 // CFG: NEWS-MAIN-LIMIT
 $cfg->setConfigEntry('news_main_limit', 5);
 
diff --git a/core b/core
index b580ca852dc945d23290a6f7fb2c77e7c52e0d4b..8d68f4eec6508b1c1d49ef98a8bbbf0b27edd6b2 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit b580ca852dc945d23290a6f7fb2c77e7c52e0d4b
+Subproject commit 8d68f4eec6508b1c1d49ef98a8bbbf0b27edd6b2