]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 12 Aug 2021 10:45:36 +0000 (12:45 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 12 Aug 2021 10:45:36 +0000 (12:45 +0200)
- throw a OutOfBoundsException if an array element is not there
- initialize private key data record with NULL (stored currently as empty string)
- Do not shorten config keys, write them clearly!

Signed-off-by: Roland Häder <roland@mxchange.org>
application/hub/classes/nodes/class_BaseHubNode.php
application/hub/config-local.php-dist
application/hub/config.php

index 5d7620ef5e635559994090a00cdd3502355157ab..b221c3508265a785ecb6cbef55f6587d7497c831 100644 (file)
@@ -40,6 +40,7 @@ use Org\Mxchange\CoreFramework\Traits\State\StateableTrait;
 
 // Import SPL stuff
 use \InvalidArgumentException;
+use \OutOfBoundsException;
 use \UnexpectedValueException;
 
 /**
@@ -251,7 +252,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
 
                                // Stop further searching
                                break;
-                       } elseif ($unl == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('node_listen_addr')) {
+                       } elseif ($unl == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('node_listen_address')) {
                                /*
                                 * IP matches listen address. At this point we really don't care
                                 * if we can really listen on that address
@@ -416,6 +417,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
         *
         * @return      void
         * @throws      UnexpectedValueException        If private_key_hash is "invalid"
+        * @throws      OutOfBoundsException    If an array element is not found
         */
        public function bootstrapGeneratePrivateKey () {
                // Find node by id
@@ -430,12 +432,18 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                        $current = $resultInstance->current();
 
                        // Is the element set?
-                       if (is_null($current[NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY])) {
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: current(%s)=%d', NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY, array_key_exists(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY, $current)));
+                       //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: current[%s]=%s', __METHOD__, __LINE__, gettype($current), print_r($current, TRUE)));
+                       if (!array_key_exists(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY, $current)) {
+                               // This should not happend
+                               throw new OutOfBoundsException(sprintf('Array current[] does not contain element %s', NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY));
+                       } elseif (empty($current[NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY])) {
                                /*
                                 * Auto-generate the private key for e.g. out-dated database
                                 * "tables". This allows a smooth update for the underlaying
                                 * database table.
                                 */
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: Calling this->generatePrivateKeyAndHash(%s) ...', $this->getSearchInstance()->__toString()));
                                $this->generatePrivateKeyAndHash($this->getSearchInstance());
                        } else {
                                // Get the node id from result and set it
@@ -478,10 +486,15 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                        $criteriaInstance->addCriteria(NodeInformationDatabaseFrontend::DB_COLUMN_SESSION_ID, $this->getSessionId());
                }
 
-               // Add the private key if acquired
+               // Is the private key there?
                if (!empty($this->getPrivateKey())) {
+                       // Add the private key
                        $criteriaInstance->addCriteria(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY     , base64_encode($this->getPrivateKey()));
                        $criteriaInstance->addCriteria(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY_HASH, $this->getNodePrivateKeyHash());
+               } else {
+                       // Add empty fields
+                       $criteriaInstance->addCriteria(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY     , NULL);
+                       $criteriaInstance->addCriteria(NodeInformationDatabaseFrontend::DB_COLUMN_PRIVATE_KEY_HASH, NULL);
                }
 
                // Add own external and internal addresses as UNLs
@@ -657,7 +670,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class');
 
                // Setup address and port
-               $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
+               $listenerInstance->setListenAddressByConfiguration('node_listen_address');
 
                /*
                 * All nodes can now use the same configuration entry because it can be
@@ -684,7 +697,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class');
 
                // Setup address and port
-               $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
+               $listenerInstance->setListenAddressByConfiguration('node_listen_address');
 
                /*
                 * All nodes can now use the same configuration entry because it can be
index 679b47a9749170426dde3590bdba0a60bf8fdbc1..2dce156b05c5b53d6c2a01ccee6ff7930358c672 100644 (file)
@@ -39,8 +39,8 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 // Some hub-specific configuration like port hostname where we will listen, etc.
 $cfg = FrameworkBootstrap::getConfigurationInstance();
 
-// CFG: NODE-LISTEN-ADDR
-$cfg->setConfigEntry('node_listen_addr', '0.0.0.0');
+// CFG: NODE-LISTEN-ADDRESS
+$cfg->setConfigEntry('node_listen_address', '0.0.0.0');
 
 // CFG: NODE-LISTEN-PORT
 $cfg->setConfigEntry('node_listen_port', 9060);
index a8d0a34f7a6d492d77fd8fc2d716a0fb2ccb4be4..d1c118f4e0d27805c0412fd99bf7b810ae5139b3 100644 (file)
@@ -30,8 +30,8 @@ $cfg = FrameworkBootstrap::getConfigurationInstance();
 // CFG: HUB-BOOTSTRAP-NODES
 $cfg->setConfigEntry('hub_bootstrap_nodes', 'tcp://188.138.90.169:9060');
 
-// CFG: NODE-LISTEN-ADDR
-$cfg->setConfigEntry('node_listen_addr', '0.0.0.0');
+// CFG: NODE-LISTEN-ADDRESS
+$cfg->setConfigEntry('node_listen_address', '0.0.0.0');
 
 // CFG: NODE-LISTEN-PORT
 $cfg->setConfigEntry('node_listen_port', 9060);