From: Roland Haeder Date: Tue, 22 Jul 2014 18:54:28 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=48e83cb812bffbcb9c5f86d97aca5a2b5d0b275b;p=hub.git Continued: - fixed bad handlig in NodeDistributedHashTableDatabaseWrapper - improved other stuff (communicator, ...) - used new 'core' (only chash.php) Signed-off-by: Roland Haeder --- diff --git a/application/hub/main/communicator/class_BaseCommunicator.php b/application/hub/main/communicator/class_BaseCommunicator.php index 1fda37328..0d544714f 100644 --- a/application/hub/main/communicator/class_BaseCommunicator.php +++ b/application/hub/main/communicator/class_BaseCommunicator.php @@ -37,7 +37,7 @@ class BaseCommunicator extends BaseHubSystem { } /** - * Initializes the node's state which sets it to 'init' + * Initializes the communicator's state which sets it to 'init' * * @return void */ diff --git a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php index e0329ac3a..8d5aedce0 100644 --- a/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php +++ b/application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php @@ -56,7 +56,7 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr * class. * * @return void - * @todo 0% done + * @todo ~10% done */ protected function initProducer () { $this->partialStub('Please implement this method.'); @@ -83,10 +83,17 @@ class MinerTestGenesisBlockProducer extends BaseBlockProducer implements BlockPr * * @param $stateInstance An instance of a Stateable instance * @return void - * @todo 0% done + * @todo ~5% done */ public function prepareBlockProduction (Stateable $stateInstance) { - $this->partialStub('Please implement this method, stateInstance=' . $stateInstance->__toString()); + // The state must be 'booting' + $stateInstance->validateMinerStateIsBooting(); + + /* + * Now that the miner is booting a genesis block for testing purposes + * can be created. The "real" genesis block will be created differently + * to this. + */ } } diff --git a/application/hub/main/states/communicator/init/class_CommunicatorInitState.php b/application/hub/main/states/communicator/init/class_CommunicatorInitState.php index 86f745553..d0c89c0ca 100644 --- a/application/hub/main/states/communicator/init/class_CommunicatorInitState.php +++ b/application/hub/main/states/communicator/init/class_CommunicatorInitState.php @@ -51,6 +51,16 @@ class CommunicatorInitState extends BaseCommunicatorState implements Stateable { // Return the prepared instance return $stateInstance; } + + /** + * Executes the state with given Executor instance + * + * @param $executorInstance An instance of a Executor class + * @return void + * @todo 0% done? + */ + public function executeState (Executor $executorInstance) { + } } // [EOF] diff --git a/application/hub/main/states/miner/booting/class_MinerBootingState.php b/application/hub/main/states/miner/booting/class_MinerBootingState.php index 4c3ddd8c0..5a29b1539 100644 --- a/application/hub/main/states/miner/booting/class_MinerBootingState.php +++ b/application/hub/main/states/miner/booting/class_MinerBootingState.php @@ -62,6 +62,9 @@ class MinerBootingState extends BaseMinerState implements Stateable { * @return void */ public function executeState (Executor $executorInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Calling prepareBlockProduction() on ' . $executorInstance->__toString() . ' ...'); + // Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there $executorInstance->prepareBlockProduction($this); } diff --git a/application/hub/main/states/miner/class_BaseMinerState.php b/application/hub/main/states/miner/class_BaseMinerState.php index 891a7221d..0208d7a2c 100644 --- a/application/hub/main/states/miner/class_BaseMinerState.php +++ b/application/hub/main/states/miner/class_BaseMinerState.php @@ -63,6 +63,21 @@ class BaseMinerState extends BaseState { } // END - if } + /** + * Validates whether the state is 'booting' or throws an exception if + * it is every other state. + * + * @return void + * @throws InvalidStateException If the state is not 'booting' + */ + public function validateMinerStateIsBooting () { + // Just compare it... + if (!$this instanceof MinerBootingState) { + // Throw the exception + throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE); + } // END - if + } + /** * Checks if this state is 'virgin' * diff --git a/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php b/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php index 1ab70861a..c6d87ae9e 100644 --- a/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php +++ b/application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php @@ -66,8 +66,8 @@ class MinerNodeCommunicatorTask extends BaseTask implements Taskable, Visitable // Get the communicator instance $communicatorInstance = CommunicatorFactory::createCommunicatorInstance('miner_node_communicator_class', 'node'); - // Get the current miner state from registry - $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance(); + // Get the current miner state from it + $stateInstance = $communicatorInstance->getStateInstance(); // Debug message /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString()); diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index ab01534f1..e7759ba14 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -605,8 +605,14 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Debug message /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...'); - // Just update our record - $this->updateLocalNode(); + // Is the node already registered? + if ($this->isLocalNodeRegistered()) { + // Just update our record + $this->updateLocalNode(); + } else { + // Register it + $this->registerLocalNode(); + } } } diff --git a/core b/core index 1efa4dc3d..d4a8a7830 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 1efa4dc3d8bd367e85e5cecf13778d06e0418415 +Subproject commit d4a8a783029f708b1d67b44557b5387017bdd63f