From: Roland Haeder Date: Mon, 12 May 2014 19:20:50 +0000 (+0200) Subject: Added/renamed miner classes: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=716e597e5d42c271fee57dbe589816e3d7f65dc3;p=hub.git Added/renamed miner classes: - Added communicator class for miner->node communication. This allows the miner to claim found blocks and ask the network for more. - Moved some miner tasks in sub directories Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/communicator/miner/.htaccess b/application/hub/main/communicator/miner/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/communicator/miner/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/communicator/miner/class_MinerNodeCommunicator.php b/application/hub/main/communicator/miner/class_MinerNodeCommunicator.php new file mode 100644 index 000000000..5ffb67c4c --- /dev/null +++ b/application/hub/main/communicator/miner/class_MinerNodeCommunicator.php @@ -0,0 +1,50 @@ +node communicator class + * + * @author Roland Haeder + * @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 MinerNodeCommunicator extends BaseCommunicator implements Communicator, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $communicatorInstance An instance of a Communicator class + */ + public final static function createMinerNodeCommunicator () { + // Get new instance + $communicatorInstance = new MinerNodeCommunicator(); + + // Return the prepared instance + return $communicatorInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php index f8eb6deb4..fefaf3c1e 100644 --- a/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php @@ -75,6 +75,14 @@ class MinerTaskHandlerInitializerFilter extends BaseMinerFilter implements Filte $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_test_genesis_block_producer_task_class'); $handlerInstance->registerTask('miner_test_genesis_block_producer', $taskInstance); + /* + * 3) A task for communicating into the locally running 'hub' node. + * This rask will check for new blocks on the mining network and + * tries to claim found blocks. + */ + $taskInstance = ObjectFactory::createObjectByConfiguredName('miner_node_communicator_task_class'); + $handlerInstance->registerTask('miner_node_communicator', $taskInstance); + // Put the task handler in registry Registry::getRegistry()->addInstance('task_handler', $handlerInstance); } diff --git a/application/hub/main/tasks/miner/block_fetcher/.htaccess b/application/hub/main/tasks/miner/block_fetcher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/miner/block_fetcher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/miner/block_fetcher/class_MinerBlockFetcherTask.php b/application/hub/main/tasks/miner/block_fetcher/class_MinerBlockFetcherTask.php new file mode 100644 index 000000000..21ed5370f --- /dev/null +++ b/application/hub/main/tasks/miner/block_fetcher/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/block_producer/.htaccess b/application/hub/main/tasks/miner/block_producer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/miner/block_producer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/miner/block_producer/class_MinerTestGenesisBlockProducerTask.php b/application/hub/main/tasks/miner/block_producer/class_MinerTestGenesisBlockProducerTask.php new file mode 100644 index 000000000..8963ae3e2 --- /dev/null +++ b/application/hub/main/tasks/miner/block_producer/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] +?> diff --git a/application/hub/main/tasks/miner/class_ b/application/hub/main/tasks/miner/class_ deleted file mode 100644 index 98281cc40..000000000 --- a/application/hub/main/tasks/miner/class_ +++ /dev/null @@ -1,72 +0,0 @@ - - * @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_Miner b/application/hub/main/tasks/miner/class_Miner new file mode 100644 index 000000000..98281cc40 --- /dev/null +++ b/application/hub/main/tasks/miner/class_Miner @@ -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 deleted file mode 100644 index 21ed5370f..000000000 --- a/application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php +++ /dev/null @@ -1,80 +0,0 @@ - - * @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 deleted file mode 100644 index 8963ae3e2..000000000 --- a/application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php +++ /dev/null @@ -1,80 +0,0 @@ - - * @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] -?> diff --git a/application/hub/main/tasks/miner/communicator/.htaccess b/application/hub/main/tasks/miner/communicator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/tasks/miner/communicator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php b/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php new file mode 100644 index 000000000..1ab70861a --- /dev/null +++ b/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php @@ -0,0 +1,81 @@ + + * @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 MinerNodeCommunicatorTask 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 createMinerNodeCommunicatorTask () { + // Get new instance + $taskInstance = new MinerNodeCommunicatorTask(); + + // 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 + */ + public function executeTask () { + // Get the communicator instance + $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('miner_node_communicator_class', 'node'); + + // 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 communicator instance for generating some test units + $stateInstance->executeState($communicatorInstance); + } +} + +// [EOF] +?>