From 66fe056b2df0c110683fb4378926cd3500bbec9a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 27 May 2015 03:33:40 +0200 Subject: [PATCH] Updated to latest 'core' + convertToClassName() and convertDashesToUnderscores() are now static. Signed-off-by: Roland Haeder --- application/hub/class_ApplicationHelper.php | 6 +- application/hub/config-local.php-dist | 3 + application/hub/config.php | 6 ++ .../interfaces/package/class_Receivable.php | 2 +- application/hub/main/class_BaseHubSystem.php | 2 +- application/hub/main/feature/.htaccess | 1 + .../hub/main/feature/hubcoin_reward/.htaccess | 1 + .../class_HubcoinRewardFeature.php | 69 +++++++++++++++++++ .../class_CruncherInitializationFilter.php | 2 +- .../miner/class_MinerInitializationFilter.php | 2 +- .../class_MinerPhpRequirementsFilter.php | 6 +- .../node/class_NodePhpRequirementsFilter.php | 6 +- .../assembler/class_PackageAssembler.php | 2 +- .../hub/main/package/class_NetworkPackage.php | 14 ++-- .../state/class_BaseStateResolver.php | 4 +- .../template/class_BaseXmlTemplateEngine.php | 10 +-- core | 2 +- 17 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 application/hub/main/feature/.htaccess create mode 100644 application/hub/main/feature/hubcoin_reward/.htaccess create mode 100644 application/hub/main/feature/hubcoin_reward/class_HubcoinRewardFeature.php diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 299754ec2..a44051c98 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -163,7 +163,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica $responseType = self::getResponseTypeFromSystem(); // Create a new request object - $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request'); + $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request'); // Remember request instance here $this->setRequestInstance($requestInstance); @@ -176,7 +176,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica } // END - if // ... and a new response object - $responseClass = sprintf('%sResponse', $this->convertToClassName($response)); + $responseClass = sprintf('%sResponse', self::convertToClassName($response)); $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this)); // Remember response instance here @@ -195,7 +195,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica } // END - if // Get a controller resolver - $resolverClass = $this->convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver'); + $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver'); $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); // Get a controller instance as well diff --git a/application/hub/config-local.php-dist b/application/hub/config-local.php-dist index 381d3a3fe..3525a612a 100644 --- a/application/hub/config-local.php-dist +++ b/application/hub/config-local.php-dist @@ -54,5 +54,8 @@ $cfg->setConfigEntry('node_default_mode', 'regular'); // CFG: HUB-BOOTSTRAP-NODES $cfg->setConfigEntry('hub_bootstrap_nodes', 'tcp://188.138.90.169:9060'); +// CFG: ENABLE-FEATURE-HUBCOINS-REWARD +// Disable this if you don't want to "earn" HubCoins: $cfg->setConfigEntry('enable_feature_hubcoins_reward', 'N'); + // [EOF] ?> diff --git a/application/hub/config.php b/application/hub/config.php index c46459859..85e59e4b6 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -33,6 +33,12 @@ $cfg->setConfigEntry('node_listen_port', 9060); // CFG: NODE-DEFAULT-MODE (can be 'regular', 'list', 'master' or 'boot', default is 'regular') $cfg->setConfigEntry('node_default_mode', 'regular'); +// CFG: ENABLE-FEATURE-HUBCOIN-REWARD +$cfg->setConfigEntry('enable_feature_hubcoin_reward', 'Y'); + +// CFG: FEATURE-HUBCOIN-REWARD-CLASS +$cfg->setConfigEntry('feature_hubcoin_reward_class', 'HubcoinsRewardFeature'); + // CFG: TEMPLATE-ENGINE $cfg->setConfigEntry('tpl_engine', 'ConsoleOutput'); diff --git a/application/hub/interfaces/package/class_Receivable.php b/application/hub/interfaces/package/class_Receivable.php index 5cf792583..47e72e09e 100644 --- a/application/hub/interfaces/package/class_Receivable.php +++ b/application/hub/interfaces/package/class_Receivable.php @@ -139,7 +139,7 @@ interface Receivable extends FrameworkInterface { * Feeds the hash and sender (as recipient for the 'sender' reward) to the * miner's queue, unless the message is not a "reward claim" message as this * leads to an endless loop. You may wish to run the miner to get some - * reward ("HubCoins") for "mining" this hash. + * reward ("Hubcoins") for "mining" this hash. * * @param $messageData Array with message data * @return void diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 1b2f3275a..3d1bb1cea 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -363,7 +363,7 @@ class BaseHubSystem extends BaseFrameworkSystem { */ protected function getSocketErrorHandlerFromCode ($errorCode) { // Create a name from translated error code - $handlerName = 'socketError' . $this->convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler'; + $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler'; // Is the call-back method there? if (!method_exists($this, $handlerName)) { diff --git a/application/hub/main/feature/.htaccess b/application/hub/main/feature/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/feature/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/feature/hubcoin_reward/.htaccess b/application/hub/main/feature/hubcoin_reward/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/feature/hubcoin_reward/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/feature/hubcoin_reward/class_HubcoinRewardFeature.php b/application/hub/main/feature/hubcoin_reward/class_HubcoinRewardFeature.php new file mode 100644 index 000000000..d1607ac8c --- /dev/null +++ b/application/hub/main/feature/hubcoin_reward/class_HubcoinRewardFeature.php @@ -0,0 +1,69 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class HubcoinRewardFeature extends BaseFeature implements Feature { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this Feature class and prepares it for usage + * + * @param $appInstance A manageable application + * @return $featureInstance An instance of this Feature class + */ + public final static function createHubcoinRewardFeature (ManageableApplication $appInstance) { + // Get a new instance + $featureInstance = new HubcoinRewardFeature(); + + // Return the prepared instance + return $featureInstance; + } + + /** + * Checks whether this feature can be made available to other classes. + * + * @return $isAvailable Whether this feature is available + */ + public function isFeatureAvailable () { + // Testing this feature is pretty simple: + $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === 'Y') && (extension_loaded('scrypt')) && (is_callable('scrypt'))); + + // Return status + return $isAvailable; + } + + /** + * Feature method 'generateHash' + * + * @param +} + +// [EOF] +?> diff --git a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php index ea7432ce8..7311542db 100644 --- a/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php +++ b/application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php @@ -67,7 +67,7 @@ class CruncherInitializationFilter extends BaseCruncherFilter implements Filtera } // Now convert the cruncher-mode in a class name - $className = 'Hub' . $this->convertToClassName($cruncherMode) . 'Cruncher'; + $className = 'Hub' . self::convertToClassName($cruncherMode) . 'Cruncher'; // And try to instance it try { diff --git a/application/hub/main/filter/miner/class_MinerInitializationFilter.php b/application/hub/main/filter/miner/class_MinerInitializationFilter.php index bf922d51f..dec2e891d 100644 --- a/application/hub/main/filter/miner/class_MinerInitializationFilter.php +++ b/application/hub/main/filter/miner/class_MinerInitializationFilter.php @@ -67,7 +67,7 @@ class MinerInitializationFilter extends BaseMinerFilter implements Filterable { } // Now convert the miner-mode in a class name - $className = 'Hub' . $this->convertToClassName($minerMode) . 'Miner'; + $className = 'Hub' . self::convertToClassName($minerMode) . 'Miner'; // And try to instance it try { diff --git a/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php index d75c2a05a..dc490d2ee 100644 --- a/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php +++ b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php @@ -66,14 +66,14 @@ class MinerPhpRequirementsFilter extends BaseMinerFilter implements Filterable { $checksFailed++; } // END -if - // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working + // 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.'); + 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.'); + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.'); } // Are all tests passed? diff --git a/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php b/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php index c63220ea0..bea3c8662 100644 --- a/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php +++ b/application/hub/main/filter/node/class_NodePhpRequirementsFilter.php @@ -66,14 +66,14 @@ class NodePhpRequirementsFilter extends BaseNodeFilter implements Filterable { $checksFailed++; } // END - if - // If scrypt() is not found (ext-scrypt) then the "HubCoins reward" is not working + // 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.'); + 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.'); + self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.'); } // Are all tests passed? diff --git a/application/hub/main/package/assembler/class_PackageAssembler.php b/application/hub/main/package/assembler/class_PackageAssembler.php index 5904750ca..192c54fb1 100644 --- a/application/hub/main/package/assembler/class_PackageAssembler.php +++ b/application/hub/main/package/assembler/class_PackageAssembler.php @@ -138,7 +138,7 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, ); // Construct call-back name from package error code - $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . $this->convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]); + $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]] = 'handlePackageBy' . self::convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]); // Abort if the call-back method is not there if (!method_exists($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]])) { diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 9b474be5e..df534cd3a 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -657,10 +657,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ private function generatePackageHash ($content, $senderId) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: extension_scrypt_loaded=' . intval($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded')) . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: isFeatureAvailable(hubcoin_reward)=' . intval(FrameworkFeature::isFeatureAvailable('hubcoin_reward')) . ' - CALLED!'); // Is the feature enabled? - if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { // Feature is not enabled return NULL; } // END - if @@ -674,7 +674,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Hash content and sender id together, use scrypt /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $senderId . ',content()=' . strlen($content)); - $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data)); + $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data))); // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ' - EXIT!'); @@ -693,7 +693,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ private function isPackageHashValid (array $decodedArray) { // Is the feature enabled? - if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { // Feature is not enabled, so hashes are always valid return TRUE; } // END - if @@ -701,7 +701,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // 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)); - $isHashValid = Scrypt::checkScrypt($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]); + $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH])); // Return it //* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . ',decodedArray=' . print_r($decodedArray, TRUE)); @@ -1425,7 +1425,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * Feeds the hash and sender (as recipient for the 'sender' reward) to the * miner's queue, unless the message is not a "reward claim" message as this * leads to an endless loop. You may wish to run the miner to get some - * reward ("HubCoins") for "mining" this hash. + * reward ("Hubcoins") for "mining" this hash. * * @param $messageData Array with message data * @return void @@ -1433,7 +1433,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ public function feedHashToMiner (array $messageData) { // Is the feature enabled? - if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) { + if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { /* * Feature is not enabled, don't feed the hash to the miner as it *may be invalid. diff --git a/application/hub/main/resolver/state/class_BaseStateResolver.php b/application/hub/main/resolver/state/class_BaseStateResolver.php index 62c7ca95e..8744b7156 100644 --- a/application/hub/main/resolver/state/class_BaseStateResolver.php +++ b/application/hub/main/resolver/state/class_BaseStateResolver.php @@ -96,7 +96,7 @@ class BaseStateResolver extends BaseResolver { $stateInstance = NULL; // Create state class name - $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State'; + $className = $this->getStatePrefix() . '' . self::convertToClassName($stateName) . 'State'; // ... and set it $this->setClassName($className); @@ -136,7 +136,7 @@ class BaseStateResolver extends BaseResolver { } // END - if // Create class name - $className = $this->statePrefix . $this->convertToClassName($stateName) . 'State'; + $className = $this->statePrefix . self::convertToClassName($stateName) . 'State'; // Now, let us create the full name of the state class $this->setClassName($className); diff --git a/application/hub/main/template/class_BaseXmlTemplateEngine.php b/application/hub/main/template/class_BaseXmlTemplateEngine.php index db4e2cfa2..6fca12e7c 100644 --- a/application/hub/main/template/class_BaseXmlTemplateEngine.php +++ b/application/hub/main/template/class_BaseXmlTemplateEngine.php @@ -245,7 +245,7 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { // Is the template dependency set? if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) { // Get a temporay template instance - $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . $this->convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class'); + $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance($this->typePrefix . '_' . self::convertDashesToUnderscores($node) . '_' . $this->xmlTemplateType . '_template_class'); // Then load it $templateInstance->loadXmlTemplate($templateDependency); @@ -269,7 +269,7 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { */ public final function startElement ($resource, $element, array $attributes) { // Initial method name which will never be called... - $methodName = 'init' . $this->convertToClassName($this->xmlTemplateType); + $methodName = 'init' . self::convertToClassName($this->xmlTemplateType); // Make the element name lower-case $element = strtolower($element); @@ -278,13 +278,13 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { //* DEBUG: */ echo "START: >".$element."<
\n"; if (in_array($element, $this->getMainNodes())) { // Okay, main node found! - $methodName = 'start' . $this->convertToClassName($element); + $methodName = 'start' . self::convertToClassName($element); // Set it $this->setCurrMainNode($element); } elseif (in_array($element, $this->getSubNodes())) { // Sub node found - $methodName = 'start' . $this->convertToClassName($element); + $methodName = 'start' . self::convertToClassName($element); } else { // Invalid node name found throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN); @@ -314,7 +314,7 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { } // END - if // Construct method name - $methodName = 'finish' . $this->convertToClassName($nodeName); + $methodName = 'finish' . self::convertToClassName($nodeName); // Call the corresponding method //* DEBUG: */ echo "call: ".$methodName."
\n"; diff --git a/core b/core index c397ac084..1f81d21b9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c397ac084fc4f194ddae9fd84ce7233197598704 +Subproject commit 1f81d21b97669832b84da3680d046eb9e4afba64 -- 2.39.2