From: Roland Haeder Date: Mon, 31 Mar 2014 21:07:41 +0000 (+0200) Subject: Added unfinished stuff for producing the test "genesis block". X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=da797bb51fd80363eda297291e09be47530698fc;p=hub.git Added unfinished stuff for producing the test "genesis block". Signed-off-by: Roland Haeder --- diff --git a/application/hub/config.php b/application/hub/config.php index c4fe119b5..8242ceff1 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -959,6 +959,33 @@ $cfg->setConfigEntry('miner_shutdown_filter', 'MinerShutdownFilter'); // CFG: MINER-INIT-STATE-CLASS $cfg->setConfigEntry('miner_init_state_class', 'MinerInitState'); +// CFG: MINER-BLOCK-FETCHER-TASK-CLASS +$cfg->setConfigEntry('miner_block_fetcher_task_class', 'MinerBlockFetcherTask'); + +// CFG: TASK-MINER-BLOCK-FETCHER-STARTUP-DELAY +$cfg->setConfigEntry('task_miner_block_fetcher_startup_delay', 1000); + +// CFG: TASK-MINER-BLOCK-FETCHER-INTERVAL-DELAY +$cfg->setConfigEntry('task_miner_block_fetcher_interval_delay', 10); + +// CFG: TASK--FETCHER-MAX-RUNS +$cfg->setConfigEntry('task_miner_block_fetcher_max_runs', 0); + +// CFG: MINER-TEST-GENESIS-BLOCK-PRODUCER-TASK-CLASS +$cfg->setConfigEntry('miner_test_genesis_block_producer_task_class', 'MinerTestGenesisBlockProducerTask'); + +// CFG: TASK-MINER-TEST-GENESIS-BLOCK-PRODUCER-STARTUP-DELAY +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_startup_delay', 500); + +// CFG: TASK-MINER-TEST-GENESIS-BLOCK-PRODUCER-INTERVAL-DELAY +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_interval_delay', 1000*60*60); + +// CFG: TASK-MINER-TEST-GENESIC-BLOCK-PRODUCER-MAX-RUNS +$cfg->setConfigEntry('task_miner_test_genesis_block_producer_max_runs', 1); + +// CFG: MINER-TEST-GENESIS-BLOCK-PRODUCER-CLASS +$cfg->setConfigEntry('miner_test_genesis_block_producer_class', 'MinerTestGenesisBlockProducer'); + /////////////////////////////////////////////////////////////////////////////// // Cruncher configuration /////////////////////////////////////////////////////////////////////////////// @@ -999,12 +1026,6 @@ $cfg->setConfigEntry('cruncher_shutdown_filter', 'CruncherShutdownFilter'); // CFG: CRUNCHER-WORK-UNIT-FETCHER-TASK-CLASS $cfg->setConfigEntry('cruncher_work_unit_fetcher_task_class', 'CruncherWorkUnitFetcherTask'); -// CFG: CRUNCHER-TEST-UNIT-PRODUCER-TASK-CLASS -$cfg->setConfigEntry('cruncher_test_unit_producer_task_class', 'CruncherTestUnitProducerTask'); - -// CFG: CRUNCHER-KEY-PRODUCER-TASK-CLASS -$cfg->setConfigEntry('cruncher_key_producer_task_class', 'CruncherKeyProducerTask'); - // CFG: TASK-CRUNCHER-WORK-UNIT-FETCHER-STARTUP-DELAY $cfg->setConfigEntry('task_cruncher_work_unit_fetcher_startup_delay', 1000); @@ -1014,6 +1035,9 @@ $cfg->setConfigEntry('task_cruncher_work_unit_fetcher_interval_delay', 10); // CFG: TASK-CRUNCHER-WORK-UNIT-FETCHER-MAX-RUNS $cfg->setConfigEntry('task_cruncher_work_unit_fetcher_max_runs', 0); +// CFG: CRUNCHER-TEST-UNIT-PRODUCER-TASK-CLASS +$cfg->setConfigEntry('cruncher_test_unit_producer_task_class', 'CruncherTestUnitProducerTask'); + // CFG: TASK-CRUNCHER-TEST-UNIT-PRODUCER-STARTUP-DELAY $cfg->setConfigEntry('task_cruncher_test_unit_producer_startup_delay', 500); @@ -1023,6 +1047,9 @@ $cfg->setConfigEntry('task_cruncher_test_unit_producer_interval_delay', 1000*60* // CFG: TASK-CRUNCHER-TEST-UNIT-PRODUCER-MAX-RUNS $cfg->setConfigEntry('task_cruncher_test_unit_producer_max_runs', 0); +// CFG: CRUNCHER-KEY-PRODUCER-TASK-CLASS +$cfg->setConfigEntry('cruncher_key_producer_task_class', 'CruncherKeyProducerTask'); + // CFG: TASK-CRUNCHER-KEY-PRODUCER-STARTUP-DELAY $cfg->setConfigEntry('task_cruncher_key_producer_startup_delay', 750); diff --git a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php index 8f132efe7..3bdbdd920 100644 --- a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php @@ -63,9 +63,17 @@ class MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filte // Register all tasks: // - // 1) A task for ... - //$taskInstance = ObjectFactory::createObjectByConfiguredName('miner_???_task_class'); - //$handlerInstance->registerTask('miner_???', $taskInstance); + // 1) A task for fetching blocks from the network + $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_block_fetcher_task_class'); + $handlerInstance->registerTask('miner_block_fetcher', $taskInstance); + + /* + * 2) A task for generating a test "genesis" block. This "block" + * consists of several hashes of famous phrases or "catch lines" from + * free-software authors. + */ + $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_test_genesis_block_producer_task_class'); + $handlerInstance->registerTask('miner_test_genesis_block_producer', $taskInstance); // Put the task handler in registry Registry::getRegistry()->addInstance('task_handler', $handlerInstance); diff --git a/application/hub/main/producer/miner/.htaccess b/application/hub/main/producer/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/miner/blocks/.htaccess b/application/hub/main/producer/miner/blocks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/miner/blocks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php new file mode 100644 index 000000000..44ac83e6d --- /dev/null +++ b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2011 - 2014 Cruncher 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 MinerTestGenesisBlockProducer extends BaseUnitProducer implements UnitProducer, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $producerInstance An instance of a Producer class + */ + public final static function createMinerTestGenesisBlockProducer () { + // Get new instance + $producerInstance = new MinerTestGenesisBlockProducer(); + + // Return the prepared instance + return $producerInstance; + } + + /** + * Initializes the producer. This method satisfies the abstract BaseProducer + * class. + * + * @return void + * @todo 0% done + */ + protected function initProducer () { + $this->partialStub('Please implement this method.'); + } + + /** + * Prepares the produces of some test units and pushes them onto the queue + * + * @param $stateInstance An instance of a Stateable instance + * @return void + * @todo 0% done + */ + public function prepareUnitProduction (Stateable $stateInstance) { + $this->partialStub('Please implement this method, stateInstance=' . $stateInstance->__toString()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/producer/miner/class_BaseBlockProducer.php b/application/hub/main/producer/miner/class_BaseBlockProducer.php new file mode 100644 index 000000000..4ed231824 --- /dev/null +++ b/application/hub/main/producer/miner/class_BaseBlockProducer.php @@ -0,0 +1,42 @@ + + * @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 . + */ +abstract class BaseBlockProducer extends BaseProducer { + /** + * Block status + */ + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/miner/.htaccess b/application/hub/main/tasks/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/miner/class_ b/application/hub/main/tasks/miner/class_ new file mode 100644 index 000000000..98281cc40 --- /dev/null +++ b/application/hub/main/tasks/miner/class_ @@ -0,0 +1,72 @@ + + * @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???Task extends BaseTask implements Taskable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $taskInstance An instance of a Visitable class + */ + public final static function createMiner???Task () { + // Get new instance + $taskInstance = new Miner???Task(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + * @todo Maybe visit some sub-objects + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + * @todo 0% + */ + public function executeTask () { + $this->partialStub('Unimplemented task.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php b/application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php new file mode 100644 index 000000000..21ed5370f --- /dev/null +++ b/application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php @@ -0,0 +1,80 @@ + + * @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 MinerBlockFetcherTask extends BaseTask implements Taskable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $taskInstance An instance of a Taskable/Visitable class + */ + public final static function createMinerBlockFetcherTask () { + // Get new instance + $taskInstance = new MinerBlockFetcherTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + */ + public function executeTask () { + /* + * Get the miner instance and call a method which should check if + * the in-buffer is going to depleted. If so, new WUs are fetched from + * network or (if enabled in config) a random test WU is being + * generated. This test WU is for developing only or, if you like, to + * test your miner loop. + * + * Please report any bugs you encounter to me. + */ + Registry::getRegistry()->getInstance('miner')->doSearchForBlocks(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php b/application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php new file mode 100644 index 000000000..8963ae3e2 --- /dev/null +++ b/application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php @@ -0,0 +1,80 @@ + + * @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 MinerTestGenesisBlockProducerTask extends BaseTask implements Taskable, Visitable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $taskInstance An instance of a Taskable/Visitable class + */ + public final static function createMinerTestGenesisBlockProducerTask () { + // Get new instance + $taskInstance = new MinerTestGenesisBlockProducerTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visitor + * + * @param $visitorInstance An instance of a Visitor class + * @return void + */ + public function accept (Visitor $visitorInstance) { + // Visit this task + $visitorInstance->visitTask($this); + } + + /** + * Executes the task + * + * @return void + */ + public function executeTask () { + // Get the producer instance + $producerInstance = ProducerFactory::createProducerInstance('miner_test_genesis_block_producer_class', 'test_unit'); + + // Get the current miner state from registry + $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance(); + + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString()); + + // We can now invoke that state instance and pass our producer instance for generating some test units + $stateInstance->executeState($producerInstance); + } +} + +// [EOF] +?>