]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/package/class_NetworkPackage.php
Better name for the miner: It "mines" for Hubcoins.
[hub.git] / application / hub / main / package / class_NetworkPackage.php
index c0e01cffba2abb5341e3db43d29a81ec9aae6ba7..4c5dc1b10defb8e8738e9543ffe4444e48040118 100644 (file)
@@ -656,9 +656,13 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      $hash           Hash as hex-encoded string
         */
        private function generatePackageHash ($content, $senderId) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!');
+
                // Is the feature enabled?
-               if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+               if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
                        // Feature is not enabled
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...');
                        return NULL;
                } // END - if
 
@@ -671,7 +675,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        
                // Hash content and sender id together, use scrypt
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $senderId . ',content()=' . strlen($content));
-               $hash = Scrypt::hashScrypt($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data));
+               $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array($senderId . ':' . $content . ':' . $this->determineSenderPrivateKeyHash($data)));
+
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: hash=' . $hash . ' - EXIT!');
 
                // Return it
                return $hash;
@@ -686,19 +693,28 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @todo        Unfinished area, hashes are currently NOT fully supported
         */
        private function isPackageHashValid (array $decodedArray) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: decodedArray=' . print_r($decodedArray, TRUE) . ' - CALLED!');
+
+               // Make sure the required array elements are there
+               assert(isset($decodedArray[self::PACKAGE_CONTENT_SENDER]));
+               assert(isset($decodedArray[self::PACKAGE_CONTENT_MESSAGE]));
+               assert(isset($decodedArray[self::PACKAGE_CONTENT_HASH]));
+
                // Is the feature enabled?
-               if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+               if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
                        // Feature is not enabled, so hashes are always valid
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Feature "hubcoin_reward" not available, not checking hash. Returning TRUE ...');
                        return TRUE;
                } // END - if
 
                // Check validity
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',decodedArray=' . print_r($decodedArray, TRUE));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',message()=' . strlen($decodedArray[self::PACKAGE_CONTENT_MESSAGE]) . '),hash=' . $decodedArray[self::PACKAGE_CONTENT_HASH]);
                //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE));
-               $isHashValid = Scrypt::checkScrypt($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]);
+               $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH]));
 
                // Return it
-               //* DEBUG-DIE: */ die(__METHOD__ . ': isHashValid=' . intval($isHashValid) . ',decodedArray=' . print_r($decodedArray, TRUE));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: isHashValid=' . intval($isHashValid) . ' - EXIT!');
                return $isHashValid;
        }
 
@@ -1419,7 +1435,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * Feeds the hash and sender (as recipient for the 'sender' reward) to the
         * miner's queue, unless the message is not a "reward claim" message as this
         * leads to an endless loop. You may wish to run the miner to get some
-        * reward ("HubCoins") for "mining" this hash.
+        * reward ("Hubcoins") for "mining" this hash.
         *
         * @param       $messageData    Array with message data
         * @return      void
@@ -1427,7 +1443,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        public function feedHashToMiner (array $messageData) {
                // Is the feature enabled?
-               if ($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === FALSE) {
+               if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
                        /*
                         * Feature is not enabled, don't feed the hash to the miner as it
                         *may be invalid.