]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/package/class_NetworkPackage.php
The package hash needs to be copied to the message array as it needs to be
[hub.git] / application / hub / main / package / class_NetworkPackage.php
index c1d8f059a17781c9d5d1c8b31b963fbccf46227d..7eb2c4d9467a211111526bafce68bc0c4e2a7ac6 100644 (file)
@@ -117,8 +117,11 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        /**
         * Constants for message data array
         */
-       const MESSAGE_ARRAY_DATA = 'message_data';
-       const MESSAGE_ARRAY_TYPE = 'message_type';
+       const MESSAGE_ARRAY_DATA   = 'message_data';
+       const MESSAGE_ARRAY_TYPE   = 'message_type';
+       const MESSAGE_ARRAY_SENDER = 'message_sender';
+       const MESSAGE_ARRAY_HASH   = 'message_hash';
+       const MESSAGE_ARRAY_TAGS   = 'message_tags';
 
        /**
         * Generic answer status field
@@ -1334,6 +1337,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @todo        Implement verification of all sent tags here?
         */
        public function handleNewlyArrivedMessage () {
+               // Make sure there is at least one message
+               assert($this->isNewMessageArrived());
+
                // Get it from the stacker, it is the full array with the decoded message
                $decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
 
@@ -1351,6 +1357,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * elements from $decodedContent are no longer needed.
                 */
                $chainInstance->processMessage($decodedContent, $this);
+
+               /*
+                * Post-processing of message data (this won't remote the message from
+                * the stack).
+                */
+               $chainInstance->postProcessMessage();
        }
 
        /**
@@ -1394,21 +1406,24 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * leads to an endless loop. You may wish to run the miner to get some
         * reward ("HubCoins") for "mining" this hash.
         *
-        * @param       $decodedDataArray       Array with decoded message
+        * @param       $messageData    Array with message data
         * @return      void
         * @todo        ~10% done?
         */
-       public function feedHashToMiner (array $decodedDataArray) {
+       public function feedHashToMiner (array $messageData) {
                // Make sure the required elements are there
-               assert(isset($decodedDataArray[self::PACKAGE_CONTENT_SENDER]));
-               assert(isset($decodedDataArray[self::PACKAGE_CONTENT_HASH]));
-               assert(isset($decodedDataArray[self::PACKAGE_CONTENT_TAGS]));
+               assert(isset($messageData[self::MESSAGE_ARRAY_SENDER]));
+               assert(isset($messageData[self::MESSAGE_ARRAY_HASH]));
+               assert(isset($messageData[self::MESSAGE_ARRAY_TAGS]));
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: messageData=' . print_r($messageData, TRUE));
 
                // Resolve session id ('sender' is a session id) into node id
-               $nodeId = HubTools::resolveNodeIdBySessionId($decodedDataArray[self::PACKAGE_CONTENT_SENDER]);
+               $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]);
 
                // Is 'claim_reward' the message type?
-               if (in_array('claim_reward', $decodedDataArray[self::PACKAGE_CONTENT_TAGS])) {
+               if (in_array('claim_reward', $messageData[self::MESSAGE_ARRAY_TAGS])) {
                        /*
                         * Then don't feed this message to the miner as this causes an
                         * endless loop of mining.
@@ -1416,7 +1431,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                        return;
                } // END - if
 
-               $this->partialStub('@TODO nodeId=' . $nodeId . ',decodedDataArray=' . print_r($decodedDataArray, TRUE));
+               $this->partialStub('@TODO nodeId=' . $nodeId . ',messageData=' . print_r($messageData, TRUE));
        }
 }