private $serialNumber = 0x00000000;
/**
- * Length of largest possible serial number
+ * Maximum possible serial number
*/
- private $maxSerialLength = 8;
+ private $maxSerialNumber = 0;
/**
- * Maximum possible serial number
+ * Length of largest possible serial number
*/
- private $maxSerialNumber = 0;
+ const MAX_SERIAL_LENGTH = 8;
/**
- * Seperator between chunk data, serial number and chunk hash
+ * Separator between chunk data, serial number and chunk hash
*/
- const CHUNK_DATA_HASH_SEPERATOR = '@';
+ const CHUNK_DATA_HASH_SEPARATOR = '@';
/**
- * Seperator for all chunk hashes
+ * SEPARATOR for all chunk hashes
*/
- const CHUNK_HASH_SEPERATOR = ';';
+ const CHUNK_HASH_SEPARATOR = ';';
/**
- * Seperator between two chunks
+ * SEPARATOR between two chunks
*/
- const CHUNK_SEPERATOR = '|';
+ const CHUNK_SEPARATOR = '|';
/**
* Identifier for hash chunk
$this->chunkSize = $this->getConfigInstance()->getConfigEntry('package_chunk_size');
// - Maximum serial number
- $this->maxSerialNumber = $this->hex2dec(str_repeat('f', $this->maxSerialLength));
+ $this->maxSerialNumber = $this->hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH));
}
/**
*/
private function getProcessedPackagesIndex (array $packageData) {
return (
- $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
- $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
- $packageData[NetworkPackage::PACKAGE_DATA_CONTENT] . NetworkPackage::PACKAGE_DATA_SEPERATOR
+ $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_CONTENT] . NetworkPackage::PACKAGE_DATA_SEPARATOR
);
}
// Is the array index there?
$isProcessed = (
- (isset($this->processedPackages[$index])) &&
+ (isset($this->processedPackages[$index]))
+ &&
($this->processedPackages[$index] === true)
);
// Hash size
strlen($hash) -
// Length of sperators
- (strlen(self::CHUNK_DATA_HASH_SEPERATOR) * 2) -
+ (strlen(self::CHUNK_DATA_HASH_SEPARATOR) * 2) -
// Length of max serial number
- $this->maxSerialLength
+ self::MAX_SERIAL_LENGTH
);
// This should be larger than zero bytes
assert($this->serialNumber <= $this->maxSerialNumber);
// Encode the current serial number
- $encodedSerialNumber = $this->dec2Hex($this->serialNumber, $this->maxSerialLength);
+ $encodedSerialNumber = $this->dec2Hex($this->serialNumber, self::MAX_SERIAL_LENGTH);
// Count one up
$this->serialNumber++;
// Generate end-of-package marker
$rawData =
self::END_OF_PACKAGE_IDENTIFIER .
- $finalHash . self::CHUNK_HASH_SEPERATOR .
- $chunkHash . self::CHUNK_SEPERATOR;
+ $finalHash . self::CHUNK_HASH_SEPARATOR .
+ $chunkHash . self::CHUNK_SEPARATOR;
// Also get a hash from it
- $chunkHash = $this->generateHashFromRawData($rawData);
+ $eopHash = $this->generateHashFromRawData($rawData);
- // Append it to the chunk's data and hash array
- $this->chunkHashes[$finalHash][] = $chunkHash;
+ // Append it to the eop's data and hash array
+ $this->chunkHashes[$finalHash][] = $eopHash;
$this->chunks[$finalHash][] = $rawData;
}
/**
* Splits the given encoded data into smaller chunks, the size of the final
- * and the seperator is being subtracted from chunk size to fit it into a
+ * and the SEPARATOR is being subtracted from chunk size to fit it into a
* TCP package (512 bytes).
*
* @param $rawData Raw data string
$this->chunkHashes[$finalHash][] = $chunkHash;
// Prepend the hash to the chunk
- $chunk =
- $chunkHash . self::CHUNK_DATA_HASH_SEPERATOR .
- $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPERATOR .
- $chunk . self::CHUNK_SEPERATOR
- ;
+ $chunk = (
+ $chunkHash . self::CHUNK_DATA_HASH_SEPARATOR .
+ $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPARATOR .
+ $chunk . self::CHUNK_SEPARATOR
+ );
// Make sure the chunk is not larger than a TCP package can hold
assert(strlen($chunk) <= NetworkPackage::TCP_PACKAGE_SIZE);
*/
private function prependHashChunk ($rawData, $finalHash) {
// "Implode" the whole array of hashes into one string
- $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPERATOR, $this->chunkHashes[$finalHash]);
+ $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
// Also get a hash from it
$chunkHash = $this->generateHashFromRawData($rawData);
// Prepend the hash to the chunk
$chunk =
- $chunkHash . self::CHUNK_DATA_HASH_SEPERATOR .
- $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPERATOR .
- $chunk . self::CHUNK_SEPERATOR
+ $chunkHash . self::CHUNK_DATA_HASH_SEPARATOR .
+ $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPARATOR .
+ $chunk . self::CHUNK_SEPARATOR
;
// Make sure the chunk is not larger than a TCP package can hold
* to all chunks and prepends a chunk with all hashes only in it. It will
* return the final hash for faster processing of packages.
*
- * @param $packageData Raw package data array
- * @param $connectionInstance A helper instance for connections
- * @return $finalHash Final hash for faster processing
- * @todo $connectionInstance is unused
+ * @param $packageData Raw package data array
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return $finalHash Final hash for faster processing
+ * @todo $helperInstance is unused
*/
- public function fragmentPackageArray (array $packageData, BaseConnectionHelper $connectionInstance) {
+ public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
// Is this package already fragmented?
if (!$this->isPackageProcessed($packageData)) {
+ // Remove package status, the recipient doesn't need this
+ unset($packageData[NetworkPackage::PACKAGE_DATA_STATUS]);
+
// First we need to "implode" the array
- $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPERATOR, $packageData);
+ $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData);
// Generate the final hash from the raw data (not encoded!)
$finalHash = $this->generateHashFromRawData($rawData);
*
* @param $finalHash Final hash for faster lookup
* @return $rawDataChunk Raw package data chunk
+ * @throws AssertionException If $finalHash was not 'true'
*/
public function getNextRawDataChunk ($finalHash) {
try {
// This may happen when the final hash is true
if ($finalHash === true) {
// Set current to null
- $current = null;
+ $current = NULL;
} else {
// Throw the exception
throw $e;