]> git.mxchange.org Git - hub.git/commitdiff
Added unfinished stuff for producing the test "genesis block".
authorRoland Haeder <roland@mxchange.org>
Mon, 31 Mar 2014 21:07:41 +0000 (23:07 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 31 Mar 2014 21:07:41 +0000 (23:07 +0200)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/config.php
application/hub/main/filter/task/miner/class_MinerTaskHandlerInitializerFilter.php
application/hub/main/producer/miner/.htaccess [new file with mode: 0644]
application/hub/main/producer/miner/blocks/.htaccess [new file with mode: 0644]
application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php [new file with mode: 0644]
application/hub/main/producer/miner/class_BaseBlockProducer.php [new file with mode: 0644]
application/hub/main/tasks/miner/.htaccess [new file with mode: 0644]
application/hub/main/tasks/miner/class_ [new file with mode: 0644]
application/hub/main/tasks/miner/class_MinerBlockFetcherTask.php [new file with mode: 0644]
application/hub/main/tasks/miner/class_MinerTestGenesisBlockProducerTask.php [new file with mode: 0644]

index c4fe119b554d1f454d67ac945695a3904f260850..8242ceff105e668665acfae3b87317c229533f9b 100644 (file)
@@ -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);
 
index 8f132efe75a0b26a692ea58731afb4aedae31cf0..3bdbdd920a7df61bb279ab0e71b3a95502b3ea95 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..44ac83e
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * A MinerTestGenesisBlock producer class
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..4ed2318
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * A general BlockProducer class
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..98281cc
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * A ??? task for miners
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..21ed537
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * A BlockFetcher task for miners which asks the network for new blocks and
+ * starts the "block chain" fetching if no block has been fetched so far.
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..8963ae3
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * A TestGenesisBlockProducer task for miners
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>