* @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 . */ 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 () { } /** * Initializes the executor, whatever it does. * * @return void * @todo 0% done */ public function initExecutor (Stateable $stateInstance) { $this->partialStub('Maybe implement this method?'); } /** * 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 self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: The cruncher is not virgin. stateInstance=' . $stateInstance->__toString() . ''); return; } elseif (!$this->getIteratorInstance()->valid()) { // This producer's iterator has finished its assignment self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorInstance=' . $this->getIteratorInstance()->__toString() . ''); 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(); // Add it to the out-going work queue $this->addValueToOutgoingQueue($currentKey); // Is the per-work unit limit reached? if ($this->isOutgoingQueueLimitReached('cruncher_per_unit_key_limit')) { // @TODO Send the produced key bundle to the unit producer's input queue self::createDebugInstance(__CLASS__)->debugOutput('currentKey(b64)="' . base64_encode($currentKey) . '" needs to be processed.'); // At last re-init the stack $this->initOutgoingQueue(); } // END - if // Continue with next one $this->getIteratorInstance()->next(); } } // [EOF] ?>