]> git.mxchange.org Git - hub.git/commitdiff
Also submit private key hash in all messages (yepp, getting more ...).
authorRoland Haeder <roland@mxchange.org>
Mon, 11 May 2015 23:55:35 +0000 (01:55 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 11 May 2015 23:55:35 +0000 (01:55 +0200)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/main/package/class_NetworkPackage.php

index 291b8e578e263ae3469a4938adb3fcbe4504b45e..72ecc12457e0442e98a8a01ef602a7c8830f52f7 100644 (file)
@@ -73,35 +73,38 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        /**
         * Array indexes for raw package array
         */
-       const INDEX_PACKAGE_SENDER    = 0;
-       const INDEX_PACKAGE_RECIPIENT = 1;
-       const INDEX_PACKAGE_CONTENT   = 2;
-       const INDEX_PACKAGE_STATUS    = 3;
-       const INDEX_PACKAGE_HASH      = 4;
+       const INDEX_PACKAGE_SENDER           = 0;
+       const INDEX_PACKAGE_RECIPIENT        = 1;
+       const INDEX_PACKAGE_CONTENT          = 2;
+       const INDEX_PACKAGE_STATUS           = 3;
+       const INDEX_PACKAGE_HASH             = 4;
+       const INDEX_PACKAGE_PRIVATE_KEY_HASH = 5;
 
        /**
         * Size of the decoded data array
         */
-       const DECODED_DATA_ARRAY_SIZE = 5;
+       const DECODED_DATA_ARRAY_SIZE = 6;
 
        /**
         * Named array elements for decoded package content
         */
-       const PACKAGE_CONTENT_EXTENSION = 'compressor';
-       const PACKAGE_CONTENT_MESSAGE   = 'message';
-       const PACKAGE_CONTENT_TAGS      = 'tags';
-       const PACKAGE_CONTENT_CHECKSUM  = 'checksum';
-       const PACKAGE_CONTENT_SENDER    = 'sender';
-       const PACKAGE_CONTENT_HASH      = 'hash';
+       const PACKAGE_CONTENT_EXTENSION        = 'compressor';
+       const PACKAGE_CONTENT_MESSAGE          = 'message';
+       const PACKAGE_CONTENT_TAGS             = 'tags';
+       const PACKAGE_CONTENT_CHECKSUM         = 'checksum';
+       const PACKAGE_CONTENT_SENDER           = 'sender';
+       const PACKAGE_CONTENT_HASH             = 'hash';
+       const PACKAGE_CONTENT_PRIVATE_KEY_HASH = 'pkhash';
 
        /**
         * Named array elements for package data
         */
-       const PACKAGE_DATA_SENDER    = 'sender';
-       const PACKAGE_DATA_RECIPIENT = 'recipient';
-       const PACKAGE_DATA_CONTENT   = 'content';
-       const PACKAGE_DATA_STATUS    = 'status';
-       const PACKAGE_DATA_HASH      = 'hash';
+       const PACKAGE_DATA_SENDER           = 'sender';
+       const PACKAGE_DATA_RECIPIENT        = 'recipient';
+       const PACKAGE_DATA_CONTENT          = 'content';
+       const PACKAGE_DATA_STATUS           = 'status';
+       const PACKAGE_DATA_HASH             = 'hash';
+       const PACKAGE_DATA_PRIVATE_KEY_HASH = 'pkhash';
 
        /**
         * All package status
@@ -361,10 +364,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Make sure the requested element is there
                // @TODO Wrong hash!!!!
                /* DEBUG-DIE */ die('decodedData=' . print_r($decodedData, TRUE));
-               assert(isset($decodedData[self::PACKAGE_CONTENT_HASH]));
+               assert(isset($decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH]));
 
                // There is no DHT entry so, accept the hash from decoded data
