From: Roland Häder Date: Tue, 5 Apr 2011 23:33:13 +0000 (+0000) Subject: Cruncher continued and rewritten to use states: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=eedbbb80ac6f49f2d43e3ae9a18008a25cfdc16e;p=hub.git Cruncher continued and rewritten to use states: - States 'init' and 'virgin' introduced - Needed cruncher parts refactured to use the new states - Creation of node/cruncher states is now done in factories - Key producer added which will produce keys if the required state 'virgin' is beging detected. This producer works without a loop which is recommended for task-based applications - A lot other improvements - TODOs.txt updated --- diff --git a/.gitattributes b/.gitattributes index 4217c86de..c046a648d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -37,6 +37,8 @@ application/hub/interfaces/cruncher/class_CruncherHelper.php svneol=native#text/ application/hub/interfaces/discovery/.htaccess -text svneol=unset#text/plain application/hub/interfaces/discovery/class_DiscoverableRecipient.php svneol=native#text/plain application/hub/interfaces/discovery/class_DiscoverableSocket.php svneol=native#text/plain +application/hub/interfaces/executor/.htaccess svneol=native#text/plain +application/hub/interfaces/executor/class_Executor.php svneol=native#text/plain application/hub/interfaces/handler/.htaccess -text svneol=unset#text/plain application/hub/interfaces/handler/class_Handleable.php -text svneol=unset#text/plain application/hub/interfaces/handler/network/.htaccess -text svneol=unset#text/plain @@ -71,7 +73,10 @@ application/hub/interfaces/pool/listener/class_PoolableListener.php -text svneol application/hub/interfaces/pool/peer/.htaccess -text svneol=unset#text/plain application/hub/interfaces/pool/peer/class_PoolablePeer.php -text svneol=unset#text/plain application/hub/interfaces/producer/.htaccess svneol=native#text/plain +application/hub/interfaces/producer/class_ -text application/hub/interfaces/producer/class_Producer.php svneol=native#text/plain +application/hub/interfaces/producer/keys/.htaccess svneol=native#text/plain +application/hub/interfaces/producer/keys/class_KeyProducer.php svneol=native#text/plain application/hub/interfaces/producer/work_units/.htaccess svneol=native#text/plain application/hub/interfaces/producer/work_units/class_UnitProducer.php svneol=native#text/plain application/hub/interfaces/protocol/.htaccess -text svneol=unset#text/plain @@ -189,6 +194,10 @@ application/hub/main/factories/source/units/.htaccess svneol=native#text/plain application/hub/main/factories/source/units/class_UnitSourceFactory.php svneol=native#text/plain application/hub/main/factories/states/.htaccess -text svneol=unset#text/plain application/hub/main/factories/states/class_StateFactory.php -text svneol=unset#text/plain +application/hub/main/factories/states/cruncher/.htaccess svneol=native#text/plain +application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php svneol=native#text/plain +application/hub/main/factories/states/node/.htaccess svneol=native#text/plain +application/hub/main/factories/states/node/class_NodeStateFactory.php svneol=native#text/plain application/hub/main/factories/states/peer/.htaccess -text svneol=unset#text/plain application/hub/main/factories/states/peer/class_PeerStateFactory.php svneol=native#text/plain application/hub/main/factories/tags/.htaccess -text svneol=unset#text/plain @@ -384,7 +393,10 @@ application/hub/main/producer/.htaccess svneol=native#text/plain application/hub/main/producer/class_ -text application/hub/main/producer/class_BaseProducer.php svneol=native#text/plain application/hub/main/producer/cruncher/.htaccess svneol=native#text/plain +application/hub/main/producer/cruncher/class_BaseKeyProducer.php svneol=native#text/plain application/hub/main/producer/cruncher/class_BaseUnitProducer.php svneol=native#text/plain +application/hub/main/producer/cruncher/keys/.htaccess svneol=native#text/plain +application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php svneol=native#text/plain application/hub/main/producer/cruncher/work_units/.htaccess svneol=native#text/plain application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php svneol=native#text/plain application/hub/main/queries/.htaccess -text svneol=unset#text/plain @@ -421,6 +433,13 @@ application/hub/main/source/units/class_TestUnitSource.php svneol=native#text/pl application/hub/main/states/.htaccess -text svneol=unset#text/plain application/hub/main/states/class_ -text svneol=unset#text/plain application/hub/main/states/class_BaseState.php -text svneol=unset#text/plain +application/hub/main/states/cruncher/.htaccess svneol=native#text/plain +application/hub/main/states/cruncher/class_ -text +application/hub/main/states/cruncher/class_BaseCruncherState.php svneol=native#text/plain +application/hub/main/states/cruncher/init/.htaccess svneol=native#text/plain +application/hub/main/states/cruncher/init/class_CruncherInitState.php svneol=native#text/plain +application/hub/main/states/cruncher/virgin/.htaccess svneol=native#text/plain +application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php svneol=native#text/plain application/hub/main/states/generic/.htaccess -text svneol=unset#text/plain application/hub/main/states/hub/.htaccess -text svneol=unset#text/plain application/hub/main/states/hub/class_BaseHubState.php -text svneol=unset#text/plain @@ -450,6 +469,7 @@ application/hub/main/tasks/class_ -text svneol=unset#text/plain application/hub/main/tasks/class_BaseTask.php -text svneol=unset#text/plain application/hub/main/tasks/cruncher/.htaccess svneol=native#text/plain application/hub/main/tasks/cruncher/class_ -text +application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php svneol=native#text/plain application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php svneol=native#text/plain application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php svneol=native#text/plain application/hub/main/tasks/hub/.htaccess -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 471744745..de147ba7b 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -273,8 +273,11 @@ $cfg->setConfigEntry('network_package_stacker_class', 'FiFoStacker'); // CFG: CRUNCHER-BUFFER-STACKER-CLASS $cfg->setConfigEntry('cruncher_buffer_stacker_class', 'FiFoStacker'); -// CFG: PRODUCER-OUTGOING-WORK-QUEUE -$cfg->setConfigEntry('producer_outgoing_work_queue', 'FiFoStacker'); +// CFG: PRODUCER-OUTGOING-QUEUE +$cfg->setConfigEntry('producer_outgoing_queue', 'FiFoStacker'); + +// CFG: PRODUCER-INCOMING-QUEUE +$cfg->setConfigEntry('producer_incoming_queue', 'FiFoStacker'); // CFG: STACKER-ANNOUNCEMENT-MAX-SIZE $cfg->setConfigEntry('stacker_announcement_max_size', 20); @@ -300,8 +303,11 @@ $cfg->setConfigEntry('stacker_out_queue_max_size', 10000); // CFG: STACKER-OBJECT-REGISTRY-MAX-SIZE $cfg->setConfigEntry('stacker_object_registry_max_size', 100); -// CFG: STACKER-WORK-QUEUE-MAX-SIZE -$cfg->setConfigEntry('stacker_work_queue_max_size', 1000); +// CFG: STACKER-OUTGOING-QUEUE-MAX-SIZE +$cfg->setConfigEntry('stacker_outgoing_queue_max_size', 1000); + +// CFG: STACKER-INCOMING-QUEUE-MAX-SIZE +$cfg->setConfigEntry('stacker_incoming_queue_max_size', 1000); // CFG: NEWS-MAIN-LIMIT $cfg->setConfigEntry('news_main_limit', 5); @@ -405,6 +411,9 @@ $cfg->setConfigEntry('cruncher_work_unit_fetcher_task_class', 'CruncherWorkUnitF // 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-NETWORK-PACKAGE-WRITER-STARTUP-DELAY $cfg->setConfigEntry('task_network_package_writer_startup_delay', 2500); @@ -432,6 +441,15 @@ $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: TASK-CRUNCHER-KEY-PRODUCER-STARTUP-DELAY +$cfg->setConfigEntry('task_cruncher_key_producer_startup_delay', 750); + +// CFG: TASK-CRUNCHER-KEY-PRODUCER-INTERVAL-DELAY +$cfg->setConfigEntry('task_cruncher_key_producer_interval_delay', 10); + +// CFG: TASK-CRUNCHER-KEY-PRODUCER-MAX-RUNS +$cfg->setConfigEntry('task_cruncher_key_producer_max_runs', 0); + // CFG: TASK-LIST-CLASS $cfg->setConfigEntry('task_list_class', 'TaskList'); @@ -549,6 +567,9 @@ $cfg->setConfigEntry('cruncher_max_text_unit_amount', 10); // CFG: CRUNCHER-TEST-UNIT-PRODUCER-CLASS $cfg->setConfigEntry('cruncher_test_unit_producer_class', 'CruncherTestUnitProducer'); +// CFG: CRUNCHER-KEY-PRODUCER-CLASS +$cfg->setConfigEntry('cruncher_key_producer_class', 'CruncherKeyProducer'); + // CFG: CRUNCHER-TEST-UNIT-PRODUCER-TEMPLATE-CLASS $cfg->setConfigEntry('cruncher_test_unit_producer_template_class', 'XmlCruncherTestUnitTemplateEngine'); @@ -573,8 +594,8 @@ $cfg->setConfigEntry('cruncher_unit_db_wrapper_class', 'CruncherUnitDatabaseWrap // CFG: CRUNCHER-RANDOM-SECRET-MESSAGE-LENGTH $cfg->setConfigEntry('random_secret_message_length', 100); -// CFG: CRUNCHER-RANDOM-SECRET-KEY-LENGTH -$cfg->setConfigEntry('random_secret_key_length', 8); +// CFG: TEST-UNIT-RANDOM-SECRET-KEY-LENGTH +$cfg->setConfigEntry('test_unit_random_secret_key_length', 8*4); // CFG: TEST-UNIT-SOURCE-CLASS $cfg->setConfigEntry('test_unit_source_class', 'TestUnitSource'); @@ -582,5 +603,11 @@ $cfg->setConfigEntry('test_unit_source_class', 'TestUnitSource'); // CFG: CRYPTO-RANDOM-MESSAGE-HELPER-CLASS $cfg->setConfigEntry('crypto_random_message_helper_class', 'CryptoRandomUnitMessageHelper'); +// CFG: CRUNCHER-INIT-STATE-CLASS +$cfg->setConfigEntry('cruncher_init_state_class', 'CruncherInitState'); + +// CFG: CRUNCHER-VIRGIN-STATE-CLASS +$cfg->setConfigEntry('cruncher_virgin_state_class', 'CruncherVirginState'); + // [EOF] ?> diff --git a/application/hub/interfaces/executor/.htaccess b/application/hub/interfaces/executor/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/executor/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/executor/class_Executor.php b/application/hub/interfaces/executor/class_Executor.php new file mode 100644 index 000000000..18f20db60 --- /dev/null +++ b/application/hub/interfaces/executor/class_Executor.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface Executor extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/producer/class_ b/application/hub/interfaces/producer/class_ new file mode 100644 index 000000000..0a4f8adb0 --- /dev/null +++ b/application/hub/interfaces/producer/class_ @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface ???Producer extends Producer { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/producer/keys/.htaccess b/application/hub/interfaces/producer/keys/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/producer/keys/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/producer/keys/class_KeyProducer.php b/application/hub/interfaces/producer/keys/class_KeyProducer.php new file mode 100644 index 000000000..743431962 --- /dev/null +++ b/application/hub/interfaces/producer/keys/class_KeyProducer.php @@ -0,0 +1,36 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +interface KeyProducer extends Producer, Executor { + /** + * Produces some keys and pushes them onto the queue + * + * @param $stateInstance An instance of a Stateable instance + * @return void + */ + function produceKeys (Stateable $stateInstance); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/producer/work_units/class_UnitProducer.php b/application/hub/interfaces/producer/work_units/class_UnitProducer.php index 31f8bcc22..a5e1b6767 100644 --- a/application/hub/interfaces/producer/work_units/class_UnitProducer.php +++ b/application/hub/interfaces/producer/work_units/class_UnitProducer.php @@ -22,13 +22,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface UnitProducer extends Producer { +interface UnitProducer extends Producer, Executor { /** - * Produces some work/test units and pushes them onto the queue + * Prepares the produces of some work/test units and pushes them onto the queue * + * @param $stateInstance An instance of a Stateable instance * @return void */ - function produceUnits (); + function prepareUnitProduction (Stateable $stateInstance); } // [EOF] diff --git a/application/hub/interfaces/states/class_Stateable.php b/application/hub/interfaces/states/class_Stateable.php index 7347e605b..336550629 100644 --- a/application/hub/interfaces/states/class_Stateable.php +++ b/application/hub/interfaces/states/class_Stateable.php @@ -22,6 +22,13 @@ * along with this program. If not, see . */ interface Stateable extends FrameworkInterface { + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + */ + function executeState (Executor $executorInstance); } // [EOF] diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 62eb1304b..bb5df6468 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -27,6 +27,11 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $nodeInstance = null; + /** + * An instance of a cruncher + */ + private $cruncherInstance = null; + /** * Listener instance */ @@ -37,6 +42,11 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $packageInstance = null; + /** + * State instance + */ + private $stateInstance = null; + /** * Protected constructor * @@ -49,41 +59,60 @@ class BaseHubSystem extends BaseFrameworkSystem { } /** - * Setter for listener instance + * Getter for node instance * - * @param $listenerInstance A Listenable instance + * @return $nodeInstance An instance of a node node + */ + public final function getNodeInstance () { + return $this->nodeInstance; + } + + /** + * Setter for node instance + * + * @param $nodeInstance An instance of a node node * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; + protected final function setNodeInstance (NodeHelper $nodeInstance) { + $this->nodeInstance = $nodeInstance; } /** - * Getter for listener instance + * Getter for cruncher instance * - * @return $listenerInstance A Listenable instance + * @return $cruncherInstance An instance of a cruncher cruncher */ - protected final function getListenerInstance () { - return $this->listenerInstance; + public final function getCruncherInstance () { + return $this->cruncherInstance; } /** - * Setter for node instance + * Setter for cruncher instance * - * @param $nodeInstance An instance of a node node + * @param $cruncherInstance An instance of a cruncher cruncher * @return void */ - protected final function setNodeInstance (NodeHelper $nodeInstance) { - $this->nodeInstance = $nodeInstance; + protected final function setCruncherInstance (CruncherHelper $cruncherInstance) { + $this->cruncherInstance = $cruncherInstance; } /** - * Getter for node instance + * Setter for listener instance * - * @return $nodeInstance An instance of a node node + * @param $listenerInstance A Listenable instance + * @return void */ - public final function getNodeInstance () { - return $this->nodeInstance; + protected final function setListenerInstance (Listenable $listenerInstance) { + $this->listenerInstance = $listenerInstance; + } + + /** + * Getter for listener instance + * + * @return $listenerInstance A Listenable instance + */ + protected final function getListenerInstance () { + return $this->listenerInstance; } /** @@ -105,6 +134,25 @@ class BaseHubSystem extends BaseFrameworkSystem { return $this->packageInstance; } + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + public final function setStateInstance (Stateable $stateInstance) { + $this->stateInstance = $stateInstance; + } + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + public final function getStateInstance () { + return $this->stateInstance; + } + /** * Shuts down a given socket resource. This method does only ease calling * the right visitor. @@ -125,6 +173,28 @@ class BaseHubSystem extends BaseFrameworkSystem { // Call the visitor $this->accept($visitorInstance); } + + /** + * "Getter" for a printable state name + * + * @return $stateName Name of the node's state in a printable format + */ + public final function getPrintableState () { + // Default is 'null' + $stateName = 'null'; + + // Get the state instance + $stateInstance = $this->getStateInstance(); + + // Is it an instance of Stateable? + if ($stateInstance instanceof Stateable) { + // Then use that state name + $stateName = $stateInstance->getStateName(); + } // END - if + + // Return result + return $stateName; + } } // [EOF] diff --git a/application/hub/main/cruncher/class_BaseHubCruncher.php b/application/hub/main/cruncher/class_BaseHubCruncher.php index cbaa0e3ad..39471d34d 100644 --- a/application/hub/main/cruncher/class_BaseHubCruncher.php +++ b/application/hub/main/cruncher/class_BaseHubCruncher.php @@ -46,6 +46,19 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable { protected function __construct ($className) { // Call parent constructor parent::__construct($className); + + // Init this cruncher + $this->initCruncher(); + } + + /** + * Initialize the cruncher generically + * + * @return void + */ + private function initCruncher () { + // Init the state + CruncherStateFactory::createCruncherStateInstanceByName('init', $this); } /** diff --git a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php index ca4567b71..65fb3ca9e 100644 --- a/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php +++ b/application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php @@ -64,7 +64,10 @@ class HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Regis if ($this->getConfigInstance()->getConfigEntry('cruncher_test_units_enabled') == 'N') { // They are disabled, so skip any further steps return; - } // END - if + } elseif ($this->getStateInstance()->isCruncherStateVirgin()) { + // No virgin crunchers please, because they usually have no test units ready for crunching + return; + } // Get a test-unit generator instance $generatorInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_generator_class'); @@ -86,6 +89,13 @@ class HubMcryptCruncher extends BaseHubCruncher implements CruncherHelper, Regis * @return void */ protected function fillInBufferQueueWithWorkUnits () { + // This cruncher's state must not be one of these: 'virgin' + if ($this->getStateInstance()->isCruncherStateVirgin()) { + // We can silently skip here, until the generation is finished + return; + } // END - if + + // @TODO Implement this method $this->partialStub('Please implement this method.'); } diff --git a/application/hub/main/factories/states/class_StateFactory.php b/application/hub/main/factories/states/class_StateFactory.php index 66825162b..f551ef47b 100644 --- a/application/hub/main/factories/states/class_StateFactory.php +++ b/application/hub/main/factories/states/class_StateFactory.php @@ -1,59 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 StateFactory extends ObjectFactory { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of a configurable node state and sets it in the - * given node instance. - * - * @param $stateName Name of the state - * @param $nodeInstance A NodeHelper class instance - * @return $stateInstance A Stateable class instance - */ - public static final function createStateInstanceByName ($stateName, NodeHelper $nodeInstance) { - // Then construct the class' configuraton entry - $className = 'node_' . $stateName . '_state_class'; - - // Get a class from that configuration entry - $stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance)); - - // Once we have that state, set it in the node instance - $nodeInstance->setStateInstance($stateInstance); - - // For any purposes, return the state instance - return $stateInstance; - } -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/factories/states/cruncher/.htaccess b/application/hub/main/factories/states/cruncher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/states/cruncher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php b/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php new file mode 100644 index 000000000..7a326e5ab --- /dev/null +++ b/application/hub/main/factories/states/cruncher/class_CruncherStateFactory.php @@ -0,0 +1,59 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 CruncherStateFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a configurable cruncher state and sets it in the + * given cruncher instance. + * + * @param $stateName Name of the state + * @param $cruncherInstance A CruncherHelper class instance + * @return $stateInstance A Stateable class instance + */ + public static final function createCruncherStateInstanceByName ($stateName, CruncherHelper $cruncherInstance) { + // Then construct the class' configuraton entry + $className = 'cruncher_' . $stateName . '_state_class'; + + // Get a class from that configuration entry + $stateInstance = self::createObjectByConfiguredName($className, array($cruncherInstance)); + + // Once we have that state, set it in the cruncher instance + $cruncherInstance->setStateInstance($stateInstance); + + // For any purposes, return the state instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/factories/states/node/.htaccess b/application/hub/main/factories/states/node/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/states/node/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/states/node/class_NodeStateFactory.php b/application/hub/main/factories/states/node/class_NodeStateFactory.php new file mode 100644 index 000000000..d1e8f42c8 --- /dev/null +++ b/application/hub/main/factories/states/node/class_NodeStateFactory.php @@ -0,0 +1,59 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 NodeStateFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a configurable node state and sets it in the + * given node instance. + * + * @param $stateName Name of the state + * @param $nodeInstance A NodeHelper class instance + * @return $stateInstance A Stateable class instance + */ + public static final function createNodeStateInstanceByName ($stateName, NodeHelper $nodeInstance) { + // Then construct the class' configuraton entry + $className = 'node_' . $stateName . '_state_class'; + + // Get a class from that configuration entry + $stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance)); + + // Once we have that state, set it in the node instance + $nodeInstance->setStateInstance($stateInstance); + + // For any purposes, return the state instance + return $stateInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php b/application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php index 813d9d584..212257206 100644 --- a/application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php +++ b/application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php @@ -75,6 +75,14 @@ class CruncherTaskHandlerInitializerFilter extends BaseFilter implements Filtera $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_producer_task_class'); $handlerInstance->registerTask('cruncher_test_unit_producer', $taskInstance); + /* + * 3) A task for generating keys based on the generated test unit. This + * task will only be executed if the state of the cruncher is one of + * these: 'virgin'. + */ + $taskInstance = ObjectFactory::createObjectByConfiguredName('cruncher_key_producer_task_class'); + $handlerInstance->registerTask('cruncher_key_producer', $taskInstance); + // Put the task handler in registry Registry::getRegistry()->addInstance('task', $handlerInstance); } diff --git a/application/hub/main/iterator/producer/keys/class_TestUnitKeyProducerIterator.php b/application/hub/main/iterator/producer/keys/class_TestUnitKeyProducerIterator.php index 189eb0ee8..5feea77ba 100644 --- a/application/hub/main/iterator/producer/keys/class_TestUnitKeyProducerIterator.php +++ b/application/hub/main/iterator/producer/keys/class_TestUnitKeyProducerIterator.php @@ -22,6 +22,21 @@ * along with this program. If not, see . */ class TestUnitKeyProducerIterator extends BaseIterator implements Iterator { + /** + * Maximum different bit combinations + */ + private $maxBits = 0; + + /** + * Key length + */ + private $keyLength = 0; + + /** + * Current iteration + */ + private $currentIteration = 0; + /** * Protected constructor * @@ -30,6 +45,18 @@ class TestUnitKeyProducerIterator extends BaseIterator implements Iterator { protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Get key length + $this->keyLength = $this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length'); + + // Make sure the key length isn't getting to big (32 byte = 256 bit is really a lot) + assert($this->keyLength <= (8 * 32)); + + // Set max bits entry + $this->maxBits = pow(2, $this->keyLength); + + // Debug message + $this->debugOutput('ITERATOR: maxBits=' . $this->maxBits . ',keyLength=' . $this->keyLength); } /** @@ -46,15 +73,16 @@ class TestUnitKeyProducerIterator extends BaseIterator implements Iterator { } /** - * Getter for current value from group or generic + * Getter for current value * * @return $current Current value in iteration */ public function current () { - // Default is null - $current = null; + // Calculate ASCII string representation of the key number + $current = $this->dec2asc($this->currentIteration); - $this->partialStub('Please implement this method.'); + // Prepend more zeros + $current = $this->prependStringToString($current, chr(0), ($this->keyLength / 8)); // Return it return $current; @@ -76,7 +104,13 @@ class TestUnitKeyProducerIterator extends BaseIterator implements Iterator { * @return void */ public function next () { - $this->partialStub('Please implement this method.'); + /* + * This is of course a very ineffective key generation iterator because + * it will create a lot of keys that will never decode an encrypted + * message. If you know a better algorithm which is freely available and + * can be implemented as an itertator please contact me. + */ + $this->currentIteration++; } /** @@ -95,7 +129,7 @@ class TestUnitKeyProducerIterator extends BaseIterator implements Iterator { * @return void */ public function valid () { - $this->partialStub('Please implement this method.'); + return ($this->currentIteration <= $this->maxBits); } } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 0b95a0a35..9b89aee84 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -59,11 +59,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ private $hubIsAnnounced = false; - /** - * State instance - */ - private $stateInstance = null; - /** * Wether this hub is active */ @@ -91,7 +86,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { private function initState() { // Get the state factory and create the initial state, we don't need // the state instance here - StateFactory::createStateInstanceByName('init', $this); + NodeStateFactory::createNodeStateInstanceByName('init', $this); } /** @@ -134,25 +129,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { return $this->listenerPoolInstance; } - /** - * Setter for state instance - * - * @param $stateInstance Node's current state instance - * @return void - */ - public final function setStateInstance (Stateable $stateInstance) { - $this->stateInstance = $stateInstance; - } - - /** - * Getter for state instance - * - * @return $stateInstance Node's current state instance - */ - public final function getStateInstance () { - return $this->stateInstance; - } - /** * Setter for session id * @@ -222,7 +198,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { /** * "Getter" for a printable state name * - * @return $stateName Name of the node's state in a printable format + * @return $stateName Name of the node's state in a printable format */ public final function getPrintableState () { // Default is 'null' diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 920c38b66..af8cc7318 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -23,10 +23,15 @@ */ abstract class BaseProducer extends BaseFrameworkSystem { /** - * Out-going work-queue + * Outgoing work-queue */ private $outgoingQueueInstance = null; + /** + * Incoming raw data/items queue + */ + private $incomingQueueInstance = null; + /** * Protected constructor * @@ -45,9 +50,18 @@ abstract class BaseProducer extends BaseFrameworkSystem { } /** - * Setter for out-going work queue + * Getter for outgoing work queue * - * @param $outgoingQueueInstance The out-going work queue instance + * @param $outgoingQueueInstance The outgoing work queue instance + */ + protected final function getOutgoingQueueInstance () { + return $this->outgoingQueueInstance; + } + + /** + * Setter for outgoing work queue + * + * @param $outgoingQueueInstance The outgoing work queue instance * @return void */ private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { @@ -55,12 +69,22 @@ abstract class BaseProducer extends BaseFrameworkSystem { } /** - * Getter for out-going work queue + * Getter for incoming raw data/items queue * - * @param $outgoingQueueInstance The out-going work queue instance + * @param $incomingQueueInstance The incoming raw data/items queue instance */ - protected final function getOutgoingQueueInstance () { - return $this->outgoingQueueInstance; + protected final function getIncomingQueueInstance () { + return $this->incomingQueueInstance; + } + + /** + * Setter for incoming raw data/items queue + * + * @param $incomingQueueInstance The incoming raw data/items queue instance + * @return void + */ + private final function setIncomingQueueInstance (Stackable $incomingQueueInstance) { + $this->incomingQueueInstance = $incomingQueueInstance; } /** @@ -71,20 +95,26 @@ abstract class BaseProducer extends BaseFrameworkSystem { abstract protected function initProducer(); /** - * Initializes the work queue which is being used for out-going, produced + * Initializes the work queue which is being used for outgoing, produced * items. * * @return void */ protected function initWorkQueue () { // Get an instance and set it in this producer - $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_work_queue')); + $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_outgoing_queue')); + + // Init the queue + $this->getOutgoingQueueInstance()->initStacker('outgoing_queue'); + + // Get an instance and set it in this producer + $this->setOutgoingQueueInstance(ObjectFactory::createObjectByConfiguredName('producer_incoming_queue')); // Init the queue - $this->getOutgoingQueueInstance()->initStacker('work_queue'); + $this->getOutgoingQueueInstance()->initStacker('incoming_queue'); // Debug message - $this->debugOutput('PRODUCER: Out-going work queue initialized.'); + $this->debugOutput('PRODUCER: All queues have been initialized.'); } } diff --git a/application/hub/main/producer/cruncher/class_BaseKeyProducer.php b/application/hub/main/producer/cruncher/class_BaseKeyProducer.php new file mode 100644 index 000000000..bd3fcc2a6 --- /dev/null +++ b/application/hub/main/producer/cruncher/class_BaseKeyProducer.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 . + */ +abstract class BaseKeyProducer extends BaseProducer { + /** + * 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/producer/cruncher/class_BaseUnitProducer.php b/application/hub/main/producer/cruncher/class_BaseUnitProducer.php index 328334fa1..6c1c4bc20 100644 --- a/application/hub/main/producer/cruncher/class_BaseUnitProducer.php +++ b/application/hub/main/producer/cruncher/class_BaseUnitProducer.php @@ -1,6 +1,6 @@ * @version 0.0.0 diff --git a/application/hub/main/producer/cruncher/keys/.htaccess b/application/hub/main/producer/cruncher/keys/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/producer/cruncher/keys/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php new file mode 100644 index 000000000..3b14f8e44 --- /dev/null +++ b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php @@ -0,0 +1,108 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, 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 createCruncherKeyProducer () { + // Get new instance + $producerInstance = new CruncherKeyProducer(); + + // Get a helper instance, we now only need this for the key iterator + $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test')); + + // Next get an iterator, again the helper will do that for us + $iteratorInstance = $helperInstance->getKeyIterator(); + + // Set it in the producer + $producerInstance->setIteratorInstance($iteratorInstance); + + // Return the prepared instance + return $producerInstance; + } + + /** + * Initializes the producer. This method satisfies the abstract BaseProducer + * class. + * + * @return void + * @todo Find something for init phase of this key producer + */ + protected function initProducer () { + } + + /** + * Produces some keys and pushes them onto the queue + * + * @param $stateInstance An instance of a Stateable instance + * @return void + * @todo ~30% done + */ + public function produceKeys (Stateable $stateInstance) { + // Is this cruncher virgin? + if (!$stateInstance->isCruncherStateVirgin()) { + // This cruncher is not virgin, so skip it + $this->debugOutput('ITERATOR: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . '.'); + return; + } elseif (!$this->getIteratorInstance()->valid()) { + // This iterator has finished his assignment + $this->debugOutput('ITERATOR: Finished creating keys.'); + return; + } + + /* + * Now we need to create an iterator, just as for the work units, + * to create new keys from the encrypted message. The iterator will + * not iterate over an object nor a collection. It will instead + * encapsulate the "key production" into a class and not in a simple + * for() loop. These keys then needs to be bundled into test units + * and stored to database for later re-usage. + */ + + // Get current key (which is not the key of the iterator) + // This is always an ASCII string. + $currentKey = $this->getIteratorInstance()->current(); + + // @TODO Do something with it + $this->debugOutput('currentKey(b64)="' . base64_encode($currentKey) . '" needs to be processed.'); + + // Continue with next one + $this->getIteratorInstance()->next(); + } +} + +// [EOF] +?> diff --git a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php index 673e9d037..4c88ff6f4 100644 --- a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php +++ b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -72,12 +72,13 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, } /** - * Produces some test units and pushes them onto the queue + * Prepares the produces of some test units and pushes them onto the queue * + * @param $stateInstance An instance of a Stateable instance * @return void - * @todo ~30% done + * @todo ~60% done */ - public function produceUnits () { + public function prepareUnitProduction (Stateable $stateInstance) { // First get a database wrapper because we want to permanently store test units $wrapperInstance = ObjectFactory::createObjectByConfiguredName('cruncher_unit_db_wrapper_class'); @@ -97,6 +98,9 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, // Entries found // @TODO Unfinished work here $this->debugInstance(); + + // The state must be changed because ... + $stateInstance->someFooStateChange(); } else { // Get an encrypted, random message from our source $encryptedMessage = $this->getHelperInstance()->generateRandomMessage(); @@ -107,31 +111,8 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, // Set the encrypted message in the template instance $this->getTemplateInstance()->assignVariable('encrypted_message', $encryptedMessage); - /* - * Now we need to create an iterator, just as for the work units, - * to create new keys from the encrypted message. The iterator will - * not iterate over an object nor a collection. It will instead - * encapsulate the "key production" into a class and not in a simple - * for() loop. These keys then needs to be bundled into test units - * and stored to database for later re-usage. - */ - - // First get an iterator, again the helper will do that for us - $iteratorInstance = $this->getHelperInstance()->getKeyIterator(); - - // Begin the "key production" - while ($iteratorInstance->valid()) { - // Get current key (which is not the key of the iterator) - $currentKey = $iteratorInstance->current(); - - // @TODO Do something with it - $this->debugOutput('currentKey=' . $currentKey . ' needs to be processed.'); - - // Continue with next one - $iteratorInstance->next(); - } // END - while - - die(__METHOD__ . ": Ended the key production.\n"); + // The state must be changed because we have a new message + $stateInstance->encryptedMessageGenerated(); } } } diff --git a/application/hub/main/source/units/class_TestUnitSource.php b/application/hub/main/source/units/class_TestUnitSource.php index 804b06c2e..0de4ac22b 100644 --- a/application/hub/main/source/units/class_TestUnitSource.php +++ b/application/hub/main/source/units/class_TestUnitSource.php @@ -63,7 +63,7 @@ class TestUnitSource extends BaseSource implements Sourceable { $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length'))); // Get a random, secret key - $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_key_length')); + $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('test_unit_random_secret_key_length') / 8); // Now encrypt the message with our key and a good (strong) cipher $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey)); diff --git a/application/hub/main/states/class_BaseState.php b/application/hub/main/states/class_BaseState.php index bdb26830b..3f4f17e43 100644 --- a/application/hub/main/states/class_BaseState.php +++ b/application/hub/main/states/class_BaseState.php @@ -60,6 +60,17 @@ class BaseState extends BaseHubSystem implements Stateable { protected final function setStateName ($stateName) { $this->stateName = $stateName; } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + * @throws UnsupportedOperationException This method should be overwritten + */ + public function executeState (Executor $executorInstance) { + throw new UnsupportedOperationException(array($this, __FUNCTION__, $executorInstance), self::EXCEPTION_UNSPPORTED_OPERATION); + } } // [EOF] diff --git a/application/hub/main/states/cruncher/.htaccess b/application/hub/main/states/cruncher/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/cruncher/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/cruncher/class_ b/application/hub/main/states/cruncher/class_ new file mode 100644 index 000000000..b3925cba0 --- /dev/null +++ b/application/hub/main/states/cruncher/class_ @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 Cruncher???State extends BaseCruncherState 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 $cruncherInstance An instance of a CruncherHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createCruncher???State (CruncherHelper $cruncherInstance) { + // Get new instance + $stateInstance = new Cruncher???State(); + + // Debug message + $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the cruncher instance + $stateInstance->setCruncherInstance($cruncherInstance); + + // 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/cruncher/class_BaseCruncherState.php b/application/hub/main/states/cruncher/class_BaseCruncherState.php new file mode 100644 index 000000000..c65ef1a6f --- /dev/null +++ b/application/hub/main/states/cruncher/class_BaseCruncherState.php @@ -0,0 +1,63 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 BaseCruncherState extends BaseState { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Validates wether 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 validateCruncherStateIsActive () { + // Just compare it... + if (!$this instanceof CruncherActiveState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } + + /** + * Checks if this state is 'virgin' + * + * @return $isVirgin Wether this state is 'virgin' + */ + public function isCruncherStateVirgin () { + // Just compare it... + return ($this instanceof CruncherVirginState); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/cruncher/init/.htaccess b/application/hub/main/states/cruncher/init/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/cruncher/init/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/cruncher/init/class_CruncherInitState.php b/application/hub/main/states/cruncher/init/class_CruncherInitState.php new file mode 100644 index 000000000..1caf37c58 --- /dev/null +++ b/application/hub/main/states/cruncher/init/class_CruncherInitState.php @@ -0,0 +1,82 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 CruncherInitState extends BaseCruncherState 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 $cruncherInstance An instance of a CruncherHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createCruncherInitState (CruncherHelper $cruncherInstance) { + // Get new instance + $stateInstance = new CruncherInitState(); + + // Debug message + $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the cruncher instance + $stateInstance->setCruncherInstance($cruncherInstance); + + // 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' + CruncherStateFactory::createCruncherStateInstanceByName('virgin', $this->getCruncherInstance()); + } +} + +// [EOF] +?> diff --git a/application/hub/main/states/cruncher/virgin/.htaccess b/application/hub/main/states/cruncher/virgin/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/cruncher/virgin/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php b/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php new file mode 100644 index 000000000..6f567f4af --- /dev/null +++ b/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php @@ -0,0 +1,71 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 CruncherVirginState extends BaseCruncherState 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 $cruncherInstance An instance of a CruncherHelper class + * @return $stateInstance An instance of a Stateable class + */ + public final static function createCruncherVirginState (CruncherHelper $cruncherInstance) { + // Get new instance + $stateInstance = new CruncherVirginState(); + + // Debug message + $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.'); + + // Set the cruncher instance + $stateInstance->setCruncherInstance($cruncherInstance); + + // 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] +?> diff --git a/application/hub/main/states/node/active/class_NodeActiveState.php b/application/hub/main/states/node/active/class_NodeActiveState.php index 516eed987..9822dfaa8 100644 --- a/application/hub/main/states/node/active/class_NodeActiveState.php +++ b/application/hub/main/states/node/active/class_NodeActiveState.php @@ -65,7 +65,7 @@ class NodeActiveState extends BaseNodeState implements Stateable { */ public function nodeAnnouncedToUpperHubs () { // Create the new state instance - StateFactory::createStateInstanceByName('announced', $this->getNodeInstance()); + NodeStateFactory::createNodeStateInstanceByName('announced', $this->getNodeInstance()); } } diff --git a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php index 263ad0dc1..30b080f92 100644 --- a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php +++ b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class NodeAnnouncedState extends BaseState implements Stateable { +class NodeAnnouncedState extends BaseNodeState implements Stateable { /** * Protected constructor * diff --git a/application/hub/main/states/node/class_ b/application/hub/main/states/node/class_ index 6b6491d01..efc807d39 100644 --- a/application/hub/main/states/node/class_ +++ b/application/hub/main/states/node/class_ @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class Node???State extends BaseState implements Stateable { +class Node???State extends BaseNodeState implements Stateable { /** * Protected constructor * diff --git a/application/hub/main/states/node/init/class_NodeInitState.php b/application/hub/main/states/node/init/class_NodeInitState.php index 3312c34e9..473204dce 100644 --- a/application/hub/main/states/node/init/class_NodeInitState.php +++ b/application/hub/main/states/node/init/class_NodeInitState.php @@ -60,10 +60,11 @@ class NodeInitState extends BaseNodeState implements Stateable { * nodes with current state 'init' now 'virgin'. * * @return void + * @todo We might want to move some calls to this method to fill it with life */ public function nodeGeneratedSessionId () { // Create the new state instance - StateFactory::createStateInstanceByName('virgin', $this->getNodeInstance()); + NodeStateFactory::createNodeStateInstanceByName('virgin', $this->getNodeInstance()); } } diff --git a/application/hub/main/states/node/virgin/class_NodeVirginState.php b/application/hub/main/states/node/virgin/class_NodeVirginState.php index e3e8425ce..61e239555 100644 --- a/application/hub/main/states/node/virgin/class_NodeVirginState.php +++ b/application/hub/main/states/node/virgin/class_NodeVirginState.php @@ -65,7 +65,7 @@ class NodeVirginState extends BaseNodeState implements Stateable { */ public function nodeIsActivated () { // Create the new state instance - StateFactory::createStateInstanceByName('active', $this->getNodeInstance()); + NodeStateFactory::createNodeStateInstanceByName('active', $this->getNodeInstance()); } } diff --git a/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php b/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php new file mode 100644 index 000000000..7e1c4a2d8 --- /dev/null +++ b/application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php @@ -0,0 +1,90 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 CruncherKeyProducerTask 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 createCruncherKeyProducerTask () { + // Get new instance + $taskInstance = new CruncherKeyProducerTask(); + + // Return the prepared instance + return $taskInstance; + } + + /** + * Accepts the visitor to process the visit "request" + * + * @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 () { + // First we check if we already have an instance (which will happen at any later cyclus) + if (!Registry::getRegistry()->instanceExists('key_producer')) { + // No instance found, so we need to create a producer instance + $producerInstance = ObjectFactory::createObjectByConfiguredName('cruncher_key_producer_class'); + + // ... and add it to the registry + Registry::getRegistry()->addInstance('key_producer', $producerInstance); + } else { + // Get the producer instance from registry + $producerInstance = Registry::getRegistry()->getInstance('key_producer'); + } + + // Get the current cruncher state from registry + $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance(); + + // Debug message + //* DEBUG: */ $this->debugOutput('TASK: 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/cruncher/class_CruncherTestUnitProducerTask.php b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php index acaa55798..5b62110b9 100644 --- a/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php +++ b/application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php @@ -61,7 +61,6 @@ class CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitab * Executes the task * * @return void - * @todo 0% */ public function executeTask () { // First we check if we already have an instance (which will happen at any later cyclus) @@ -76,8 +75,14 @@ class CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitab $producerInstance = Registry::getRegistry()->getInstance('test_unit_producer'); } - // We can now use that producer instance for generating some test units - $producerInstance->produceUnits(); + // Get the current cruncher state from registry + $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance(); + + // Debug message + //* DEBUG: */ $this->debugOutput('TASK: Executing stateInstance=' . $stateInstance->__toString()); + + // We can now invoke that state instance and pass our producer instance for generating some test units + $stateInstance->executeState($producerInstance); } } diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 58dfcd9b6..14eb7f90c 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -9,9 +9,10 @@ ./application/hub/main/connectors/query/local/class_LocalQueryConnector.php:10: * @todo Find an interface for: handleAllQueries() ./application/hub/main/connectors/query/local/class_LocalQueryConnector.php:78: * @TODO 0% done: Unfinished work here ./application/hub/main/connectors/queues/local/class_LocalQueueConnector.php:58: * @TODO 0% done: Unfinished work here -./application/hub/main/cruncher/class_BaseHubCruncher.php:175: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem -./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:128: * @todo 0% done -./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:98: * @todo Implement this method +./application/hub/main/cruncher/class_BaseHubCruncher.php:188: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem +./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:108: * @todo Implement this method +./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:138: * @todo 0% done +./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:98: // @TODO Implement this method ./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102: // @TODO We may need some locking here ./application/hub/main/factories/socket/class_SocketFactory.php:10: * @todo Find an interface for hub helper ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapBufferQueueInitializerFilter.php:54: * @todo 0% done @@ -51,9 +52,9 @@ ./application/hub/main/nodes/boot/class_HubBootNode.php:119: // @TODO Add some filters here ./application/hub/main/nodes/boot/class_HubBootNode.php:58: * @todo add some more special bootstrap things for this boot node ./application/hub/main/nodes/boot/class_HubBootNode.php:99: * @todo Unfinished method -./application/hub/main/nodes/class_BaseHubNode.php:452: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem -./application/hub/main/nodes/class_BaseHubNode.php:492: * @todo Change the first if() block to check for a specific state -./application/hub/main/nodes/class_BaseHubNode.php:667: // @TODO Add some criteria, e.g. if the node is active or so +./application/hub/main/nodes/class_BaseHubNode.php:428: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem +./application/hub/main/nodes/class_BaseHubNode.php:468: * @todo Change the first if() block to check for a specific state +./application/hub/main/nodes/class_BaseHubNode.php:643: // @TODO Add some criteria, e.g. if the node is active or so ./application/hub/main/nodes/list/class_HubListNode.php:58: * @todo Implement more bootstrap steps ./application/hub/main/nodes/list/class_HubListNode.php:68: * @todo Unfinished method ./application/hub/main/nodes/list/class_HubListNode.php:91: // @TODO Add some filters here @@ -70,13 +71,16 @@ ./application/hub/main/package/class_NetworkPackage.php:383: // @TODO Add some logging here ./application/hub/main/package/class_NetworkPackage.php:409: // @TODO Add some logging here ./application/hub/main/pools/peer/class_DefaultPeerPool.php:148: // @TODO Check for IP -./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:127: // @TODO Do something with it -./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:78: * @todo ~30% done -./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:98: // @TODO Unfinished work here +./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:62: * @todo Find something for init phase of this key producer +./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:72: * @todo ~30% done +./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:99: // @TODO Do something with it +./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:79: * @todo ~60% done +./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:99: // @TODO Unfinished work here ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:68: * @todo ~30% done ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:80: // @TODO On some systems it is 134, on some 107? +./application/hub/main/states/node/init/class_NodeInitState.php:63: * @todo We might want to move some calls to this method to fill it with life +./application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php:53: * @todo Maybe visit some sub-objects ./application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php:53: * @todo Maybe visit some sub-objects -./application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php:64: * @todo 0% ./application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php:54: * @todo Maybe visit some sub-objects ./application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php:53: * @todo 0% ./application/hub/main/tasks/hub/class_HubSelfConnectTask.php:53: * @todo 0% @@ -98,10 +102,10 @@ ./inc/classes/exceptions/main/class_MissingMethodException.php:13: * @todo Try to rewrite user/guest login classes and mark this exception as deprecated ./inc/classes/exceptions/main/class_NoConfigEntryException.php:10: * @todo Rename this class to NoFoundEntryException ./inc/classes/interfaces/class_FrameworkInterface.php:11: * @todo Find a better name for this interface -./inc/classes/main/class_BaseFrameworkSystem.php:1197: * @todo Write a logging mechanism for productive mode -./inc/classes/main/class_BaseFrameworkSystem.php:1211: // @TODO Finish this part! +./inc/classes/main/class_BaseFrameworkSystem.php:1237: * @todo Write a logging mechanism for productive mode +./inc/classes/main/class_BaseFrameworkSystem.php:1251: // @TODO Finish this part! ./inc/classes/main/class_BaseFrameworkSystem.php:169: // @todo Try to clean these constants up -./inc/classes/main/class_BaseFrameworkSystem.php:368: * @todo SearchableResult and UpdateableResult shall have a super interface to use here +./inc/classes/main/class_BaseFrameworkSystem.php:408: * @todo SearchableResult and UpdateableResult shall have a super interface to use here ./inc/classes/main/commands/web/class_WebLoginAreaCommand.php:64: * @todo Add some stuff here: Some personal data, app/game related data ./inc/classes/main/commands/web/class_WebProblemCommand.php:58: * @todo 0% done ./inc/classes/main/commands/web/class_WebStatusCommand.php:58: * @todo 0% done @@ -167,7 +171,7 @@ ./inc/classes/main/response/image/class_ImageResponse.php:91: * @todo this will send only one cookie out, the first one. ./inc/classes/main/result/class_DatabaseResult.php:226: * @todo 0% done ./inc/classes/main/result/class_DatabaseResult.php:379:4 * @todo Find a caching way without modifying the result array -./inc/classes/main/rng/class_RandomNumberGenerator.php:152: * @todo I had a better random number generator here but now it is somewhere lost :( +./inc/classes/main/rng/class_RandomNumberGenerator.php:161: * @todo I had a better random number generator here but now it is somewhere lost :( ./inc/classes/main/rng/class_RandomNumberGenerator.php:83: * @todo Add site key for stronger salt! ./inc/classes/main/template/class_BaseTemplateEngine.php:1055: // @TODO This silent abort should be logged, maybe. ./inc/classes/main/template/class_BaseTemplateEngine.php:1063: // @TODO Old behaviour, will become obsolete! @@ -206,6 +210,7 @@ ./application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED +./application/hub/main/factories/states/class_StateFactory.php:2:// @DEPRECATED ./application/hub/main/filter/activation/class_HubActivationSelfAnnouncementFilter.php:2:// @DEPRECATED ./application/hub/main/filter/bootstrap/class_HubBootstrapAquireHubIdFilter.php:2:// @DEPRECATED ./application/hub/main/filter/bootstrap/class_HubBootstrapExtraBootstrappingFilter.php:2:// @DEPRECATED @@ -238,6 +243,7 @@ ./inc/classes/exceptions/language/class_MissingLanguageHandlerException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ClassNotFoundException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php:2:// @DEPRECATED +./inc/classes/exceptions/main/class_MissingMethodException.php:14: * @deprecated Please do no longer use this exception ./inc/classes/interfaces/helper/class_HelpableLogin.php:2:// @DEPRECATED ./inc/classes/interfaces/helper/class_HelpableTemplate.php:2:// @DEPRECATED ./inc/classes.php:9: * @deprecated