]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Tue, 22 Jul 2014 18:54:28 +0000 (20:54 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 22 Jul 2014 18:54:28 +0000 (20:54 +0200)
- fixed bad handlig in NodeDistributedHashTableDatabaseWrapper
- improved other stuff (communicator, ...)
- used new 'core' (only chash.php)

Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/main/communicator/class_BaseCommunicator.php
application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php
application/hub/main/states/communicator/init/class_CommunicatorInitState.php
application/hub/main/states/miner/booting/class_MinerBootingState.php
application/hub/main/states/miner/class_BaseMinerState.php
application/hub/main/tasks/miner/communicator/class_MinerNodeCommunicatorTask.php
application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
core

index 1fda37328f20125f165004eecee3e214f738d01b..0d544714fe8b1406457b796669f32c55bbe175ab 100644 (file)
@@ -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
         */
index e0329ac3ab13a3926844834fb574939b267ee2de..8d5aedce0ecd741c822f2c5780ec5c2e8c701886 100644 (file)
@@ -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.
+                */
        }
 }
 
index 86f7455535c6c40b66c04cc96565e95ee0aff56e..d0c89c0ca26fb26204cd4c687142aa9341fbeaf4 100644 (file)
@@ -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]
index 4c3ddd8c0d7ee2dbcf7dd9e8aefa6acccecaa5fe..5a29b1539e6637e7cdb23396c23f6ef77d7a6cce 100644 (file)
@@ -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);
        }
index 891a7221d0a2e46bb00d8b61b3d788b94d8da16a..0208d7a2cee02e901ea7aa36f07e4ae7e66ac18f 100644 (file)
@@ -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'
         *
index 1ab70861a9d11beb20df9fb9f8a86b58c77f277f..c6d87ae9eb34d533c93ff85049e66a4e7d5f8cd3 100644 (file)
@@ -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());
index ab01534f1eca6a01c59321f6e16329a12dd7d1e1..e7759ba14931f17a7024b9aa924d2462666e700e 100644 (file)
@@ -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 1efa4dc3d8bd367e85e5cecf13778d06e0418415..d4a8a783029f708b1d67b44557b5387017bdd63f 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 1efa4dc3d8bd367e85e5cecf13778d06e0418415
+Subproject commit d4a8a783029f708b1d67b44557b5387017bdd63f