-               return $decodedData[self::PACKAGE_CONTENT_HASH];
+               return $decodedData[self::PACKAGE_CONTENT_PRIVATE_KEY_HASH];
        }
 
        /**
@@ -653,9 +656,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        private function generatePackageHash ($content, $senderId) {
                // Fake array
                $data = array(
-                       self::PACKAGE_CONTENT_SENDER  => $senderId,
-                       self::PACKAGE_CONTENT_MESSAGE => $content,
-                       self::PACKAGE_CONTENT_HASH    => ''
+                       self::PACKAGE_CONTENT_SENDER           => $senderId,
+                       self::PACKAGE_CONTENT_MESSAGE          => $content,
+                       self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => ''
                );
        
                // Hash content and sender id together, use scrypt
@@ -727,11 +730,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Now prepare the temporary array and push it on the 'undeclared' stack
                $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
-                       self::PACKAGE_DATA_SENDER    => $this->getSessionId(),
-                       self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
-                       self::PACKAGE_DATA_CONTENT   => $packageContent,
-                       self::PACKAGE_DATA_STATUS    => self::PACKAGE_STATUS_NEW,
-                       self::PACKAGE_DATA_HASH      => $this->generatePackageHash($content, $this->getSessionId())
+                       self::PACKAGE_DATA_SENDER           => $this->getSessionId(),
+                       self::PACKAGE_DATA_RECIPIENT        => $helperInstance->getRecipientType(),
+                       self::PACKAGE_DATA_CONTENT          => $packageContent,
+                       self::PACKAGE_DATA_STATUS           => self::PACKAGE_STATUS_NEW,
+                       self::PACKAGE_DATA_HASH             => $this->generatePackageHash($content, $this->getSessionId()),
+                       self::PACKAGE_DATA_PRIVATE_KEY_HASH => $this->getPrivateKeyHash(),
                ));
 
                // Debug message
@@ -1243,11 +1247,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * Create 'decodedData' array with all assoziative array elements.
                 */
                $decodedData = array(
-                       self::PACKAGE_DATA_SENDER    => $decodedArray[self::INDEX_PACKAGE_SENDER],
-                       self::PACKAGE_DATA_RECIPIENT => $decodedArray[self::INDEX_PACKAGE_RECIPIENT],
-                       self::PACKAGE_DATA_CONTENT   => $decodedArray[self::INDEX_PACKAGE_CONTENT],
-                       self::PACKAGE_DATA_STATUS    => self::PACKAGE_STATUS_DECODED,
-                       self::PACKAGE_DATA_HASH      => $decodedArray[self::INDEX_PACKAGE_HASH]
+                       self::PACKAGE_DATA_SENDER           => $decodedArray[self::INDEX_PACKAGE_SENDER],
+                       self::PACKAGE_DATA_RECIPIENT        => $decodedArray[self::INDEX_PACKAGE_RECIPIENT],
+                       self::PACKAGE_DATA_CONTENT          => $decodedArray[self::INDEX_PACKAGE_CONTENT],
+                       self::PACKAGE_DATA_STATUS           => self::PACKAGE_STATUS_DECODED,
+                       self::PACKAGE_DATA_HASH             => $decodedArray[self::INDEX_PACKAGE_HASH]
+                       self::PACKAGE_DATA_PRIVATE_KEY_HASH => $decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]
                );
 
                // And return it
@@ -1279,17 +1284,19 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 */
                $decodedContent = array(
                        // Compressor's extension used to compress the data
-                       self::PACKAGE_CONTENT_EXTENSION => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
+                       self::PACKAGE_CONTENT_EXTENSION        => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
                        // Package data (aka "message") in BASE64-decoded form but still compressed
-                       self::PACKAGE_CONTENT_MESSAGE   => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
+                       self::PACKAGE_CONTENT_MESSAGE          => base64_decode($decodedContent[self::INDEX_PACKAGE_DATA]),
                        // Tags as an indexed array for "tagging" the message
-                       self::PACKAGE_CONTENT_TAGS      => explode(self::PACKAGE_TAGS_SEPARATOR, $decodedContent[self::INDEX_TAGS]),
+                       self::PACKAGE_CONTENT_TAGS             => explode(self::PACKAGE_TAGS_SEPARATOR, $decodedContent[self::INDEX_TAGS]),
                        // Checksum of the _decoded_ data
-                       self::PACKAGE_CONTENT_CHECKSUM  => $decodedContent[self::INDEX_CHECKSUM],
+                       self::PACKAGE_CONTENT_CHECKSUM         => $decodedContent[self::INDEX_CHECKSUM],
                        // Sender's id
-                       self::PACKAGE_CONTENT_SENDER    => $decodedData[self::PACKAGE_DATA_SENDER],
+                       self::PACKAGE_CONTENT_SENDER           => $decodedData[self::PACKAGE_DATA_SENDER],
                        // Hash from decoded raw data
-                       self::PACKAGE_CONTENT_HASH      => $decodedData[self::PACKAGE_DATA_HASH]
+                       self::PACKAGE_CONTENT_HASH             => $decodedData[self::PACKAGE_DATA_HASH],
+                       // Hash of private key
+                       self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $decodedData[self::PACKAGE_DATA_PRIVATE_KEY_HASH]
                );
 
                // Is the checksum valid?