]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/package/class_NetworkPackage.php
Development of 'hub' project continued:
[hub.git] / application / hub / main / package / class_NetworkPackage.php
index 0defa3a36eda700f65540e9d0e7dab4a345eaca6..e060c32f9238c09f7145a067fb9d75f5e0c4ed19 100644 (file)
@@ -132,9 +132,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        const PACKAGE_RECIPIENT_SEPARATOR = ':';
 
        /**
-        * Network target (alias): 'upper hubs'
+        * Network target (alias): 'upper nodes'
         */
-       const NETWORK_TARGET_UPPER_HUBS = 'upper';
+       const NETWORK_TARGET_UPPER_NODES = 'upper';
 
        /**
         * Network target (alias): 'self'
@@ -249,17 +249,15 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Init all stacker
                $packageInstance->initStackers();
 
-               // Get a visitor instance for speeding up things
+               // Get a visitor instance for speeding up things and set it
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_monitor_visitor_class', array($packageInstance));
-
-               // Set it in this package
                $packageInstance->setVisitorInstance($visitorInstance);
 
-               // Get crypto instance and set it in this package
+               // Get crypto instance and set it, too
                $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
                $packageInstance->setCryptoInstance($cryptoInstance);
 
-               // Get a singleton package assembler instance from factory and set it here
+               // Get a singleton package assembler instance from factory and set it here, too
                $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance($packageInstance);
                $packageInstance->setAssemblerInstance($assemblerInstance);
 
@@ -365,7 +363,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
        /**
         * "Getter" for hash from given content and sender's session id
         *
-        * @param       $decodedContent         Decoded package content
+        * @param       $decodedContent         Raw package content
         * @param       $sessionId                      Session id of the sender
         * @return      $hash                           Hash for given package content
         */
@@ -577,7 +575,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Is it the same?
                //$isSignatureValid = 
-               die(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray,true));
+               exit(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray,true));
        }
 
        /**
@@ -772,7 +770,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         *
         * @return      $isPending      Whether decoded raw data is pending
         */
-       private function isDecodedDataPending () {
+       private function isRawDataPending () {
                // Just return whether the stack is not empty
                $isPending = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING));
 
@@ -791,7 +789,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                $poolInstance->accept($this->getVisitorInstance());
 
                // Check for new data arrival
-               $hasArrived = $this->isDecodedDataPending();
+               $hasArrived = $this->isRawDataPending();
 
                // Return the status
                return $hasArrived;
@@ -809,7 +807,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * This method should only be called if decoded raw data is pending,
                 * so check it again.
                 */
-               if (!$this->isDecodedDataPending()) {
+               if (!$this->isRawDataPending()) {
                        // This is not fatal but should be avoided
                        // @TODO Add some logging here
                        return;
@@ -824,7 +822,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Make sure both array elements are there
                assert(
                        (is_array($decodedData)) &&
-                       (isset($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA])) &&
+                       (isset($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA])) &&
                        (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
                );
 
@@ -836,9 +834,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED);
 
                // Remove the last chunk SEPARATOR (because it is being added and we don't need it)
-               if (substr($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
+               if (substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) {
                        // It is there and should be removed
-                       $decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA], 0, -1);
+                       $decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA] = substr($decodedData[BaseRawDataHandler::PACKAGE_RAW_DATA], 0, -1);
                } // END - if
 
                // This package is "handled" and can be pushed on the next stack
@@ -851,12 +849,12 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @param       $handlerInstance        An instance of a Networkable class
         * @return      void
         */
-       public function addDecodedDataToIncomingStack (Networkable $handlerInstance) {
+       public function addRawDataToIncomingStack (Networkable $handlerInstance) {
                /*
                 * Get the decoded data from the handler, this is an array with
-                * 'decoded_data' and 'error_code' as elements.
+                * 'raw_data' and 'error_code' as elements.
                 */
-               $decodedData = $handlerInstance->getNextDecodedData();
+               $decodedData = $handlerInstance->getNextRawData();
 
                // Very noisy debug message:
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true));
@@ -870,7 +868,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         *
         * @return      $isHandled      Whether incoming decoded data is handled
         */
-       public function isIncomingDecodedDataHandled () {
+       public function isIncomingRawDataHandled () {
                // Determine if the stack is not empty
                $isHandled = (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED));
 
@@ -911,7 +909,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        public function assembleDecodedDataToPackage () {
                // Make sure the raw decoded package data is handled
-               assert($this->isIncomingDecodedDataHandled());
+               assert($this->isIncomingRawDataHandled());
 
                // Get current package content (an array with two elements; see handleIncomingDecodedData() for details)
                $packageContent = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECODED_HANDLED);
@@ -996,7 +994,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                 * @todo Unsupported feature of "signed" messages commented out
                if (!$this->isPackageSignatureValid($decodedArray)) {
                        // Is not valid, so throw an exception here
-                       die(__METHOD__ . ':INVALID SIG! UNDER CONSTRUCTION!' . chr(10));
+                       exit(__METHOD__ . ':INVALID SIG! UNDER CONSTRUCTION!' . chr(10));
                } // END - if
                */
 
@@ -1023,7 +1021,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * @return      void
         * @throws      InvalidDataChecksumException    If the checksum doesn't match
         */
-       public function handleDecodedData (array $decodedData) {
+       public function handleRawData (array $decodedData) {
                /*
                 * "Decode" the package's content by a simple explode() call, for
                 * details of the array elements, see comments for constant
@@ -1123,6 +1121,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                // Create a handler instance from given message type
                $handlerInstance = MessageTypeHandlerFactory::createMessageTypeHandlerInstance($messageArray[self::MESSAGE_ARRAY_TYPE]);
 
+               // Add type for later easier handling
+               $messageArray[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_TYPE] = $messageArray[self::MESSAGE_ARRAY_TYPE];
+
                // Handle message data
                $handlerInstance->handleMessageData($messageArray[self::MESSAGE_ARRAY_DATA], $this);
        }