From 716e597e5d42c271fee57dbe589816e3d7f65dc3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 12 May 2014 21:20:50 +0200 Subject: [PATCH] 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 --- .../hub/main/communicator/miner/.htaccess | 1 + .../miner/class_MinerNodeCommunicator.php | 50 ++++++++++++ ...lass_MinerTaskHandlerInitializerFilter.php | 8 ++ .../main/tasks/miner/block_fetcher/.htaccess | 1 + .../class_MinerBlockFetcherTask.php | 0 .../main/tasks/miner/block_producer/.htaccess | 1 + ...lass_MinerTestGenesisBlockProducerTask.php | 0 .../main/tasks/miner/{class_ => class_Miner} | 0 .../main/tasks/miner/communicator/.htaccess | 1 + .../class_MinerNodeCommunicatorTask.php | 81 +++++++++++++++++++ 10 files changed, 143 insertions(+) create mode 100644 application/hub/main/communicator/miner/.htaccess create mode 100644 application/hub/main/communicator/miner/class_MinerNodeCommunicator.php create mode 100644 application/hub/main/tasks/miner/block_fetcher/.htaccess rename application/hub/main/tasks/miner/{ => block_fetcher}/class_MinerBlockFetcherTask.php (100%) create mode 100644 application/hub/main/tasks/miner/block_producer/.htaccess rename application/hub/main/tasks/miner/{ => block_producer}/class_MinerTestGenesisBlockProducerTask.php (100%) rename application/hub/main/tasks/miner/{class_ => class_Miner} (100%) create mode 100644 application/hub/main/tasks/miner/communicator/.htaccess create mode 100644 application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php 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/class_MinerBlockFetcherTask.php b/application/hub/main/tasks/miner/block_fetcher/class_MinerBlockFetcherTask.php similarity index 100% rename from application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php rename to application/hub/main/tasks/miner/block_fetcher/class_MinerBlockFetcherTask.php 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/class_MinerTestGenesisBlockProducerTask.php b/application/hub/main/tasks/miner/block_producer/class_MinerTestGenesisBlockProducerTask.php similarity index 100% rename from application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php rename to application/hub/main/tasks/miner/block_producer/class_MinerTestGenesisBlockProducerTask.php diff --git a/application/hub/main/tasks/miner/class_ b/application/hub/main/tasks/miner/class_Miner similarity index 100% rename from application/hub/main/tasks/miner/class_ rename to application/hub/main/tasks/miner/class_Miner 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] +?> -- 2.39.5