]> git.mxchange.org Git - hub.git/commitdiff
Rewrote numbered indexes to assoziative
authorRoland Häder <roland@mxchange.org>
Sun, 22 Apr 2012 19:47:38 +0000 (19:47 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 22 Apr 2012 19:47:38 +0000 (19:47 +0000)
application/hub/main/class_BaseHubSystem.php
application/hub/main/handler/chunks/class_ChunkHandler.php

index 978f6922c2d5deda4ac932c269860b0656135b5e..62c578028bb04f1efa92cbdc0ecf35bb4c821f6b 100644 (file)
@@ -294,10 +294,10 @@ class BaseHubSystem extends BaseFrameworkSystem {
                assert(count($chunkSplits) == 3);
 
                // Validate final chunk
-               if (substr($chunkSplits[2], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
+               if (substr($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
                        // Not fine
                        $isValid = false;
-               } elseif (substr_count($chunkSplits[2], PackageFragmenter::CHUNK_HASH_SEPARATOR) != 1) {
+               } elseif (substr_count($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], PackageFragmenter::CHUNK_HASH_SEPARATOR) != 1) {
                        // CHUNK_HASH_SEPARATOR shall only be found once
                        $isValid = false;
                }
index a0d0bfcacaadfc55fc75d2a2b5e4e551094b958a..d70d8faa071a1dab8da0c8608ac6b6f78fc067a0 100644 (file)
@@ -27,6 +27,16 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
         */
        const STACKER_NAME_CHUNKS_WITH_FINAL_EOP = 'final_chunks';
 
+       /**
+        * Chunk splits:
+        * 0 = Hash
+        * 1 = Serial number
+        * 2 = Raw data
+        */
+       const CHUNK_SPLITS_INDEX_HASH     = 0;
+       const CHUNK_SPLITS_INDEX_SERIAL   = 0;
+       const CHUNK_SPLITS_INDEX_RAW_DATA = 0;
+
        /**
         * The final array for assembling the original package back together
         */
@@ -88,13 +98,13 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
         */
        private function isChunkHashValid (array $chunkSplits) {
                // Now hash the raw data again
-               $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[2], $chunkSplits[0], false);
+               $chunkHash = $this->getCryptoInstance()->hashString($chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA], $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH], false);
 
                // Debug output
-               //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',chunkSplits[0]=' . $chunkSplits[0] . ',chunkSplits[1]=' . $chunkSplits[1]);
+               //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: chunkHash=' . $chunkHash . ',chunkSplits[chunk_hash]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ',chunkSplits[serial]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL] . ',chunkSplits[raw_data]=' . $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA]);
 
                // Check it
-               $isValid = ($chunkSplits[0] === $chunkHash);
+               $isValid = ($chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] === $chunkHash);
 
                // ... and return it
                return $isValid;
@@ -127,16 +137,16 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
         */
        private function addChunkToFinalArray (array $chunkSplits) {
                // Is the serial number (index 1) already been added?
-               if (isset($this->finalPackageChunks[$chunkSplits[1]])) {
+               if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) {
                        // Then throw an exception
                        throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED);
                } // END - if
 
                // Add the chunk data (index 2) to the final array and use the serial number as index
-               $this->finalPackageChunks['content'][$chunkSplits[1]] = $chunkSplits[2];
+               $this->finalPackageChunks['content'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_RAW_DATA];
 
                // ... and the hash as well
-               $this->finalPackageChunks['hashes'][$chunkSplits[1]] = $chunkSplits[0];
+               $this->finalPackageChunks['hashes'][$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]] = $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH];
        }
 
        /**
@@ -225,9 +235,9 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
                } // END - if
 
                // Is the serial number valid (chars 0-9, length equals PackageFragmenter::MAX_SERIAL_LENGTH)?
-               if (!$this->isSerialNumberValid($chunkSplits[1])) {
+               if (!$this->isSerialNumberValid($chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL])) {
                        // Do some logging
-                       $this->debugOutput('CHUNK-HANDLER: Chunk serial number for hash ' . $chunkSplits[0] . ' is invalid.');
+                       $this->debugOutput('CHUNK-HANDLER: Chunk serial number for hash ' . $chunkSplits[self::CHUNK_SPLITS_INDEX_HASH] . ' is invalid.');
 
                        // Re-request this chunk
                        $this->rerequestChunkBySplitsArray($chunkSplits);
@@ -270,7 +280,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
         * Assembles all chunks (except EOP and "hash chunk") back together to the original package data.
         *
         * This is done by the following steps:
-*
+        *
         * 1) Sort the final array with ksort(). This will bring the "hash
         *    chunk" up to the last array index and the EOP chunk to the
         *    pre-last array index