From 6ab3bc9bc98e62c2950652cf38c63444cee762ba Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 27 May 2015 00:21:12 +0200 Subject: [PATCH] 'scrypt' is better now a "feature" which needs to be tested and enabled in a pre-filter. Signed-off-by: Roland Haeder --- application/hub/init.php | 3 +++ .../class_MinerPhpRequirementsFilter.php | 10 ++++++++ .../node/class_NodePhpRequirementsFilter.php | 12 +++++++++- .../hub/main/package/class_NetworkPackage.php | 23 ++++++++++++++++++- core | 2 +- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/application/hub/init.php b/application/hub/init.php index 548d5172e..8699bacb7 100644 --- a/application/hub/init.php +++ b/application/hub/init.php @@ -37,5 +37,8 @@ require($cfg->getConfigEntry('base_path') . 'inc/database.php'); // Get own internal address and set it in config $cfg->setConfigEntry('internal_address', HubTools::determineOwnInternalAddress()); +// By default scrypt is assumed (and later tested) NOT being there +$cfg->setConfigEntry('extension_scrypt_loaded', FALSE); + // [EOF] ?> diff --git a/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php index 8e3286dd0..d75c2a05a 100644 --- a/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php +++ b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php @@ -66,6 +66,16 @@ class MinerPhpRequirementsFilter extends BaseMinerFilter implements Filterable { $checksFailed++; } // END -if + // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working + if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) { + // Mark it as working + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "HubCoin reward" feature enabled.'); + $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE); + } else { + // Not working (not all have ext-scrypt installed + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "HubCoin reward" feature disabled.'); + } + // Are all tests passed? if ($checkPassed === FALSE) { // Throw an exception diff --git a/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php b/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php index c27302919..c63220ea0 100644 --- a/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php +++ b/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php @@ -64,7 +64,17 @@ class NodePhpRequirementsFilter extends BaseNodeFilter implements Filterable { // Test failed $checkPassed = FALSE; $checksFailed++; - } // END -if + } // END - if + + // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working + if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) { + // Mark it as working + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "HubCoin reward" feature enabled.'); + $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE); + } else { + // Not working (not all have ext-scrypt installed + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "HubCoin reward" feature disabled.'); + } // Are all tests passed? if ($checkPassed === FALSE) { diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index de863f121..c0e01cffb 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -653,9 +653,15 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * * @param $content Raw package data * @param $senderId Sender id to generate a hash for - * @return $hash Hash as hex-encoded string + * @return $hash Hash as hex-encoded string */ private function generatePackageHash ($content, $senderId) { + // Is the feature enabled? + if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + // Feature is not enabled + return NULL; + } // END - if + // Fake array $data = array( self::PACKAGE_CONTENT_SENDER => $senderId, @@ -680,6 +686,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @todo Unfinished area, hashes are currently NOT fully supported */ private function isPackageHashValid (array $decodedArray) { + // Is the feature enabled? + if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + // Feature is not enabled, so hashes are always valid + return TRUE; + } // END - if + // Check validity /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',decodedArray=' . print_r($decodedArray, TRUE)); //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE)); @@ -1414,6 +1426,15 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @todo ~10% done? */ public function feedHashToMiner (array $messageData) { + // Is the feature enabled? + if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + /* + * Feature is not enabled, don't feed the hash to the miner as it + *may be invalid. + */ + return; + } // END - if + // Make sure the required elements are there assert(isset($messageData[self::MESSAGE_ARRAY_SENDER])); assert(isset($messageData[self::MESSAGE_ARRAY_HASH])); diff --git a/core b/core index 0ae3d7b0f..4e6776af7 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 0ae3d7b0ff8ec700c174130c886eb2f9467022f0 +Subproject commit 4e6776af7c45da16f4bd7cfbab786c9c77179e01 -- 2.39.2