3 * A CruncherKey producer class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Registerable {
26 * Protected constructor
30 protected function __construct () {
31 // Call parent constructor
32 parent::__construct(__CLASS__);
36 * Creates an instance of this class
38 * @return $producerInstance An instance of a Producer class
40 public final static function createCruncherKeyProducer () {
42 $producerInstance = new CruncherKeyProducer();
44 // Get a helper instance, we now only need this for the key iterator
45 $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test'));
47 // Next get an iterator, again the helper will do that for us
48 $iteratorInstance = $helperInstance->getKeyIterator();
50 // Set it in the producer
51 $producerInstance->setIteratorInstance($iteratorInstance);
53 // Return the prepared instance
54 return $producerInstance;
58 * Initializes the producer. This method satisfies the abstract BaseProducer
62 * @todo Find something for init phase of this key producer
64 protected function initProducer () {
68 * Produces some keys and pushes them onto the queue
70 * @param $stateInstance An instance of a Stateable instance
74 public function produceKeys (Stateable $stateInstance) {
75 // Is this cruncher virgin?
76 if (!$stateInstance->isCruncherStateVirgin()) {
77 // This cruncher is not virgin, so skip it
78 $this->debugOutput('PRODUCER: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . '');
80 } elseif (!$this->getIteratorInstance()->valid()) {
81 // This producer's iterator has finished its assignment
82 $this->debugOutput('PRODUCER: Finished creating keys. iteratorinstance=' . $this->getIteratorInstance()->__toString() . '');
87 * Now we need to create an iterator, just as for the work units,
88 * to create new keys from the encrypted message. The iterator will
89 * not iterate over an object nor a collection. It will instead
90 * encapsulate the "key production" into a class and not in a simple
91 * for() loop. These keys then needs to be bundled into test units
92 * and stored to database for later re-usage.
96 * Get current key (which is not the key of the iterator) This is always
99 $currentKey = $this->getIteratorInstance()->current();
101 // Add it to the out-going work queue
102 $this->addValueToOutgoingQueue($currentKey);
104 // Is the per-work unit limit reached?
105 if ($this->isOutgoingQueueLimitReached('cruncher_per_unit_key_limit')) {
106 // @TODO Do something with it
107 $this->debugOutput('currentKey(b64)="' . base64_encode($currentKey) . '" needs to be processed.');
109 // At last re-init the stack
110 $this->initOutgoingQueue();
113 // Continue with next one
114 $this->getIteratorInstance()->next();