From: Roland Haeder Date: Mon, 31 Mar 2014 19:32:15 +0000 (+0200) Subject: Added very basic classes and config entries (duplicated from cruncher sub-project... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f4667d20de8529f941eb7267e1497f05669c5b8;p=hub.git Added very basic classes and config entries (duplicated from cruncher sub-project) for "continued hashing miner". Signed-off-by: Roland Haeder --- diff --git a/application/hub/config.php b/application/hub/config.php index 526836593..c4fe119b5 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -919,6 +919,46 @@ $cfg->setConfigEntry('self_recipient_class', 'SelfRecipient'); // CFG: UPPER-RECIPIENT-CLASS $cfg->setConfigEntry('upper_recipient_class', 'UpperRecipient'); +/////////////////////////////////////////////////////////////////////////////// +// Miner configuration +/////////////////////////////////////////////////////////////////////////////// + +// CFG: MINER-DEFAULT-MODE (can be only 'chash' at the moment) +$cfg->setConfigEntry('miner_default_mode', 'chash'); + +// CFG: MINER-BUFFER-STACKER-CLASS +$cfg->setConfigEntry('miner_buffer_stacker_class', 'FiFoStacker'); + +// CFG: HUBCONSOLE-CMD-CRUNCHER-RESOLVER-CLASS +$cfg->setConfigEntry('hubconsole_cmd_miner_resolver_class', 'HubConsoleCommandResolver'); + +// CFG: MINER-PHP-REQUIREMENTS-FILTER +$cfg->setConfigEntry('miner_php_requirements_filter', 'MinerPhpRequirementsFilter'); + +// CFG: MINER-INITIALIZER-FILTER +$cfg->setConfigEntry('miner_initializer_filter', 'MinerInitializationFilter'); + +// CFG: MINER-WELCOME-TEASER-FILTER +$cfg->setConfigEntry('miner_welcome_teaser_filter', 'MinerWelcomeTeaserFilter'); + +// CFG: MINER-BOOTSTRAP-TASK-HANDLER-INITIALIZER-FILTER +$cfg->setConfigEntry('miner_bootstrap_task_handler_initializer_filter', 'MinerTaskHandlerInitializerFilter'); + +// CFG: CRUNCHER-BOOTSTRAP-EXTRA-BOOTSTRAPPING-FILTER +$cfg->setConfigEntry('miner_bootstrap_extra_bootstrapping_filter', 'MinerBootstrapExtraBootstrappingFilter'); + +// CFG: MINHER-BOOTSTRAP-BUFFER-QUEUE-INITIALIZER-FILTER +$cfg->setConfigEntry('miner_bootstrap_buffer_queue_initializer_filter', 'MinerBootstrapBufferQueueInitializerFilter'); + +// CFG: MINER-BOOTSTRAP-GENERIC-ACTIVATION-FILTER +$cfg->setConfigEntry('miner_bootstrap_generic_activation_filter', 'MinerBootstrapGenericActivationFilter'); + +// CFG: MINER-SHUTDOWN-FILTER +$cfg->setConfigEntry('miner_shutdown_filter', 'MinerShutdownFilter'); + +// CFG: MINER-INIT-STATE-CLASS +$cfg->setConfigEntry('miner_init_state_class', 'MinerInitState'); + /////////////////////////////////////////////////////////////////////////////// // Cruncher configuration /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/interfaces/miner/.htaccess b/application/hub/interfaces/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/miner/class_MinerHelper.php b/application/hub/interfaces/miner/class_MinerHelper.php new file mode 100644 index 000000000..4f1daedaf --- /dev/null +++ b/application/hub/interfaces/miner/class_MinerHelper.php @@ -0,0 +1,85 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * @todo We need to find a better name for this interface + * + * 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 . + */ +interface MinerHelper extends FrameworkInterface { + /** + * Method to "bootstrap" the miner. This step does also apply provided + * command-line arguments stored in the request instance. You should now + * get it from calling $this->getRequestInstance(). + * + * @return void + */ + function doBootstrapping (); + + /** + * This method determines if the in-buffer is going to depleted and if so, + * it fetches more WUs from the network. If no WU can be fetched from the + * network and if enabled, a random test WU is being generated. + * + * @return void + */ + function doFetchWorkUnits (); + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + function outputConsoleTeaser (); + + /** + * Add some miner-specific filters + * + * @param $controllerInstance An object of a Controller instance + * @param $responseInstance An object of a Responseable instance + * @return void + */ + function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance); + + /** + * Enables/disables the miner (just sets a flag) + * + * @param $version Version number of this miner + * @return void + */ + function enableIsActive ($isActive = TRUE); + + /** + * Determines whether the miner is active + * + * @return $isActive Whether the miner is active + */ + function isActive (); + + /** + * Initializes all buffer queues (mostly in/out) + * + * @return void + */ + function initBufferQueues (); +} + +// [EOF] +?> diff --git a/application/hub/main/commands/console/class_HubConsoleMinerCommand.php b/application/hub/main/commands/console/class_HubConsoleMinerCommand.php new file mode 100644 index 000000000..83aaf6369 --- /dev/null +++ b/application/hub/main/commands/console/class_HubConsoleMinerCommand.php @@ -0,0 +1,132 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2012 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 HubConsoleMinerCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public static final function createHubConsoleMinerCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new HubConsoleMinerCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo Try to create a MinerActivationTask or so + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a registry and the application instance from it + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + /* + * ----------------------- Bootstrapping phase ------------------------ + * Try to bootstrap the node and pass the request instance to it for + * extra arguments which mostly override config entries or enable special + * features within the hub (none is ready at this development stage) + */ + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Beginning with bootstrap...'); + $applicationInstance->getControllerInstance()->executeBootstrapFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Bootstrap finished.'); + + // Get miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Add some miner-specific filters + $minerInstance->addExtraMinerFilters(); + + // Get task handler instance + $handlerInstance = Registry::getRegistry()->getInstance('task_handler'); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---'); + + /* + * ----------------------------- Main loop ---------------------------- + * This is the main loop. Queried calls should come back here very fast + * so the whole application runs on nice speed. This while-loop goes + * until the miner is no longer active or all tasks are killed. + */ + while (($minerInstance->isActive()) && ($handlerInstance->hasTasksLeft())) { + // Handle all tasks here + $handlerInstance->handleTasks(); + } // END - while + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Leaving main loop. ---'); + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + * @todo Should we add some more filters? + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Add pre filters + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_php_requirements_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_initializer_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('miner_welcome_teaser_filter')); + + // Add bootstrap filters + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_task_handler_initializer_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_extra_bootstrapping_filter')); + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_buffer_queue_initializer_filter')); + + // This is the last generic boostrap filter + $controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('miner_bootstrap_generic_activation_filter')); + + // Add shutdown filters + //$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_task_handler_filter')); + + // This is the last generic shutdown filter + $controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('miner_shutdown_filter')); + } +} + +// [EOF] +?> diff --git a/application/hub/main/controller/console/class_HubConsoleMinerController.php b/application/hub/main/controller/console/class_HubConsoleMinerController.php new file mode 100644 index 000000000..96de80a07 --- /dev/null +++ b/application/hub/main/controller/console/class_HubConsoleMinerController.php @@ -0,0 +1,131 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2012 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 HubConsoleMinerController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Init additional filter chains + foreach (array('bootstrap','shutdown') as $filterChain) { + $this->initFilterChain($filterChain); + } // END - foreach + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + */ + public static final function createHubConsoleMinerController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new HubConsoleMinerController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the pre filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } + + /** + * Add a bootstrap filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addBootstrapFilter (Filterable $filterInstance) { + $this->addFilter('bootstrap', $filterInstance); + } + + /** + * Executes all bootstrap filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeBootstrapFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->executeFilters('bootstrap', $requestInstance, $responseInstance); + } + + /** + * Add a shutdown filter + * + * @param $filterInstance A Filterable class + * @return void + */ + public function addShutdownFilter (Filterable $filterInstance) { + $this->addFilter('shutdown', $filterInstance); + } + + /** + * Executes all shutdown filters + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + public function executeShutdownFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->executeFilters('shutdown', $requestInstance, $responseInstance); + } +} + +// [EOF] +?> diff --git a/application/hub/main/factories/states/miner/.htaccess b/application/hub/main/factories/states/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/states/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/states/miner/class_MinerStateFactory.php b/application/hub/main/factories/states/miner/class_MinerStateFactory.php new file mode 100644 index 000000000..5120f3da1 --- /dev/null +++ b/application/hub/main/factories/states/miner/class_MinerStateFactory.php @@ -0,0 +1,59 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerStateFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a configurable miner state and sets it in the + * given miner instance. + * + * @param $stateName Name of the state + * @param $minerInstance A MinerHelper class instance + * @return $stateInstance A Stateable class instance + */ + public static final function createMinerStateInstanceByName ($stateName, MinerHelper $minerInstance) { + // Then construct the class' configuraton entry + $className = 'miner_' . $stateName . '_state_class'; + + // Get a class from that configuration entry + $stateInstance = self::createObjectByConfiguredName($className, array($minerInstance)); + + // Once we have that state, set it in the miner instance + $minerInstance->setStateInstance($stateInstance); + + // For any purposes, return the state instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/bootstrap/miner/.htaccess b/application/hub/main/filter/bootstrap/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/bootstrap/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/bootstrap/miner/class_MinerBootstrap b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrap new file mode 100644 index 000000000..b80cc4de2 --- /dev/null +++ b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrap @@ -0,0 +1,66 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner 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 MinerBootstrap???Filter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createMinerBootstrap???Filter () { + // Get a new instance + $filterInstance = new MinerBootstrap???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Now do something + $this->partialStub('Please implement this step.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapBufferQueueInitializerFilter.php b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapBufferQueueInitializerFilter.php new file mode 100644 index 000000000..3998123b8 --- /dev/null +++ b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapBufferQueueInitializerFilter.php @@ -0,0 +1,66 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerBootstrapBufferQueueInitializerFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createMinerBootstrapBufferQueueInitializerFilter () { + // Get a new instance + $filterInstance = new MinerBootstrapBufferQueueInitializerFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Init all buffer queues + $minerInstance->initBufferQueues(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php new file mode 100644 index 000000000..7919af35b --- /dev/null +++ b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php @@ -0,0 +1,66 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerBootstrapExtraBootstrappingFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerBootstrapExtraBootstrappingFilter () { + // Get a new instance + $filterInstance = new MinerBootstrapExtraBootstrappingFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $minerInstance is null (no NullPointerException here) + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Do some extra bootstrapping steps + $minerInstance->doBootstrapping(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapGenericActivationFilter.php b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapGenericActivationFilter.php new file mode 100644 index 000000000..08d0c7cb0 --- /dev/null +++ b/application/hub/main/filter/bootstrap/miner/class_MinerBootstrapGenericActivationFilter.php @@ -0,0 +1,69 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerBootstrapGenericActivationFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createMinerBootstrapGenericActivationFilter () { + // Get a new instance + $filterInstance = new MinerBootstrapGenericActivationFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo Maybe we want to do somthing more here? + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get a miner instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Set the flag + $minerInstance->enableIsActive(); + + // Debug message + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: The miner has been activated.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/class_BaseMinerFilter.php b/application/hub/main/filter/class_BaseMinerFilter.php new file mode 100644 index 000000000..bfad26404 --- /dev/null +++ b/application/hub/main/filter/class_BaseMinerFilter.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 BaseMinerFilter extends BaseHubFilter { + /** + * Protected constructor + * + * @param $className Real name of class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/miner/.htaccess b/application/hub/main/filter/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/miner/class_Miner b/application/hub/main/filter/miner/class_Miner new file mode 100644 index 000000000..9bca1d696 --- /dev/null +++ b/application/hub/main/filter/miner/class_Miner @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 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 Miner???Filter extends BaseminerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createMiner???Filter () { + // Get a new instance + $filterInstance = new Miner???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/miner/class_MinerInitializationFilter.php b/application/hub/main/filter/miner/class_MinerInitializationFilter.php new file mode 100644 index 000000000..5785e5b95 --- /dev/null +++ b/application/hub/main/filter/miner/class_MinerInitializationFilter.php @@ -0,0 +1,97 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerInitializationFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerInitializationFilter () { + // Get a new instance + $filterInstance = new MinerInitializationFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // The default miner-mode is from our configuration + $minerMode = $this->getConfigInstance()->getConfigEntry('miner_default_mode'); + + // Is the miner 'mode' parameter set? + if ($requestInstance->isRequestElementSet('mode')) { + // Then use this which overrides the config entry temporarily + $minerMode = $requestInstance->getRequestElement('mode'); + } else { + // Set it for easier re-usage + $requestInstance->setRequestElement('mode', $minerMode); + } + + // Now convert the miner-mode in a class name + $className = 'Hub' . $this->convertToClassName($minerMode) . 'Miner'; + + // And try to instance it + try { + // Get an instance + $minerInstance = ObjectFactory::createObjectByName($className); + + // Get a registry + $applicationInstance = Registry::getRegistry()->getInstance('app'); + + // Set the app instance + $minerInstance->setApplicationInstance($applicationInstance); + + // Add miner-specific filters + $minerInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); + } catch (ClassNotFoundException $e) { + // This exception means, the miner mode is invalid. + // @TODO Can we rewrite this to app_exit() ? + $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: miner mode ' . $minerMode . ' is invalid.'); + } + + // Set the miner instance in registry + Registry::getRegistry()->addInstance('miner', $minerInstance); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php new file mode 100644 index 000000000..8e3286dd0 --- /dev/null +++ b/application/hub/main/filter/miner/class_MinerPhpRequirementsFilter.php @@ -0,0 +1,78 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerPhpRequirementsFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerPhpRequirementsFilter () { + // Get a new instance + $filterInstance = new MinerPhpRequirementsFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If a required PHP function is not available + * @todo Add more test and try to add an extra message to the thrown exception + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // By default, the requirement check is passed and zero checks are failed + $checkPassed = TRUE; + $checksFailed = 0; + + // Socket support is essential... + if (!function_exists('socket_create')) { + // Test failed + $checkPassed = FALSE; + $checksFailed++; + } // END -if + + // Are all tests passed? + if ($checkPassed === FALSE) { + // Throw an exception + throw new FilterChainException($this, self::FILTER_CHAIN_INTERCEPTED); + } // END - if + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/miner/class_MinerWelcomeTeaserFilter.php b/application/hub/main/filter/miner/class_MinerWelcomeTeaserFilter.php new file mode 100644 index 000000000..e671de20a --- /dev/null +++ b/application/hub/main/filter/miner/class_MinerWelcomeTeaserFilter.php @@ -0,0 +1,67 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerWelcomeTeaserFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerWelcomeTeaserFilter () { + // Get a new instance + $filterInstance = new MinerWelcomeTeaserFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $nodeInstance is null (no NullPointerException here) + * @todo Handle over the $responseInstance to outputConsoleTeaser() + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get node instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Now output the teaser + $minerInstance->outputConsoleTeaser(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/shutdown/miner/.htaccess b/application/hub/main/filter/shutdown/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/shutdown/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/shutdown/miner/class_MinerShutdownFilter.php b/application/hub/main/filter/shutdown/miner/class_MinerShutdownFilter.php new file mode 100644 index 000000000..8481f1dd6 --- /dev/null +++ b/application/hub/main/filter/shutdown/miner/class_MinerShutdownFilter.php @@ -0,0 +1,68 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerShutdownFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerShutdownFilter () { + // Get a new instance + $filterInstance = new MinerShutdownFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If $nodeInstance is null (no NullPointerException please) + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get node instance + $minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Shutdown the miner. This should be the last line + $minerInstance->doShutdown(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/task/miner/.htaccess b/application/hub/main/filter/task/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/filter/task/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php new file mode 100644 index 000000000..8f132efe7 --- /dev/null +++ b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php @@ -0,0 +1,76 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public static final function createMinerTaskHandlerInitializerFilter () { + // Get a new instance + $filterInstance = new MinerTaskHandlerInitializerFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @throws FilterChainException If we need to interrupt the filter chain + * @todo 5% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Get miner instance + //$minerInstance = Registry::getRegistry()->getInstance('miner'); + + // Get a new task handler instance + $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class'); + + // Register all tasks: + // + // 1) A task for ... + //$taskInstance = ObjectFactory::createObjectByConfiguredName('miner_???_task_class'); + //$handlerInstance->registerTask('miner_???', $taskInstance); + + // Put the task handler in registry + Registry::getRegistry()->addInstance('task_handler', $handlerInstance); + } +} + +// [EOF] +?> diff --git a/application/hub/main/miner/.htaccess b/application/hub/main/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/miner/chash/.htaccess b/application/hub/main/miner/chash/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/miner/chash/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/miner/chash/class_HubChashMiner.php b/application/hub/main/miner/chash/class_HubChashMiner.php new file mode 100644 index 000000000..dbc20dd02 --- /dev/null +++ b/application/hub/main/miner/chash/class_HubChashMiner.php @@ -0,0 +1,147 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 HubChashMiner extends BaseHubMiner implements MinerHelper, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set version number + $this->setVersion('0.0.0'); + } + + /** + * Creates an instance of this hub-miner class + * + * @return $minerInstance An instance of this hub-miner class + */ + public final static function createHubChashMiner () { + // Get a new instance + $minerInstance = new HubChashMiner(); + + // Return the instance + return $minerInstance; + } + + /** + * This method fills the in-buffer with (a) test unit(s) which are mainly + * used for development of the crunching part. They must be enabled in + * configuration, or else your miner runs out of WUs and waits for more + * to show up. + * + * In this method we already know that the in-buffer is going depleted so + * we don't need to double-check it here. + * + * @return void + */ + protected function fillInBufferQueueWithTestUnits () { + // Are test units enabled? + if ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'N') { + // They are disabled, so skip any further steps + return; + } elseif ($this->getStateInstance()->isMinerStateVirgin()) { + // No virgin miners please, because they usually have no test units ready for crunching + return; + } + + // Get a test-unit generator instance + $generatorInstance = ObjectFactory::createObjectByConfiguredName('miner_test_unit_generator_class'); + + // We don't need an iterator here because we just need to generate some test units + for ($idx = 0; $idx < $this->getConfigInstance()->getConfigEntry('miner_max_text_unit_amount'); $idx++) { + // Get a test unit from it + $unitInstance = $generatorInstance->generateNextUnitInstance(); + + // ... and finally queue it to the in-buffer queue + $this->queueUnitInstanceToInBuffer($unitInstance); + } // END - for + } + + /** + * This method fills the in-buffer with (real) WUs which will be crunched + * and the result be sent back to the key producer instance. + * + * @return void + */ + protected function fillInBufferQueueWithWorkUnits () { + // This miner's state must not be one of these: 'virgin' + if ($this->getStateInstance()->isMinerStateVirgin()) { + // We can silently skip here, until the generation is finished + return; + } // END - if + + // @TODO Implement this method + $this->partialStub('Please implement this method.'); + } + + /** + * Method to "bootstrap" the miner. This step does also apply provided + * command-line arguments stored in the request instance. No buffer queue + * will be initialized here, we only do "general" things here. + * + * @return void + * @todo Implement this method + */ + public function doBootstrapping () { + $this->partialStub('Please implement this method.'); + } + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + public function outputConsoleTeaser () { + // Output all lines + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput('Continued Hashing Miner v' . $this->getVersion() . ' is starting ...'); + self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2014 Miner Developer Team'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.'); + self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain'); + self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.'); + self::createDebugInstance(__CLASS__)->debugOutput(' '); + } + + /** + * Add some miner-specific filters + * + * @param $controllerInstance An object of a Controller instance + * @param $responseInstance An object of a Responseable instance + * @return void + * @todo 0% done + */ + public function addExtraFilters (Controller $controllerInstance, Responseable $responseInstance) { + // Add some filters here + $this->partialStub('Please add some miner-specific filters, if required.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/miner/class_ b/application/hub/main/miner/class_ new file mode 100644 index 000000000..090621d91 --- /dev/null +++ b/application/hub/main/miner/class_ @@ -0,0 +1,90 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner 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 Hub???Miner extends BaseHubMiner implements MinerHelper, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set version number + $this->setVersion('x.x'); + } + + /** + * Creates an instance of this hub-miner class + * + * @param $requestInstance An instance of a Requestable class + * @return $minerInstance An instance of this hub-miner class + */ + public final static function createHub???Miner (Requestable $requestInstance) { + // Get a new instance + $minerInstance = new Hub???Miner(); + + // Set the request instance + $minerInstance->setRequestInstance($requestInstance); + + // Return the instance + return $minerInstance; + } + + /** + * Method to "bootstrap" the miner. This step does also apply provided + * command-line arguments stored in the request instance. The regular miner + * should communicate with the bootstrap-miners at this point. + * + * @return void + * @todo Implement this method + */ + public function doBootstrapping () { + // Call generic (parent) bootstrapping method first + parent::doGenericBootstrapping(); + $this->partialStub('Please implement this method.'); + } + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + public function outputConsoleTeaser () { + $this->partialStub('Please implement this method.'); + } + + /** + * Add some miner-specific filters + * + * @return void + */ + public function addExtraHubFilters () { + // Add some filters here + } +} + +// [EOF] +?> diff --git a/application/hub/main/miner/class_BaseHubMiner.php b/application/hub/main/miner/class_BaseHubMiner.php new file mode 100644 index 000000000..a8e322321 --- /dev/null +++ b/application/hub/main/miner/class_BaseHubMiner.php @@ -0,0 +1,210 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2012 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 . + */ +abstract class BaseHubMiner extends BaseHubSystem implements Updateable { + /** + * Version information + */ + private $version = 'x.x'; + + /** + * By default no miner is active + */ + private $isActive = FALSE; + + /** + * All buffer queue instances (a FIFO) + */ + private $bufferInstance = NULL; + + /** + * Stacker name for incoming queue + */ + const STACKER_NAME_IN_QUEUE = 'in_queue'; + + /** + * Stacker name for outcoming queue + */ + const STACKER_NAME_OUT_QUEUE = 'out_queue'; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Init this miner + $this->initMiner(); + } + + /** + * Initialize the miner generically + * + * @return void + */ + private function initMiner () { + // Init the state + MinerStateFactory::createMinerStateInstanceByName('init', $this); + } + + /** + * Getter for version + * + * @return $version Version number of this miner + */ + protected final function getVersion () { + return $this->version; + } + + /** + * Setter for version + * + * @param $version Version number of this miner + * @return void + */ + protected final function setVersion ($version) { + $this->version = (string) $version; + } + + /** + * Checks whether the in-buffer queue is filled by comparing it's current + * amount of entries against a threshold. + * + * @return $isFilled Whether the in-buffer is filled + */ + protected function isInBufferQueueFilled () { + // Determine it + $isFilled = ($this->bufferInstance->getStackCount(self::STACKER_NAME_IN_QUEUE) > $this->getConfigInstance()->getConfigEntry('miner_in_buffer_min_threshold')); + + // And return the result + return $isFilled; + } + + /** + * This method fills the in-buffer with (a) test unit(s) which are mainly + * used for development of the crunching part. They must be enabled in + * configuration, or else your miner runs out of WUs and waits for more + * to show up. + * + * In this method we already know that the in-buffer is going depleted so + * we don't need to double-check it here. + * + * @return void + */ + abstract protected function fillInBufferQueueWithTestUnits (); + + /** + * This method fills the in-buffer with (real) WUs which will be crunched + * and the result be sent back to the key producer instance. + * + * @return void + */ + abstract protected function fillInBufferQueueWithWorkUnits (); + + /** + * Enables/disables the miner (just sets a flag) + * + * @param $version Version number of this miner + * @return void + */ + public final function enableIsActive ($isActive = TRUE) { + $this->isActive = (bool) $isActive; + } + + /** + * Determines whether the miner is active + * + * @return $isActive Whether the miner is active + */ + public final function isActive () { + return $this->isActive; + } + + /** + * Initializes all buffer queues (mostly in/out). This method is demanded + * by the MinerHelper interface. + * + * @return void + */ + public function initBufferQueues () { + /* + * Initialize both buffer queues, we can use the FIFO class here + * directly and encapsulate its method calls with protected methods. + */ + $this->bufferInstance = ObjectFactory::createObjectByConfiguredName('miner_buffer_stacker_class'); + + // Initialize common stackers, like in/out + $this->bufferInstance->initStacks(array( + self::STACKER_NAME_IN_QUEUE, + self::STACKER_NAME_OUT_QUEUE + )); + + // Output debug message + self::createDebugInstance(__CLASS__)->debugOutput('MINER: All buffers are now initialized.'); + } + + /** + * This method determines if the in-buffer is going to depleted and if so, + * it fetches more WUs from the network. If no WU can be fetched from the + * network and if enabled, a random test WU is being generated. + * + * This method is demanded from the MinerHelper interface. + * + * @return void + */ + public function doFetchWorkUnits () { + // Simply check if we have enough WUs left in the in-buffer queue (a FIFO) + if (!$this->isInBufferQueueFilled()) { + // The in-buffer queue needs filling, so head out and get some work + $this->fillInBufferQueueWithWorkUnits(); + + // Is the buffer still not filled and are test-packages allowed? + if ((!$this->isInBufferQueueFilled()) && ($this->getConfigInstance()->getConfigEntry('miner_test_units_enabled') == 'Y')) { + // Then fill the in-buffer with (one) test-unit(s) + $this->fillInBufferQueueWithTestUnits(); + } // END - if + } // END - if + } + + /** + * Updates a given field with new value + * + * @param $fieldName Field to update + * @param $fieldValue New value to store + * @return void + * @throws DatabaseUpdateSupportException If this class does not support database updates + * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem + */ + public function updateDatabaseField ($fieldName, $fieldValue) { + // Unfinished + $this->partialStub('Unfinished!'); + return; + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/miner/.htaccess b/application/hub/main/states/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/miner/class_ b/application/hub/main/states/miner/class_ new file mode 100644 index 000000000..b2020ce94 --- /dev/null +++ b/application/hub/main/states/miner/class_ @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner 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 Miner???State extends BaseMinerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('!!!'); + } + + /** + * Creates an instance of this class + * + * @param $minerInstance An instance of a MinerHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createMiner???State (MinerHelper $minerInstance) { + // Get new instance + $stateInstance = new Miner???State(); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Has changed from ' . $minerInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the miner instance + $stateInstance->setMinerInstance($minerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + public function executeState (Executor $executorInstance) { + $this->partialStub('This state needs implementation. executorInstance=' . $executorInstance->__toString()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/miner/class_BaseMinerState.php b/application/hub/main/states/miner/class_BaseMinerState.php new file mode 100644 index 000000000..e1a0ed334 --- /dev/null +++ b/application/hub/main/states/miner/class_BaseMinerState.php @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 BaseMinerState extends BaseState { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Validates whether the state is 'active' or throws an exception if + * it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'active' + */ + public function validateMinerStateIsActive () { + // Just compare it... + if (!$this instanceof MinerActiveState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } + + /** + * Checks if this state is 'virgin' + * + * @return $isVirgin Whether this state is 'virgin' + */ + public function isMinerStateVirgin () { + // Just compare it... + return ($this instanceof MinerVirginState); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/miner/init/.htaccess b/application/hub/main/states/miner/init/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/miner/init/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/miner/init/class_MinerInitState.php b/application/hub/main/states/miner/init/class_MinerInitState.php new file mode 100644 index 000000000..02d353209 --- /dev/null +++ b/application/hub/main/states/miner/init/class_MinerInitState.php @@ -0,0 +1,79 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerInitState extends BaseMinerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('init'); + } + + /** + * Creates an instance of this class + * + * @param $minerInstance An instance of a MinerHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createMinerInitState (MinerHelper $minerInstance) { + // Get new instance + $stateInstance = new MinerInitState(); + + // Set the miner instance + $stateInstance->setMinerInstance($minerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + public function executeState (Executor $executorInstance) { + // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there + $executorInstance->prepareUnitProduction($this); + } + + /** + * An encrypted message has been generated so we change the state to + * 'virgin'. + * + * @return void + */ + public function encryptedMessageGenerated () { + // Change the state now to 'virgin' + MinerStateFactory::createMinerStateInstanceByName('virgin', $this->getMinerInstance()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/miner/virgin/.htaccess b/application/hub/main/states/miner/virgin/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/miner/virgin/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/miner/virgin/class_MinerVirginState.php b/application/hub/main/states/miner/virgin/class_MinerVirginState.php new file mode 100644 index 000000000..01450614c --- /dev/null +++ b/application/hub/main/states/miner/virgin/class_MinerVirginState.php @@ -0,0 +1,68 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2014 Miner Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.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 MinerVirginState extends BaseMinerState implements Stateable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('virgin'); + } + + /** + * Creates an instance of this class + * + * @param $minerInstance An instance of a MinerHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createMinerVirginState (MinerHelper $minerInstance) { + // Get new instance + $stateInstance = new MinerVirginState(); + + // Set the miner instance + $stateInstance->setMinerInstance($minerInstance); + + // Return the prepared instance + return $stateInstance; + } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + public function executeState (Executor $executorInstance) { + // Produce some keys now + $executorInstance->produceKeys($this); + } +} + +// [EOF] +?>