From 34a880607a6e578dbfce66d1061fad22f0e29ee4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 12 Aug 2021 12:45:36 +0200 Subject: [PATCH] Continued: - 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! MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/nodes/class_BaseHubNode.php | 23 +++++++++++++++---- application/hub/config-local.php-dist | 4 ++-- application/hub/config.php | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index 5d7620ef5..b221c3508 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -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 diff --git a/application/hub/config-local.php-dist b/application/hub/config-local.php-dist index 679b47a97..2dce156b0 100644 --- a/application/hub/config-local.php-dist +++ b/application/hub/config-local.php-dist @@ -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); diff --git a/application/hub/config.php b/application/hub/config.php index a8d0a34f7..d1c118f4e 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -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); -- 2.39.5