]> git.mxchange.org Git - hub.git/commitdiff
Filter for package tags added, handling of new messages basicly finished
authorRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 10:15:26 +0000 (10:15 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 10:15:26 +0000 (10:15 +0000)
- Interface 'FilterablePackage' added
- Filter PackageAnnouncementTagFilter added which shall filter announcement
  messages and process them
- Class PackageFilterChain added which is a specialized filter chain for
  handling packages (or their messages)
- Stack for 'processed messages' added
- Other minor improvements
- TODOs.txt updated

17 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/filter/.htaccess [new file with mode: 0644]
application/hub/interfaces/filter/class_FilterablePackage.php [new file with mode: 0644]
application/hub/main/factories/chain/.htaccess [new file with mode: 0644]
application/hub/main/factories/chain/class_PackageFilterChainFactory.php [new file with mode: 0644]
application/hub/main/filter/chains/.htaccess [new file with mode: 0644]
application/hub/main/filter/chains/class_PackageFilterChain.php [new file with mode: 0644]
application/hub/main/filter/tags/.htaccess [new file with mode: 0644]
application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php [new file with mode: 0644]
application/hub/main/handler/chunks/class_ChunkHandler.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/registry/connection/class_ConnectionRegistry.php
application/hub/main/registry/socket/class_SocketRegistry.php
application/hub/main/tasks/network/class_NetworkPackageReaderTask.php
application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php
docs/TODOs.txt

index a28c16fc0cbfa3b20cc7a40268147c81730bd0cc..552e40a8f82580b972476c701b05c2febcf20133 100644 (file)
@@ -48,6 +48,8 @@ application/hub/interfaces/discovery/class_DiscoverableRecipient.php svneol=nati
 application/hub/interfaces/discovery/class_DiscoverableSocket.php svneol=native#text/plain
 application/hub/interfaces/executor/.htaccess svneol=native#text/plain
 application/hub/interfaces/executor/class_Executor.php svneol=native#text/plain
+application/hub/interfaces/filter/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/filter/class_FilterablePackage.php svneol=native#text/plain
 application/hub/interfaces/handler/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/chunks/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/chunks/class_HandleableChunks.php svneol=native#text/plain
@@ -197,6 +199,8 @@ application/hub/main/discovery/package/class_PackageRecipientDiscovery.php svneo
 application/hub/main/discovery/socket/.htaccess -text svneol=unset#text/plain
 application/hub/main/discovery/socket/class_PackageSocketDiscovery.php svneol=native#text/plain
 application/hub/main/factories/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/chain/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/chain/class_PackageFilterChainFactory.php svneol=native#text/plain
 application/hub/main/factories/chunks/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/chunks/class_ChunkHandlerFactory.php svneol=native#text/plain
 application/hub/main/factories/discovery/.htaccess -text svneol=unset#text/plain
@@ -245,6 +249,8 @@ application/hub/main/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdF
 application/hub/main/filter/bootstrap/node/class_NodeBootstrapInitQueuesFilter.php svneol=native#text/plain
 application/hub/main/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php svneol=native#text/plain
 application/hub/main/filter/bootstrap/node/class_NodeBootstrapRestoreNodeListFilter.php svneol=native#text/plain
+application/hub/main/filter/chains/.htaccess -text svneol=unset#text/plain
+application/hub/main/filter/chains/class_PackageFilterChain.php svneol=native#text/plain
 application/hub/main/filter/chat/.htaccess svneol=native#text/plain
 application/hub/main/filter/chat/class_ChatInitializationFilter.php svneol=native#text/plain
 application/hub/main/filter/chat/class_ChatPhpRequirementsFilter.php svneol=native#text/plain
@@ -269,6 +275,8 @@ application/hub/main/filter/shutdown/node/class_NodeShutdownDeinitQueuesFilter.p
 application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php svneol=native#text/plain
 application/hub/main/filter/shutdown/node/class_NodeShutdownNodeFilter.php svneol=native#text/plain
 application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php svneol=native#text/plain
+application/hub/main/filter/tags/.htaccess -text svneol=unset#text/plain
+application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php svneol=native#text/plain
 application/hub/main/filter/task/.htaccess -text svneol=unset#text/plain
 application/hub/main/filter/task/chat/.htaccess svneol=native#text/plain
 application/hub/main/filter/task/chat/class_ChatTaskHandlerInitializerFilter.php svneol=native#text/plain
index 593affa019e35325d256d91999e3c1d6eb9eae59..9387fcbdfbe538cba1ea5b873d5b7137b4045da7 100644 (file)
@@ -195,6 +195,12 @@ $cfg->setConfigEntry('node_shutdown_task_handler_filter', 'NodeShutdownTaskHandl
 // CFG: NODE-SHUTDOWN-NODE-FILTER
 $cfg->setConfigEntry('node_shutdown_node_filter', 'NodeShutdownNodeFilter');
 
+// CFG: PACKAGE-FILTER-CHAIN-CLASS
+$cfg->setConfigEntry('package_filter_chain_class', 'PackageFilterChain');
+
+// CFG: PACKAGE-TAG-ANNOUNCEMENT-FILTER
+$cfg->setConfigEntry('package_tag_announcement_filter', 'PackageAnnouncementTagFilter');
+
 // CFG: NEWS-READER-CLASS
 $cfg->setConfigEntry('news_reader_class', 'ConsoleNewsReader');
 
@@ -282,6 +288,9 @@ $cfg->setConfigEntry('stacker_package_chunked_decoded_max_size', 800);
 // CFG: STACKER-PACKAGE-NEW-MESSAGE-MAX-SIZE
 $cfg->setConfigEntry('stacker_package_new_message_max_size', 400);
 
+// CFG: STACKER-PACKAGE-PROCESSED-MESSAGE-MAX-SIZE
+$cfg->setConfigEntry('stacker_package_processed_message_max_size', 400);
+
 // CFG: STACKER-PACKAGE-BACKBUFFER-MAX-SIZE
 $cfg->setConfigEntry('stacker_package_backbuffer_max_size', 1000);
 
diff --git a/application/hub/interfaces/filter/.htaccess b/application/hub/interfaces/filter/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/filter/class_FilterablePackage.php b/application/hub/interfaces/filter/class_FilterablePackage.php
new file mode 100644 (file)
index 0000000..c6b9d0e
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * A class for package filters
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface FilterablePackage extends Filterable {
+       /**
+        * Processes the given raw message content.
+        *
+        * @param       $messageContent         Raw message content
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        */
+       function processMessage ($messageContent, Receivable $packageInstance);
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/factories/chain/.htaccess b/application/hub/main/factories/chain/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/chain/class_PackageFilterChainFactory.php b/application/hub/main/factories/chain/class_PackageFilterChainFactory.php
new file mode 100644 (file)
index 0000000..9ded481
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PackageFilterChainFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a filter chain by given tags array.
+        *
+        * @param       $tags                   An array with tags from a package
+        * @return      $chainInstance  An instance of a filter chain class
+        */
+       public static final function createChainByTagsArray (array $tags) {
+               // Get a registry key from tags array, this does mostly call implode()
+               $registryKey = Registry::getRegistryKeyFromArray('package_filter_chain', $tags);
+
+               // Is the registry key there?
+               if (Registry::getRegistry()->instanceExists($registryKey)) {
+                       // Yes, then use that instance
+                       $chainInstance = Registry::getRegistry()->getInstance($registryKey);
+               } else {
+                       // Initialize a filter chain class
+                       $chainInstance = ObjectFactory::createObjectByConfiguredName('package_filter_chain_class');
+
+                       // "Walk" through all tags entries
+                       foreach ($tags as $tag) {
+                               /*
+                                * Now create a filter instance of this tag. This way all tags
+                                * got rudymentary verified, if an exception is coming here, it
+                                * simply means the tag is not valid. This however should be
+                                * handled some calls before this method is called.
+                                */
+                               $filterInstance = ObjectFactory::createObjectByConfiguredName('package_tag_' . $tag . '_filter');
+
+                               // Add this filter to the chain
+                               $chainInstance->addFilter($filterInstance);
+                       } // END - foreach
+
+                       // Add the finished chain to the registry
+                       Registry::getRegistry()->addInstance($registryKey, $chainInstance);
+               }
+
+               // Return the chain instance
+               return $chainInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/filter/chains/.htaccess b/application/hub/main/filter/chains/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/filter/chains/class_PackageFilterChain.php b/application/hub/main/filter/chains/class_PackageFilterChain.php
new file mode 100644 (file)
index 0000000..3e8f5cc
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * A filter chain for processing network packages (or better messages)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PackageFilterChain extends FilterChain {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $chainInstance  An instance of this class
+        */
+       public static final function createPackageFilterChain () {
+               // Get a new instance
+               $chainInstance = new PackageFilterChain();
+
+               // Return the prepared instance
+               return $chainInstance;
+       }
+
+       /**
+        * Processes the given raw message content through all filters
+        *
+        * @param       $messageContent         Raw message content
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        * @todo        This may be slow if a message with a lot tags arrived
+        */
+       public function processMessage ($messageContent, Receivable $packageInstance) {
+               // Get all filters and "run" them
+               foreach ($this->getFilters() as $filterInstance) {
+                       // Try to process it
+                       try {
+                               $filterInstance->processMessage($messageContent, $packageInstance);
+                       } catch (FilterChainException $e) {
+                               // This exception can be thrown to just skip any further processing
+                               $this->debugOutput('Failed to execute lase filter ' . $filterInstance->__toString() . ': ' . $e->getMessage());
+                               break;
+                       }
+               } // END - foreach
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/filter/tags/.htaccess b/application/hub/main/filter/tags/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php
new file mode 100644 (file)
index 0000000..ee6521e
--- /dev/null
@@ -0,0 +1,147 @@
+<?php
+/**
+ * A AnnouncementTag filter for Package
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PackageAnnouncementTagFilter extends BaseFilter implements FilterablePackage {
+       /**
+        * Constants for message data array
+        */
+       const MESSAGE_ARRAY_DATA = 'message_data';
+       const MESSAGE_ARRAY_TYPE = 'message_type';
+
+       /**
+        * Array with all data XML nodes (which hold the actual data) and their values
+        */
+       private $dataXmlNodes = array();
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Init array
+               $this->dataXmlNodes = array(
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP => '',
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID  => '',
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT    => 9060,
+                       XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT    => 9060
+               );
+       }
+
+       /**
+        * Creates an instance of this filter class
+        *
+        * @return      $filterInstance         An instance of this filter class
+        */
+       public final static function createPackageAnnouncementTagFilter () {
+               // Get a new instance
+               $filterInstance = new PackageAnnouncementTagFilter();
+
+               // Return the instance
+               return $filterInstance;
+       }
+
+       /**
+        * Executes the filter with given request and response objects
+        *
+        * @param       $requestInstance        An instance of a class with an Requestable interface
+        * @param       $responseInstance       An instance of a class with an Responseable interface
+        * @return      void
+        * @throws      UnsupportedOperationException   If this method is called, please use processMessage() instead!
+        */
+       public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+               // Please don't call this method
+               throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+       }
+
+       /**
+        * Processes the given raw message content. The method renderXmlContent
+        * may throw (not the method itself) several exceptions:
+        *
+        * InvalidXmlNodeException  - If an invalid XML node has been found (e.g.
+        *                            wrong/out-dated template used)
+        * XmlNodeMismatchException - Again might be caused by invalid XML node
+        *                            usage
+        * XmlParserException       - If the XML message is damaged or not
+        *                            well-formed
+        *
+        * @param       $messageContent         Raw message content
+        * @param       $packageInstance        An instance of a Receivable class
+        * @return      void
+        * @todo        Exceptions from renderXmlContent() are currently unhandled
+        */
+       public function processMessage ($messageContent, Receivable $packageInstance) {
+               // Get a template instance from the factory
+               $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_announcement_template_class');
+
+               // And render the XML content (aka message)
+               $templateInstance->renderXmlContent($messageContent);
+
+               /*
+                * The template system now stores all required data as 'general'
+                * variables, so simply get them. If there is an invalid XML node
+                * inside the message, the above method call will cause exceptions.
+                */
+               foreach ($this->dataXmlNodes as $key => $dummy) {
+                       // Get the variable from template engine
+                       $value = $templateInstance->readAnnouncementData($key);
+
+                       /*
+                        * If value is NULL, a variable hasn't been found. This could mean
+                        * that *this* node is running an out-dated software or the other
+                        * peer is using an out-dated announcement.xml template.
+                        */
+                       if (is_null($value)) {
+                               // Output a warning
+                               $this->debugOutput('ANNOUNCEMENT-TAG: Found not fully supported variable ' . $key . ' - skipping.');
+
+                               // Skip this part, don't write NULLs to the array
+                               continue;
+                       } // END - if
+
+                       // Debug message
+                       $this->debugOutput('ANNOUNCEMENT-TAG: key=' . $key . ',value=' . $value);
+
+                       // Set it now
+                       $this->dataXmlNodes[$key] = $value;
+               } // END - foreach
+
+               // Construct an array for pushing it on next stack
+               $messageArray = array(
+                       // Message data itself
+                       self::MESSAGE_ARRAY_DATA => $this->dataXmlNodes,
+                       // Message type (which is 'announcement')
+                       self::MESSAGE_ARRAY_TYPE => 'announcement'
+               );
+
+               // Push the processed message back on stack
+               $packageInstance->getStackerInstance()->pushNamed(NetworkPackage::STACKER_NAME_PROCESSED_MESSAGE);
+       }
+}
+
+// [EOF]
+?>
index c643bba145e0b2d7b1b2114442ebab9ff2cff736..7aa6f23e37ec985b531ed7634b5e688f1c5e3667 100644 (file)
@@ -277,7 +277,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
                $this->getFragmenterInstance()->resetSerialNumber();
 
                // "Walk" through all (content) chunks
-               foreach ($this->finalPackageChunks['content'] as $serialNumber=>$content) {
+               foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
                        // Get next serial number
                        $nextSerial = $this->getFragmenterInstance()->getNextHexSerialNumber();
 
@@ -311,7 +311,7 @@ class ChunkHandler extends BaseHandler implements HandleableChunks, Registerable
                $this->rawPackageData = '';
 
                // That went well, so start assembling all chunks
-               foreach ($this->finalPackageChunks['content'] as $serialNumber=>$content) {
+               foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) {
                        // Debug message
                        //* NOISY-DEBUG: */ $this->debugOutput('CHUNK-HANDLER: serialNumber=' . $serialNumber . ' - validating ...');
                        //* NOISY-DEBUG: */ $this->debugOutput('finalPackageChunks=' . print_r($this->finalPackageChunks,true) . 'chunkHashes=' . print_r($this->chunkHashes,true));
index 4babcc647fa3b19770273d5c9de7bf99ab2989fd..fad98f9d25609197c68ebb9c2d13df69ce8aac01 100644 (file)
@@ -171,11 +171,20 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        const STACKER_NAME_DECODED_CHUNKED = 'package_chunked_decoded';
 
+       /**************************************************************************
+        *                     Stacker for incoming messages                      *
+        **************************************************************************/
+
        /**
         * Stacker name for new messages
         */
        const STACKER_NAME_NEW_MESSAGE = 'package_new_message';
 
+       /**
+        * Stacker name for processed messages
+        */
+       const STACKER_NAME_PROCESSED_MESSAGE = 'package_processed_message';
+
        /**************************************************************************
         *                   Stacker for other/internal purposes                  *
         **************************************************************************/
@@ -256,6 +265,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
                                self::STACKER_NAME_DECODED_HANDLED,
                                self::STACKER_NAME_DECODED_CHUNKED,
                                self::STACKER_NAME_NEW_MESSAGE,
+                               self::STACKER_NAME_PROCESSED_MESSAGE,
                                self::STACKER_NAME_BACK_BUFFER
                        ) as $stackerName) {
                                // Init this stacker
@@ -1047,12 +1057,20 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         * Handles newly arrived messages
         *
         * @return      void
+        * @todo        Implement verification of all sent tags here?
         */
        public function handleNewlyArrivedMessage () {
                // Get it from the stacker, it is the full array with the decoded message
                $decodedContent = $this->getStackerInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
 
-               die('decodedContent='.print_r($decodedContent,true));
+               // Now get a filter chain back from factory with given tags array
+               $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedContent[self::PACKAGE_CONTENT_TAGS]);
+
+               /*
+                * Process the message through all filters, note that all other
+                * elements from $decodedContent are no longer needed.
+                */
+               $chainInstance->processMessage($decodedContent[self::PACKAGE_CONTENT_MESSAGE], $this);
        }
 }
 
index 7dd941b5381d1e511c4a1163f3320ab0b8dde0de..22aaedf1e41069b99f1692362dd04b1cc3c349ae 100644 (file)
@@ -217,9 +217,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC
                $connectionInstance = NULL;
 
                // Get all keys and check them
-               foreach ($this->getInstanceRegistry() as $key=>$registryInstance) {
+               foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
                        // This is always a SubRegistry instance
-                       foreach ($registryInstance->getInstanceRegistry() as $subKey=>$containerInstance) {
+                       foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
                                // This is a ConnectionContainer instance, so does the recipient match?
                                if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
                                        // Found one, so get the protocol instance and abort any further search
index 6d845eb2f0dbcef063deb52b741d5b2a5367a9d8..f6e402559806f9e0cbf78a32eb05eea11be44306 100644 (file)
@@ -217,9 +217,9 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                $protocolInstance = NULL;
 
                // Get all keys and check them
-               foreach ($this->getInstanceRegistry() as $key=>$registryInstance) {
+               foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
                        // This is always a SubRegistry instance
-                       foreach ($registryInstance->getInstanceRegistry() as $subKey=>$containerInstance) {
+                       foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
                                // This is a SocketContainer instance, so does the recipient match?
                                if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
                                        // Found one, so get the protocol instance and abort any further search
index c3932a73c2f1f1ed54b14ad21b8d413816aa7874..23410b6a9055ea58e2fd29200cf8a9f49c393312 100644 (file)
@@ -75,20 +75,26 @@ class NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
        public function executeTask () {
                // Do we have something to handle?
                if ($this->getPackageInstance()->isNewMessageArrived()) {
-                       // Okay, then handle newly arrived message
+                       /*
+                        * A fully "decoded" message has been received and added for being
+                        * processed. Processing a message should not take long, so mostly
+                        * this step involves reading all data through a XML template engine
+                        * as "XML variables" from the content (which must be a well-formed
+                        * XML) and then pushing it on the next stack "processed messages".
+                        */
                        $this->getPackageInstance()->handleNewlyArrivedMessage();
                } elseif ($this->getPackageInstance()->isIncomingDecodedDataHandled()) {
                        /*
-                        * We have handled decoded data so we should validate it, if we have
-                        * all chunks/fragments together, and assemble it into an abstract
-                        * network package.
+                        * Incoming decoded data has been handled (see below) so it needs to
+                        * be assembled back to a "package array". Please see NetworkPackage
+                        * for further details (what array elements are required et cetera).
                         */
                        $this->getPackageInstance()->assembleDecodedDataToPackage();
                } elseif ($this->getPackageInstance()->isNewRawDataPending($this->getListenerPoolInstance())) {
-                       // We have to handle raw data from the socket
+                       // Raw, decoded data has been received
                        $this->getPackageInstance()->handleIncomingDecodedData();
                } elseif ($this->getPackageInstance()->ifAssemblerHasPendingDataLeft()) {
-                       // Okay, handle it here
+                       // Handle any pending data from the package assembler
                        $this->getPackageInstance()->handleAssemblerPendingData();
                } // END - if
        }
index bb1187423d7f976de808bb8a5bb7f29495261977..9c0b2d6fe90ffb05159d266dce4db6d0a7d4e1a7 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
+       /**
+        * Some XML nodes must be available for later data extraction
+        */
+       const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip';
+       const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status';
+       const ANNOUNCEMENT_DATA_SESSION_ID  = 'session-id';
+       const ANNOUNCEMENT_DATA_TCP_PORT    = 'tcp-port';
+       const ANNOUNCEMENT_DATA_UDP_PORT    = 'udp-port';
+
        /**
         * Main nodes in the XML tree
         */
@@ -33,18 +42,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        /**
         * Sub nodes in the XML tree
         */
-       private $subNodes = array(
-               'announcement-data',
-               'listener',
-               'hub-listener',
-               'client-listener',
-               'node-status',
-               'tcp-port',
-               'udp-port',
-               'session-id',
-               'external-ip',
-               'object-type-list',
-       );
+       private $subNodes = array();
 
        /**
         * Current main node
@@ -64,6 +62,18 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Init array
+               $this->subNodes = array(
+                       'announcement-data',
+                       'listener',
+                       self::ANNOUNCEMENT_DATA_NODE_STATUS,
+                       self::ANNOUNCEMENT_DATA_TCP_PORT,
+                       self::ANNOUNCEMENT_DATA_UDP_PORT,
+                       self::ANNOUNCEMENT_DATA_SESSION_ID,
+                       self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+                       'object-type-list',
+               );
        }
 
        /**
@@ -284,6 +294,21 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                } // END - if
        }
 
+       /**
+        * Read announcement variables by calling readVariable() with 'general' as
+        * variable stack.
+        *
+        * @param       $key    Key to read from
+        * @return      $value  Value from variable
+        */
+       public function readAnnouncementData ($key) {
+               // Read the variable
+               $value = parent::readVariable($key, 'general');
+
+               // Return value
+               return $value;
+       }
+
        /**
         * Getter for cache file (FQFN)
         *
@@ -320,7 +345,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startNodeStatus () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'node-status');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
        }
 
        /**
@@ -333,26 +358,6 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                $this->getStackerInstance()->pushNamed('announcement', 'listener');
        }
 
-       /**
-        * Starts the client listener
-        *
-        * @return      void
-        */
-       private function startClientListener () {
-               // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'client-listener');
-       }
-
-       /**
-        * Starts the hub listener
-        *
-        * @return      void
-        */
-       private function startHubListener () {
-               // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'hub-listener');
-       }
-
        /**
         * Starts the TCP port
         *
@@ -360,7 +365,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startTcpPort () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'tcp-port');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_TCP_PORT);
        }
 
        /**
@@ -370,7 +375,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startUdpPort () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'udp-port');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_UDP_PORT);
        }
 
        /**
@@ -380,7 +385,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startSessionId () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'session-id');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
        }
 
        /**
@@ -390,7 +395,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startExternalIp () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'external-ip');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
        }
 
        /**
@@ -473,26 +478,6 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                $this->getStackerInstance()->popNamed('announcement');
        }
 
-       /**
-        * Finishes the hub listener
-        *
-        * @return      void
-        */
-       private function finishHubListener () {
-               // Pop the last entry
-               $this->getStackerInstance()->popNamed('announcement');
-       }
-
-       /**
-        * Finishes the client listener
-        *
-        * @return      void
-        */
-       private function finishClientListener () {
-               // Pop the last entry
-               $this->getStackerInstance()->popNamed('announcement');
-       }
-
        /**
         * Finishes the listener
         *
index 3b217cedb0e2e0ba98182ddd2adcc94e4110d219..0ea51295a54b3714d5d7e99d6ec91c2c9bcb48a5 100644 (file)
@@ -28,6 +28,7 @@
 ./application/hub/main/filter/bootstrap/chat/class_ChatBootstrapGenericActivationFilter.php:54:         * @todo        Maybe we want to do somthing more here?
 ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapBufferQueueInitializerFilter.php:54:    * @todo        0% done
 ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapGenericActivationFilter.php:54:         * @todo        Maybe we want to do somthing more here?
+./application/hub/main/filter/chains/class_PackageFilterChain.php:54:   * @todo        This may be slow if a message with a lot tags arrived
 ./application/hub/main/filter/chat/class_ChatInitializationFilter.php:54:       * @todo        0% done
 ./application/hub/main/filter/chat/class_ChatPhpRequirementsFilter.php:55:      * @todo        Add more test and try to add an extra message to the thrown exception
 ./application/hub/main/filter/chat/class_ChatWelcomeTeaserFilter.php:55:        * @todo        Handle over the $responseInstance to outputConsoleTeaser()
@@ -41,6 +42,7 @@
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownDeinitQueuesFilter.php:55:        * @todo        0% done
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php:55:       * @todo        0% done
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php:55:         * @todo        0% done
+./application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php:95:   * @todo        Exceptions from renderXmlContent() are currently unhandled
 ./application/hub/main/filter/task/chat/class_ChatTaskHandlerInitializerFilter.php:55:  * @todo        5% done
 ./application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php:55:  * @todo        5% done
 ./application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php:55:  * @todo        Maybe some more tasks needs to be added?
 ./application/hub/main/nodes/regular/class_HubRegularNode.php:58:       * @todo        Implement this method
 ./application/hub/main/nodes/regular/class_HubRegularNode.php:68:       * @todo        Unfinished method
 ./application/hub/main/nodes/regular/class_HubRegularNode.php:91:              // @TODO Add some filters here
+./application/hub/main/package/class_NetworkPackage.php:1060:   * @todo        Implement verification of all sent tags here?
 ./application/hub/main/package/class_NetworkPackage.php:23: * @todo            Needs to add functionality for handling the object's type
-./application/hub/main/package/class_NetworkPackage.php:277:           // @TODO crc32() is very weak, but it needs to be fast
-./application/hub/main/package/class_NetworkPackage.php:348:           // @TODO crc32() is very weak, but it needs to be fast
-./application/hub/main/package/class_NetworkPackage.php:502:                   // @TODO We may want to do somthing more here?
-./application/hub/main/package/class_NetworkPackage.php:540:    * @todo        Unfinished area, signatures are currently NOT fully supported
-./application/hub/main/package/class_NetworkPackage.php:647:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:779:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:930:    * @todo        This may be enchanced for outgoing packages?
-./application/hub/main/package/class_NetworkPackage.php:961:            * @todo Unsupported feature of "signed" messages commented out
+./application/hub/main/package/class_NetworkPackage.php:287:           // @TODO crc32() is very weak, but it needs to be fast
+./application/hub/main/package/class_NetworkPackage.php:358:           // @TODO crc32() is very weak, but it needs to be fast
+./application/hub/main/package/class_NetworkPackage.php:512:                   // @TODO We may want to do somthing more here?
+./application/hub/main/package/class_NetworkPackage.php:550:    * @todo        Unfinished area, signatures are currently NOT fully supported
+./application/hub/main/package/class_NetworkPackage.php:657:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:789:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:940:    * @todo        This may be enchanced for outgoing packages?
+./application/hub/main/package/class_NetworkPackage.php:971:            * @todo Unsupported feature of "signed" messages commented out
 ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:275:      * @todo        Implement a way to send non-announcement packages with extra-salt
 ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:427:      * @todo        $helperInstance is unused
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106:                       // @TODO Do something with it