]> git.mxchange.org Git - hub.git/commitdiff
New singleton-factories introduced:
authorRoland Häder <roland@mxchange.org>
Mon, 18 Apr 2011 18:25:40 +0000 (18:25 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 18 Apr 2011 18:25:40 +0000 (18:25 +0000)
- Two new registry-based singleton-factories introduced:
  + The FragmenterFactory produces singleton fragmenter instances
  + The ProducerFactory produces singleton producer instance of different types
- Rewritten the code that Base64 encoding is now transparently implemented
  around the socket_write/read() functions. So all data is now being
  transparently transfered to other peers in Base64 encoding.
- Further renames of the package streamer classes to raw-data streamers
- Minor improvements here and there
- TODOs.txt updated

29 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/handler/network/class_Networkable.php
application/hub/interfaces/helper/connections/.htaccess [new file with mode: 0644]
application/hub/interfaces/helper/connections/class_ConnectionHelper.php [new file with mode: 0644]
application/hub/main/factories/fragmenter/.htaccess [new file with mode: 0644]
application/hub/main/factories/fragmenter/class_FragmenterFactory.php [new file with mode: 0644]
application/hub/main/factories/producer/.htaccess [new file with mode: 0644]
application/hub/main/factories/producer/class_ProducerFactory.php [new file with mode: 0644]
application/hub/main/handler/network/class_BaseNetworkPackageHandler.php
application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php
application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php
application/hub/main/helper/connection/class_ [new file with mode: 0644]
application/hub/main/helper/connection/class_BaseConnectionHelper.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/package/fragmenter/class_PackageFragmenter.php
application/hub/main/streams/package/input/class_PackageInputStream.php
application/hub/main/streams/package/output/class_PackageOutputStream.php
application/hub/main/streams/raw_data/.htaccess [new file with mode: 0644]
application/hub/main/streams/raw_data/input/.htaccess [new file with mode: 0644]
application/hub/main/streams/raw_data/input/class_RawDataInputStream.php [new file with mode: 0644]
application/hub/main/streams/raw_data/output/.htaccess [new file with mode: 0644]
application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php [new file with mode: 0644]
application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php
application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php
docs/TODOs.txt

index f94e47e869566167d15d3405c53949697fcf1f48..7d10afbd6681d72e1ee23f6828e59250f386a49f 100644 (file)
@@ -46,6 +46,8 @@ application/hub/interfaces/handler/network/class_Networkable.php -text svneol=un
 application/hub/interfaces/handler/task/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/handler/task/class_HandleableTask.php -text svneol=unset#text/plain
 application/hub/interfaces/helper/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/helper/connections/.htaccess -text
+application/hub/interfaces/helper/connections/class_ConnectionHelper.php -text
 application/hub/interfaces/helper/hub/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/helper/hub/class_HelpableHub.php svneol=native#text/plain
 application/hub/interfaces/helper/messages/.htaccess svneol=native#text/plain
@@ -184,10 +186,14 @@ application/hub/main/factories/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/discovery/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/discovery/class_PackageDiscoveryFactory.php svneol=native#text/plain
 application/hub/main/factories/discovery/class_SocketDiscoveryFactory.php svneol=native#text/plain
+application/hub/main/factories/fragmenter/.htaccess -text
+application/hub/main/factories/fragmenter/class_FragmenterFactory.php -text
 application/hub/main/factories/lists/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/lists/class_RecipientListFactory.php svneol=native#text/plain
 application/hub/main/factories/package/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/package/class_NetworkPackageFactory.php svneol=native#text/plain
+application/hub/main/factories/producer/.htaccess -text
+application/hub/main/factories/producer/class_ProducerFactory.php -text
 application/hub/main/factories/socket/.htaccess -text svneol=unset#text/plain
 application/hub/main/factories/socket/class_SocketFactory.php svneol=native#text/plain
 application/hub/main/factories/source/.htaccess svneol=native#text/plain
@@ -286,6 +292,7 @@ application/hub/main/handler/tasks/.htaccess -text svneol=unset#text/plain
 application/hub/main/handler/tasks/class_TaskHandler.php -text svneol=unset#text/plain
 application/hub/main/helper/.htaccess -text svneol=unset#text/plain
 application/hub/main/helper/connection/.htaccess -text svneol=unset#text/plain
+application/hub/main/helper/connection/class_ -text
 application/hub/main/helper/connection/class_BaseConnectionHelper.php svneol=native#text/plain
 application/hub/main/helper/connection/tcp/.htaccess -text svneol=unset#text/plain
 application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php svneol=native#text/plain
@@ -466,6 +473,11 @@ application/hub/main/streams/package/input/.htaccess svneol=native#text/plain
 application/hub/main/streams/package/input/class_PackageInputStream.php -text
 application/hub/main/streams/package/output/.htaccess svneol=native#text/plain
 application/hub/main/streams/package/output/class_PackageOutputStream.php svneol=native#text/plain
+application/hub/main/streams/raw_data/.htaccess svneol=native#text/plain
+application/hub/main/streams/raw_data/input/.htaccess svneol=native#text/plain
+application/hub/main/streams/raw_data/input/class_RawDataInputStream.php -text
+application/hub/main/streams/raw_data/output/.htaccess svneol=native#text/plain
+application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php svneol=native#text/plain
 application/hub/main/tags/.htaccess -text svneol=unset#text/plain
 application/hub/main/tags/class_ -text svneol=unset#text/plain
 application/hub/main/tags/class_BaseTags.php svneol=native#text/plain
index 56d04545bc5485efc0eb7e9420de0542602edde7..456bfedf6cbd529387c3c947c20b068be3642f64 100644 (file)
@@ -567,15 +567,19 @@ $cfg->setConfigEntry('external_ip', '');
 // CFG: PACKAGE-FRAGMENTER-CLASS
 $cfg->setConfigEntry('package_fragmenter_class', 'PackageFragmenter');
 
-// CFG: NODE-RAW-PACKAGE-OUTPUT-STREAM
-$cfg->setConfigEntry('node_raw_package_output_stream', 'PackageOutputStream');
-
-// CFG: NODE-RAW-PACKAGE-INPUT-STREAM
-$cfg->setConfigEntry('node_raw_package_input_stream', 'PackageInputStream');
-
 // CFG: PACKAGE-CHUNK-SIZE
 $cfg->setConfigEntry('package_chunk_size', 256*8);
 
+// CFG: NODE-RAW-DATA-OUTPUT-STREAM-CLASS
+$cfg->setConfigEntry('node_raw_data_output_stream_class', 'RawDataOutputStream');
+
+// CFG: NODE-RAW-DATA-INPUT-STREAM-CLASS
+$cfg->setConfigEntry('node_raw_data_input_stream_class', 'RawDataInputStream');
+
+///////////////////////////////////////////////////////////////////////////////
+//                        Cruncher Configuration
+///////////////////////////////////////////////////////////////////////////////
+
 // CFG: CRUNCHER-TEST-UNITS-ENABLED
 $cfg->setConfigEntry('cruncher_test_units_enabled', 'Y');
 
index f3611a06968370006d89cb918657d3fb5510876b..12b1ad2ada159cd6c3a945b380b9998aa1022fdb 100644 (file)
  */
 interface Networkable extends Handleable {
        /**
-        * Processes a package from given resource. This is mostly useful for TCP
+        * Processes raw data from given resource. This is mostly useful for TCP
         * package handling and is implemented in the TcpListener class
         *
         * @param       $resource       A valid resource identifier
         * @return      void
         * @throws      InvalidResourceException        If the given resource is invalid
         */
-       function processResourcePackage ($resource);
+       function processResourceRawData ($resource);
 }
 
 // [EOF]
diff --git a/application/hub/interfaces/helper/connections/.htaccess b/application/hub/interfaces/helper/connections/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php
new file mode 100644 (file)
index 0000000..947899c
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * An interface for connection helper classes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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/>.
+ */
+interface ConnectionHelper extends Helper {
+       /**
+        * Sends raw package data to the recipient
+        *
+        * @param       $packageData            Raw package data
+        * @return      $totalSentBytes         Total sent bytes to the peer
+        * @throws      InvalidSocketException  If we got a problem with this socket
+        */
+       function sendRawPackageData (array $packageData);
+
+       /**
+        * Checks wether the connect retry is exhausted
+        *
+        * @return      $isExhaused             Wether connect retry is exchausted
+        */
+       function isConnectRetryExhausted ();
+
+       /**
+        * Do the shutdown sequence for this connection helper
+        *
+        * @todo        We may want to implement a filter for ease notification of other objects like our pool
+        * @return      void
+        * @throws      SocketShutdownException         If the current socket could not be shut down
+        */
+       function doShutdown ();
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/factories/fragmenter/.htaccess b/application/hub/main/factories/fragmenter/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/fragmenter/class_FragmenterFactory.php b/application/hub/main/factories/fragmenter/class_FragmenterFactory.php
new file mode 100644 (file)
index 0000000..7e1a015
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A factory class for fragmenter
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 FragmenterFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton fragmenter instance. If no instance is found, it fill
+        * be generated and stored in registry, else the fragmenter from the
+        * registry will be returned.
+        *
+        * @param       $configEntry                    A configuration entry naming the real class' name
+        * @return      $fragmenterInstance             A fragmenter instance
+        */
+       public static final function createFragmenterInstance ($configEntry) {
+               // If there is no fragmenter?
+               if (Registry::getRegistry()->instanceExists('fragmenter')) {
+                       // Get fragmenter from registry
+                       $fragmenterInstance = Registry::getRegistry()->getInstance('fragmenter');
+               } else {
+                       // Get the fragmenter instance
+                       $fragmenterInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance('fragmenter', $fragmenterInstance);
+               }
+
+               // Return the instance
+               return $fragmenterInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/factories/producer/.htaccess b/application/hub/main/factories/producer/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/producer/class_ProducerFactory.php b/application/hub/main/factories/producer/class_ProducerFactory.php
new file mode 100644 (file)
index 0000000..d952b25
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/**
+ * A factory class for producer
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 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 FragmenterFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton producer instance. If no instance is found, it fill
+        * be generated and stored in registry, else the producer from the
+        * registry will be returned.
+        *
+        * @param       $configEntry            A configuration entry naming the real class' name
+        * @parasm      $producerType           Type of the producer, can be 'key', 'test_unit', etc.
+        * @return      $producerInstance       A producer instance
+        */
+       public static final function createProducerInstance ($configEntry, $producerType) {
+               // If there is no producer?
+               if (Registry::getRegistry()->instanceExists($producerType . '_producer')) {
+                       // Get producer from registry
+                       $producerInstance = Registry::getRegistry()->getInstance($producerType . '_producer');
+               } else {
+                       // Get the producer instance
+                       $producerInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance($producerType . '_producer', $producerInstance);
+               }
+
+               // Return the instance
+               return $producerInstance;
+       }
+}
+
+// [EOF]
+?>
index 6f910f27660b954b18ddbda8a27598011c9298c4..5599cbd38637b940f5f24aaac02d4a7459e98cea 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseNetworkPackageHandler extends BaseHandler {
-       // Error codes
-       const SOCKET_ERROR_UNKNOWN             = 'unknown_error';
-       const SOCKET_ERROR_TRANSPORT_ENDPOINT  = 'transport_endpoint';
-       const SOCKET_ERROR_UNHANDLED           = 'unhandled_package';
-       const SOCKET_ERROR_EMPTY_DATA          = 'empty_data';
-       const PACKAGE_ERROR_INVALID_DATA       = 'invalid_data';
-       const PACKAGE_ERROR_INCOMPLETE_DATA    = 'incomplete_data';
-       const PACKAGE_ERROR_INVALID_CONTENT    = 'invalid_content';
-       const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error';
-       const PACKAGE_LEVEL_CHECK_OKAY         = 'checked_package';
+       // Error codes:
+       // - Socket raw data stream errors
+       const SOCKET_ERROR_UNKNOWN                = 'unknown_error';      // Unknown error (should not happen)
+       const SOCKET_ERROR_TRANSPORT_ENDPOINT     = 'transport_endpoint'; // Transport endpoint has closed
+       const SOCKET_ERROR_EMPTY_DATA             = 'empty_data';         // Other peer has sent nothing
+       const SOCKET_ERROR_INVALID_BASE64_MODULO  = 'base64_modulo';      // Length is not modulo 4
+       const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message';     // Raw data is not Base64-encoded
+       const SOCKET_ERROR_UNHANDLED              = 'unhandled_package';  // Unhandled raw data (not bad)
+
+       // - Package errors
+       const PACKAGE_ERROR_INVALID_DATA         = 'invalid_data';    // Invalid data in package found
+       const PACKAGE_ERROR_INCOMPLETE_DATA      = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+       const PACKAGE_ERROR_INVALID_CONTENT      = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+       const PACKAGE_ERROR_RECIPIENT_MISMATCH   = 'recipient_error'; // Recipient is not us
+       const PACKAGE_LEVEL_CHECK_OKAY           = 'checked_package'; // Package is fine
 
        /**
         * Error code from socket
@@ -47,6 +52,12 @@ class BaseNetworkPackageHandler extends BaseHandler {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
+
+               // Get an input stream instance
+               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_input_stream_class', array($this));
+
+               // Set it in this network-package handler
+               $this->setInputStreamInstance($streamInstance);
        }
 
        /**
index 61a9a941ec7707504d14e73dc8ddb036c4329a9c..7b644f83bc754286c5d4f0d95680672ddf836081 100644 (file)
@@ -44,45 +44,39 @@ class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw
                // Get new instance
                $handlerInstance = new TcpNetworkPackageHandler();
 
-               // Initialize new resolver instance
-               $resolverInstance = ObjectFactory::createObjectByConfiguredName('network_state_resolver_class');
-
-               // Set it in this class
-               $handlerInstance->setResolverInstance($resolverInstance);
-
                // Return the prepared instance
                return $handlerInstance;
        }
 
        /**
-        * Processes a package from given resource. This is mostly useful for TCP
+        * Processes raw data from given resource. This is mostly useful for TCP
         * package handling and is implemented in the TcpListener class
         *
         * @param       $resource       A valid resource identifier
         * @return      void
-        * @todo        We need to handle the raw data over to the NetworkPackage class if the state if fine
         */
-       public function processResourcePackage ($resource) {
+       public function processResourceRawData ($resource) {
                // Check the resource
                if (!is_resource($resource)) {
                        // Throw an exception
                        throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                } // END - if
 
-               // Init package data array
-               $packageData = array();
-
                // Reset error code to unhandled
                $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
 
                // Debug message
-               $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
+               //* NOISY-DEBUG: */ $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource);
 
-               // Read the raw data from socket
+               /*
+                * Read the raw data from socket. If you change PHP_BINARY_READ to
+                * PHP_NORMAL_READ, this line will endless block. We only have
+                * simultanous threads and no real threads.
+                */
                $rawData = socket_read($resource, $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
 
                // Debug output of read data length
-               $this->debugOutput('rawData[]=' . strlen($rawData));
+               //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: rawData[]=' . strlen($rawData));
 
                // Is it valid?
                if (($rawData === false) || (socket_last_error($resource) > 0)) {
@@ -91,11 +85,15 @@ class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw
                } elseif (empty($rawData)) {
                        // The peer did send nothing to us
                        $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
-               }
+               } else {
+                       // Low-level checks of the raw data went all fine, we can now decode the raw data
+                       $decodedData = $this->getInputStreamInstance()->streamData($rawData);
 
-               // Get a state from the resolver for this package data array
-               $stateInstance = $this->getResolverInstance()->resolveStateByPackage($this, $packageData, $resource);
-               die('UNFINISHED:'.$stateInstance->__toString()."\n");
+                       // Is the decoded data false, then streamData() could not validate it
+                       if ($decodedData !== false) {
+                               die('decodedData(' . strlen($decodedData) . ')=' . $decodedData . "\n");
+                       } // END - if
+               }
        }
 }
 
index 60f6fbe4707902c50c429503033ac3a03590491d..84e98fcb6262f6a182407ffe17a064b0ed6b8b08 100644 (file)
@@ -49,7 +49,7 @@ class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw
        }
 
        /**
-        * Processes a package from given resource. This is mostly useful for TCP
+        * Processes raw data from given resource. This is mostly useful for TCP
         * package handling and is implemented in the TcpListener class
         *
         * @param       $resource       A valid resource identifier
@@ -57,7 +57,7 @@ class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw
         * @throws      InvalidResourceException        If the given resource is invalid
         * @todo        0%
         */
-       public function processResourcePackage ($resource) {
+       public function processResourceRawData ($resource) {
                // Check the resource
                if (!is_resource($resource)) {
                        // Throw an exception
@@ -65,7 +65,7 @@ class UdpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw
                } // END - if
 
                // Implement processing here
-               $this->partialStub('Please implement this method.');
+               $this->partialStub('Please implement this method. resource=' . $resource);
        }
 }
 
diff --git a/application/hub/main/helper/connection/class_ b/application/hub/main/helper/connection/class_
new file mode 100644 (file)
index 0000000..3ef3ad9
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * A ??? connection helper class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ * @todo               Find an interface for hub helper
+ *
+ * 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 ???ConnectionHelper extends BaseConnectionHelper implements ConnectionHelper {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set protocol
+               $this->setProtocol('!!!');
+       }
+
+       /**
+        * Creates a socket resource ("connection") for given recipient in package data
+        *
+        * @param       $packageData            Raw package data
+        * @return      $socketResource         Socket resource
+        */
+       public static function createConnectionFromPackageData (array $packageData) {
+               die();
+       }
+}
+
+// [EOF]
+?>
index c88e89e53d49d298ac1acf3e3a053c424034cece..c1a21b6ca0df48e9f6da0cc8e7bc66dfaba2c039 100644 (file)
@@ -79,6 +79,12 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
 
                // Register this connection helper
                Registry::getRegistry()->addInstance('connection', $this);
+
+               // Initialize output stream
+               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_output_stream_class');
+
+               // And add it to this connection helper
+               $this->setOutputStreamInstance($streamInstance);
        }
 
        /**
@@ -154,17 +160,8 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
         * @return      $chunkData              Raw data chunk
         */
        private function getRawDataFromPackageArray (array $packageData) {
-               // If there is no fragmenter?
-               if (!Registry::getRegistry()->instanceExists('package_fragmenter')) {
-                       // Get the fragmenter instance
-                       $fragmenterInstance = ObjectFactory::createObjectByConfiguredName('package_fragmenter_class');
-
-                       // Add it to the registry
-                       Registry::getRegistry()->addInstance('package_fragmenter', $fragmenterInstance);
-               } else {
-                       // Get fragmenter from registry
-                       $fragmenterInstance = Registry::getRegistry()->getInstance('package_fragmenter');
-               }
+               // Get the fragmenter instance
+               $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package_fragmenter_class');
 
                // Implode the package data array and fragement the resulting string, returns the final hash
                $finalHash = $fragmenterInstance->fragmentPackageArray($packageData, $this);
@@ -219,8 +216,8 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
 
                // Init variables
-               $rawData = '';
-               $dataStream = ' ';
+               $rawData        = '';
+               $dataStream     = ' ';
                $totalSentBytes = 0;
 
                // Fill sending buffer with data
@@ -234,8 +231,11 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                // Nothing to sent is bad news!
                assert(strlen($rawData) > 0);
 
+               // Encode the raw data with our output-stream
+               $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
+
                // Calculate difference
-               $this->diff = $bufferSize - strlen($rawData);
+               $this->diff = $bufferSize - strlen($encodedData);
 
                // Get socket resource
                $socketResource = $this->getSocketResource();
@@ -246,8 +246,8 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                // Deliver all data
                while ($sentBytes !== false) {
                        // And deliver it
-                       //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($rawData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
-                       $sentBytes = @socket_write($socketResource, $rawData, ($bufferSize - $this->diff));
+                       //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
+                       $sentBytes = @socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
 
                        // If there was an error, we don't continue here
                        if ($sentBytes === false) {
@@ -262,27 +262,27 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
 
                                // And throw it
                                throw new InvalidSocketException(array($this, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
-                       } elseif (($sentBytes == 0) && (strlen($rawData) > 0)) {
+                       } elseif (($sentBytes == 0) && (strlen($encodedData) > 0)) {
                                // Nothing sent means we are done
                                //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (' . __LINE__ . ')');
                                break;
                        }
 
                        // The difference between sent bytes and length of raw data should not be below zero
-                       assert((strlen($rawData) - $sentBytes) >= 0);
+                       assert((strlen($encodedData) - $sentBytes) >= 0);
 
                        // Add total sent bytes
                        $totalSentBytes += $sentBytes;
 
                        // Cut out the last unsent bytes
-                       //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sent out ' . $sentBytes . ' of ' . strlen($rawData) . ' bytes ...');
-                       $rawData = substr($rawData, $sentBytes);
+                       //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...');
+                       $encodedData = substr($encodedData, $sentBytes);
 
                        // Calculate difference again
-                       $this->diff = $bufferSize - strlen($rawData);
+                       $this->diff = $bufferSize - strlen($encodedData);
 
                        // Can we abort?
-                       if (strlen($rawData) <= 0) {
+                       if (strlen($encodedData) <= 0) {
                                // Abort here, all sent!
                                //* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: All sent! (' . __LINE__ . ')');
                                break;
index 9d6b550150f86c4ff7b7599a51914ec03abb8809..947daad3521033831620e26eccb2a4bc5709700c 100644 (file)
@@ -22,7 +22,7 @@
  * 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 TcpConnectionHelper extends BaseConnectionHelper implements Helper {
+class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelper {
        /**
         * Protected constructor
         *
@@ -80,21 +80,6 @@ class TcpConnectionHelper extends BaseConnectionHelper implements Helper {
                        throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
-               // Now, we want non-blocking mode
-               if (!socket_set_nonblock($socketResource)) {
-                       // Get socket error code for verification
-                       $socketError = socket_last_error($socketResource);
-
-                       // Get error message
-                       $errorMessage = socket_strerror($socketError);
-
-                       // Shutdown this socket
-                       $helperInstance->shutdownSocket($socketResource);
-
-                       // And throw again
-                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
-               } // END - if
-
                // Set the resource
                $helperInstance->setSocketResource($socketResource);
 
@@ -129,16 +114,31 @@ class TcpConnectionHelper extends BaseConnectionHelper implements Helper {
                        }
                } // END - if
 
+               // Now, we want non-blocking mode
+               if (!socket_set_nonblock($socketResource)) {
+                       // Get socket error code for verification
+                       $socketError = socket_last_error($socketResource);
+
+                       // Get error message
+                       $errorMessage = socket_strerror($socketError);
+
+                       // Shutdown this socket
+                       $helperInstance->shutdownSocket($socketResource);
+
+                       // And throw again
+                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
                // Okay, that should be it. So return it...
                return $socketResource;
        }
 
        /**
-        * Do the shutdown sequence for TCP connections
+        * Do the shutdown sequence for this connection helper
         *
-        * @todo        We may want to implement a filter for ease notification of other objects like our pool
         * @return      void
         * @throws      SocketShutdownException         If the current socket could not be shut down
+        * @todo        We may want to implement a filter for ease notification of other objects like our pool
         */
        public function doShutdown () {
                // Clear any previous errors
index 01761f96a60d8e393ec2ac376b25a90bcc01f3c8..db230642b6a66287cf7eac7a7e0cf1686b9b094b 100644 (file)
@@ -22,7 +22,7 @@
  * 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 UdpConnectionHelper extends BaseConnectionHelper implements Helper {
+class UdpConnectionHelper extends BaseConnectionHelper implements ConnectionHelper {
        /**
         * Protected constructor
         *
@@ -43,7 +43,18 @@ class UdpConnectionHelper extends BaseConnectionHelper implements Helper {
         * @return      $socketResource         Socket resource
         */
        public static function createConnectionFromPackageData (array $packageData) {
-               die();
+               die(__METHOD__ . ': Unfinished method, packageData[]=' . count($packageData) . "\n");
+       }
+
+       /**
+        * Do the shutdown sequence for this connection helper
+        *
+        * @return      void
+        * @throws      SocketShutdownException         If the current socket could not be shut down
+        * @todo        We may want to implement a filter for ease notification of other objects like our pool
+        */
+       public function doShutdown () {
+               $this->partialStub('Please implement this method.');
        }
 }
 
index 54842ca6adea9ad504825348a4b420a089406b23..c972c1f5f6d6a156e33f1ae71ab38ce8e4f17141 100644 (file)
@@ -236,7 +236,7 @@ class TcpListener extends BaseListener implements Listenable {
                if ($currentSocket != $this->getSocketResource()) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
                        //* NOISY-DEBUG: */ $this->debugOutput('LISTENER: currentSocket=' . $currentSocket);
-                       $this->getPackageInstance()->processResourcePackage($currentSocket);
+                       $this->getPackageInstance()->processResourceRawData($currentSocket);
                } // END - if
 
                // Advance to next entry. This should be the last line
index 9a4ce15df1299ad6ad4c3ec5ec91a52ea0435269..192403e65a5f7eec40af8bbb988930cd2364fa8d 100644 (file)
@@ -51,6 +51,11 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
         */
        const PACKAGE_MASK_SEPERATOR = ':';
 
+       /**
+        * Seperator for checksum
+        */
+       const PACKAGE_CHECKSUM_SEPERATOR = ':';
+
        /**
         * Array indexes for above mask, start with zero
         */
@@ -152,15 +157,16 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
         * @param       $helperInstance         An instance of a BaseHubHelper class
         * @param       $nodeInstance           An instance of a NodeHelper class
         * @return      $hash   Hash for given package content
+        * @todo        $helperInstance is unused
         */
        private function getHashFromContent ($content, BaseHubHelper $helperInstance, NodeHelper $nodeInstance) {
                // Create the hash
-               // @TODO crc32 is not good, but it needs to be fast
+               // @TODO crc32 is not very strong, but it needs to be fast
                $hash = crc32(
                        $content .
-                       ':' .
+                       self::PACKAGE_CHECKSUM_SEPERATOR .
                        $nodeInstance->getSessionId() .
-                       ':' .
+                       self::PACKAGE_CHECKSUM_SEPERATOR .
                        $this->getCompressorInstance()->getCompressorExtension()
                );
 
index 1cf6db7ea45fbfe2e0fe52638c5eab910119d5dd..ca073ae07e356c9d5265cd16cb2c160182ba580c 100644 (file)
@@ -1,9 +1,15 @@
 <?php
 /**
  * A PackageFragmenter class to fragment package data into smaller chunks for
- * delivery. This class does add a serial number to it and in the first data
- * submission chunk it will add a sumerization of all fragements and their
- * serial numbers.
+ * delivery. This class calculates a final hash on the raw input data and
+ * fragments the data into smaller chunks after it has been encoded by a
+ * "outgoing encoding stream".
+ *
+ * All chunks are extended with a hash and a serial number to make it later
+ * easier to verify them and put them back in the right order and to, if
+ * required, request a re-delivery of an invalid chunk (e.g. hash didn't match).
+ * Also an "end-of-package" marker is being added as the last chunk to mark the
+ * end of of the whole package submission.
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -64,6 +70,7 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
         * Maximum possible serial number
         */
        private $maxSerialNumber  = 0;
+
        /**
         * Seperator between chunk data, serial number and chunk hash
         */
@@ -74,11 +81,21 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
         */
        const CHUNK_HASH_SEPERATOR = ';';
 
+       /**
+        * Seperator between two chunks
+        */
+       const CHUNK_SEPERATOR = '|';
+
        /**
         * Identifier for hash chunk
         */
        const HASH_CHUNK_IDENTIFIER = 'HASH-CHUNK:';
 
+       /**
+        * Identifier for end-of-package marker
+        */
+       const END_OF_PACKAGE_IDENTIFIER = 'EOP:';
+
        /**
         * Protected constructor
         *
@@ -101,12 +118,6 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                // Get new instance
                $fragmenterInstance = new PackageFragmenter();
 
-               // Get an output stream for all out-going packages
-               $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_package_output_stream');
-
-               // And set it in this fragmenter
-               $fragmenterInstance->setOutputStreamInstance($streamInstance);
-
                // And also a crypto instance (for our encrypted messages)
                $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
                $fragmenterInstance->setCryptoInstance($cryptoInstance);
@@ -287,16 +298,39 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                return $encodedSerialNumber;
        }
 
+       /**
+        * Appends an end-of-package chunk to the chunk list for given chunk and
+        * final hash.
+        *
+        * @param       $chunkHash      Last chunk's hash
+        * @param       $finalHash      Final hash for raw (unencoded) data
+        * @return      void
+        */
+       private function appendEndOfPackageChunk ($chunkHash, $finalHash) {
+               // Generate end-of-package marker
+               $rawData =
+                       self::END_OF_PACKAGE_IDENTIFIER .
+                       $finalHash . self::CHUNK_HASH_SEPERATOR .
+                       $chunkHash . self::CHUNK_SEPERATOR;
+
+               // Also get a hash from it
+               $chunkHash = $this->generateHashFromRawData($rawData);
+
+               // Append it to the chunk's data and hash array
+               $this->chunkHashes[$finalHash][] = $chunkHash;
+               $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
         * TCP package (512 bytes).
         *
-        * @param       $encodedData    Encoded data string
-        * @param       $finalHash              Final hash from the raw data
+        * @param       $rawData        Raw data string
+        * @param       $finalHash      Final hash from the raw data
         * @return      void
         */
-       private function splitEncodedDataIntoChunks ($encodedData, $finalHash) {
+       private function splitEncodedDataIntoChunks ($rawData, $finalHash) {
                // Make sure final hashes with at least 32 bytes can pass
                assert(strlen($finalHash) >= 32);
 
@@ -304,17 +338,24 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                $dataChunkSize = $this->getDataChunkSizeFromHash($finalHash);
                //* NOISY-DEBUG: */ $this->debugOutput('FRAGMENTER: dataChunkSize=' . $dataChunkSize);
 
+               // Init variables
+               $chunkHash = '';
+
                // Now split it up
-               for ($idx = 0; $idx < strlen($encodedData); $idx += $dataChunkSize) {
+               for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
                        // Get the next chunk
-                       $chunk = substr($encodedData, $idx, $dataChunkSize);
+                       $chunk = substr($rawData, $idx, $dataChunkSize);
 
                        // Hash it and remember it in seperate array
                        $chunkHash = $this->getCryptoInstance()->hashString($chunk);
                        $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;
+                       $chunk =
+                               $chunkHash . self::CHUNK_DATA_HASH_SEPERATOR .
+                               $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPERATOR .
+                               $chunk . self::CHUNK_SEPERATOR
+                       ;
 
                        // Make sure the chunk is not larger than a TCP package can hold
                        assert(strlen($chunk) <= NetworkPackage::TCP_PACKAGE_SIZE);
@@ -325,40 +366,44 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                } // END - for
 
                // Debug output
-               $this->debugOutput('FRAGMENTER: Encoded data of ' . strlen($encodedData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
+               //* NOISY-DEBUG: */ $this->debugOutput('FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
+
+               // Add end-of-package chunk
+               $this->appendEndOfPackageChunk($chunkHash, $finalHash);
        }
 
        /**
         * Prepends a chunk (or more) with all hashes from all chunks + final chunk.
         *
-        * @param       $encodedData    Encoded data string
-        * @param       $finalHash              Final hash from the raw data
+        * @param       $rawData        Raw data string
+        * @param       $finalHash      Final hash from the raw data
         * @return      void
         */
-       private function prependHashChunk ($encodedData, $finalHash) {
+       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]);
 
                // Also get a hash from it
                $chunkHash = $this->generateHashFromRawData($rawData);
 
-               // Also encode this one
-               $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
-
                // Calulcate chunk size
                $dataChunkSize = $this->getDataChunkSizeFromHash($chunkHash);
 
                // Now array_unshift() it to the two chunk arrays
-               for ($idx = 0; $idx < strlen($encodedData); $idx += $dataChunkSize) {
+               for ($idx = 0; $idx < strlen($rawData); $idx += $dataChunkSize) {
                        // Get the next chunk
-                       $chunk = substr($encodedData, $idx, $dataChunkSize);
+                       $chunk = substr($rawData, $idx, $dataChunkSize);
 
                        // Hash it and remember it in seperate array
                        $chunkHash = $this->getCryptoInstance()->hashString($chunk);
                        array_unshift($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;
+                       $chunk =
+                               $chunkHash . self::CHUNK_DATA_HASH_SEPERATOR .
+                               $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPERATOR .
+                               $chunk . self::CHUNK_SEPERATOR
+                       ;
 
                        // Make sure the chunk is not larger than a TCP package can hold
                        assert(strlen($chunk) <= NetworkPackage::TCP_PACKAGE_SIZE);
@@ -395,14 +440,11 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                        // Init pointer
                        $this->initPointer($finalHash);
 
-                       // Encode the package for delivery
-                       $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
-
                        // Split the encoded data into smaller chunks
-                       $this->splitEncodedDataIntoChunks($encodedData, $finalHash);
+                       $this->splitEncodedDataIntoChunks($rawData, $finalHash);
 
                        // Prepend a chunk with all hashes together
-                       $this->prependHashChunk($encodedData, $finalHash);
+                       $this->prependHashChunk($rawData, $finalHash);
 
                        // Mark the package as fragmented
                        $this->markPackageDataProcessed($packageData);
index aa9548f614ffb561cd8f1ae2e8ffc550258af4eb..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,65 +1,3 @@
 <?php
-/**
- * A PackageInputStream class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009  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 PackageInputStream extends BaseStream implements InputStreamable {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this node class
-        *
-        * @return      $streamInstance         An instance of this node class
-        */
-       public final static function createPackageInputStream () {
-               // Get a new instance
-               $streamInstance = new PackageInputStream();
-
-               // Return the instance
-               return $streamInstance;
-       }
-
-       /**
-        * Streams the data and maybe does something to it
-        *
-        * @param       $data   The data (string mostly) to "stream"
-        * @return      $data   The data (string mostly) to "stream"
-        * @todo        Do we need to do something more here?
-        */
-       public function streamData ($data) {
-               // Encode the data with BASE64 encoding
-               $data = base64_decode($data);
-
-               // Return it
-               return $data;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
index 35b382ae31b19b8c29c0e8676e3d3ccd94e92a1b..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,65 +1,3 @@
 <?php
-/**
- * A PackageOutputStream class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009  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 PackageOutputStream extends BaseStream implements OutputStreamable {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this node class
-        *
-        * @return      $streamInstance         An instance of this node class
-        */
-       public final static function createPackageOutputStream () {
-               // Get a new instance
-               $streamInstance = new PackageOutputStream();
-
-               // Return the instance
-               return $streamInstance;
-       }
-
-       /**
-        * Streams the data and maybe does something to it
-        *
-        * @param       $data   The data (string mostly) to "stream"
-        * @return      $data   The data (string mostly) to "stream"
-        * @todo        Do we need to do something more here?
-        */
-       public function streamData ($data) {
-               // Encode the data with BASE64 encoding
-               $data = base64_encode($data);
-
-               // Return it
-               return $data;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/streams/raw_data/.htaccess b/application/hub/main/streams/raw_data/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/streams/raw_data/input/.htaccess b/application/hub/main/streams/raw_data/input/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php b/application/hub/main/streams/raw_data/input/class_RawDataInputStream.php
new file mode 100644 (file)
index 0000000..c6b199e
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * A RawDataInputStream class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009  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 RawDataInputStream extends BaseStream implements InputStreamable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this node class
+        *
+        * @param       $handlerInstance        An instance of a Networkable class
+        * @return      $streamInstance         An instance of this node class
+        */
+       public final static function createRawDataInputStream (Networkable $handlerInstance) {
+               // Get a new instance
+               $streamInstance = new RawDataInputStream();
+
+               // Set the handler instance
+               $streamInstance->setHandlerInstance($handlerInstance);
+
+               // Return the instance
+               return $streamInstance;
+       }
+
+       /**
+        * Streams the data and maybe does something to it
+        *
+        * @param       $data   The data (string mostly) to "stream"
+        * @return      $data   The data (string mostly) to "stream"
+        * @todo        Do we need to do something more here?
+        */
+       public function streamData ($data) {
+               // Can it be validated?
+               if ((strlen($data) % 4) != 0) {
+                       // Length modulo 4 must be zero, else it is an invalid Base64 message
+                       $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MODULO);
+                       $data = false;
+               } elseif (!$this->isBase64Encoded($data)) {
+                       // Is not a valid Base64-encoded message
+                       $this->getHandlerInstance()->setErrorCode(BaseNetworkPackageHandler::SOCKET_ERROR_INVALID_BASE64_MESSAGE);
+                       $data = false;
+               } else {
+                       // Decode the data with BASE64-encoding
+                       $data = base64_decode($data);
+               }
+
+               // Return it
+               return $data;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/streams/raw_data/output/.htaccess b/application/hub/main/streams/raw_data/output/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php b/application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php
new file mode 100644 (file)
index 0000000..f9c61f4
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * A RawDataOutputStream class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009  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 RawDataOutputStream extends BaseStream implements OutputStreamable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this node class
+        *
+        * @return      $streamInstance         An instance of this node class
+        */
+       public final static function createRawDataOutputStream () {
+               // Get a new instance
+               $streamInstance = new RawDataOutputStream();
+
+               // Return the instance
+               return $streamInstance;
+       }
+
+       /**
+        * Streams the data and maybe does something to it
+        *
+        * @param       $data   The data (string mostly) to "stream"
+        * @return      $data   The data (string mostly) to "stream"
+        * @todo        Do we need to do something more here?
+        */
+       public function streamData ($data) {
+               // Encode the data with BASE64 encoding
+               $data = base64_encode($data);
+
+               // Return it
+               return $data;
+       }
+}
+
+// [EOF]
+?>
index 43673a23b01bd088b592f2435e61d3c98db22404..379011d14b19116e7af9a213c6eb3bd41b793178 100644 (file)
@@ -63,17 +63,8 @@ class CruncherKeyProducerTask extends BaseTask implements Taskable, Visitable {
         * @return      void
         */
        public function executeTask () {
-               // First we check if we already have an instance (which will happen at any later cyclus)
-               if (!Registry::getRegistry()->instanceExists('key_producer')) {
-                       // No instance found, so we need to create a producer instance
-                       $producerInstance = ObjectFactory::createObjectByConfiguredName('cruncher_key_producer_class');
-
-                       // ... and add it to the registry
-                       Registry::getRegistry()->addInstance('key_producer', $producerInstance);
-               } else {
-                       // Get the producer instance from registry
-                       $producerInstance = Registry::getRegistry()->getInstance('key_producer');
-               }
+               // Get the instance
+               $producerInstance = ProducerFactory::createProducerInstance('cruncher_key_producer_class', 'key');
 
                // Get the current cruncher state from registry
                $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
index f47f633e320c823fece58500797be538b77fb8c3..d3aa891d08bc280ba98978b6926b248109736b5c 100644 (file)
@@ -63,17 +63,8 @@ class CruncherTestUnitProducerTask extends BaseTask implements Taskable, Visitab
         * @return      void
         */
        public function executeTask () {
-               // First we check if we already have an instance (which will happen at any later cyclus)
-               if (!Registry::getRegistry()->instanceExists('test_unit_producer')) {
-                       // No instance found, so we need to create a producer instance
-                       $producerInstance = ObjectFactory::createObjectByConfiguredName('cruncher_test_unit_producer_class');
-
-                       // ... and add it to the registry
-                       Registry::getRegistry()->addInstance('test_unit_producer', $producerInstance);
-               } else {
-                       // Get the producer instance from registry
-                       $producerInstance = Registry::getRegistry()->getInstance('test_unit_producer');
-               }
+               // Get the producer instance
+               $producerInstance = ProducerFactory::createProducerInstance('cruncher_test_unit_producer_class', 'test_unit');
 
                // Get the current cruncher state from registry
                $stateInstance = Registry::getRegistry()->getInstance('cruncher')->getStateInstance();
index 2a05e280b54709fa9013edc345a4bc4114fcb407..6b47584a5bc0f9f2607bd4cdaaa99571f147e3fa 100644 (file)
@@ -1,6 +1,7 @@
 ### WARNING: THIS FILE IS AUTO-GENERATED BY ./todo-builder.sh ###
 ### DO NOT EDIT THIS FILE. ###
 ./application/hub/interfaces/cruncher/class_CruncherHelper.php:10: * @todo             We need to find a better name for this interface
+./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:44:  * @todo        We may want to implement a filter for ease notification of other objects like our pool
 ./application/hub/interfaces/nodes/class_NodeHelper.php:10: * @todo            We need to find a better name for this interface
 ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:104:        * @todo        Should we add some more filters?
 ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:58:         * @todo        Try to create a CruncherActivationTask or so
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php:55:         * @todo        0% 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/handler/network/tcp/class_TcpNetworkPackageHandler.php:96:       * @todo        ~10% done
 ./application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php:58:       * @todo        0%
 ./application/hub/main/handler/tasks/class_TaskHandler.php:140:                // @TODO Messurement can be added around this call
 ./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:10: * @todo         Find an interface for hub helper
-./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:139:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
+./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:141:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
 ./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:10: * @todo         Find an interface for hub helper
+./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:54:  * @todo        We may want to implement a filter for ease notification of other objects like our pool
 ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:10: * @todo               Find an interface for hub helper
 ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:61:        * @todo        Rewrite the ->renderXmlContent() call to no arguments
 ./application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php:10: * @todo                Find an interface for hub helper
 ./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:152:           // @TODO crc32 is not good, but it needs to be fast
-./application/hub/main/package/class_NetworkPackage.php:22: * @todo            Needs to add functionality for handling the object's type
-./application/hub/main/package/class_NetworkPackage.php:264:                   // @TODO We may want to do somthing more here?
-./application/hub/main/package/class_NetworkPackage.php:363:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:389:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:160:    * @todo        $helperInstance is unused
+./application/hub/main/package/class_NetworkPackage.php:164:           // @TODO crc32 is not very strong, but it needs to be fast
+./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:280:                   // @TODO We may want to do somthing more here?
+./application/hub/main/package/class_NetworkPackage.php:379:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:405:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:460:           // @TODO Add some content here
+./application/hub/main/package/class_NetworkPackage.php:469:           // @TODO Add some content here
+./application/hub/main/package/fragmenter/class_PackageFragmenter.php:426:      * @todo        $connectionInstance is unused
 ./application/hub/main/pools/peer/class_DefaultPeerPool.php:148:                       // @TODO Check for IP
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106:                       // @TODO Do something with it
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:62:         * @todo        Find something for init phase of this key producer
 ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:68:        * @todo        ~30% done
 ./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:80:                       // @TODO On some systems it is 134, on some 107?
 ./application/hub/main/states/node/init/class_NodeInitState.php:63:     * @todo        We might want to move some calls to this method to fill it with life
+./application/hub/main/streams/raw_data/input/class_RawDataInputStream.php:57:  * @todo        Do we need to do something more here?
+./application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php:53:        * @todo        Do we need to do something more here?
 ./application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php:53:     * @todo        Maybe visit some sub-objects
 ./application/hub/main/tasks/cruncher/class_CruncherTestUnitProducerTask.php:53:        * @todo        Maybe visit some sub-objects
 ./application/hub/main/tasks/cruncher/class_CruncherWorkUnitFetcherTask.php:54:         * @todo        Maybe visit some sub-objects
 ./application/hub/main/tasks/hub/announcement/class_HubSelfAnnouncementTask.php:53:     * @todo        0%
 ./application/hub/main/tasks/hub/class_HubSelfConnectTask.php:53:       * @todo        0%
+./application/hub/main/tasks/hub/class_HubSocketListenerTask.php:62:           // @TODO Do we need to visit this task? $visitorInstance->visitTask($this);
+./application/hub/main/tasks/hub/class_HubSocketListenerTask.php:69:    * @todo        0% done
 ./application/hub/main/tasks/hub/ping/class_HubPingTask.php:73:         * @todo        0% done
 ./application/hub/main/tasks/hub/update/class_HubUpdateCheckTask.php:53:        * @todo        0%
 ./application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php:10: * @todo               This template engine does not make use of setTemplateType()
 ./inc/classes/exceptions/main/class_MissingMethodException.php:13: * @todo             Try to rewrite user/guest login classes and mark this exception as deprecated
 ./inc/classes/exceptions/main/class_NoConfigEntryException.php:10: * @todo             Rename this class to NoFoundEntryException
 ./inc/classes/interfaces/class_FrameworkInterface.php:11: * @todo              Find a better name for this interface
-./inc/classes/main/class_BaseFrameworkSystem.php:1237:  * @todo        Write a logging mechanism for productive mode
-./inc/classes/main/class_BaseFrameworkSystem.php:1251:                 // @TODO Finish this part!
-./inc/classes/main/class_BaseFrameworkSystem.php:169:  // @todo Try to clean these constants up
-./inc/classes/main/class_BaseFrameworkSystem.php:408:   * @todo        SearchableResult and UpdateableResult shall have a super interface to use here
+./inc/classes/main/class_BaseFrameworkSystem.php:1253:  * @todo        Write a logging mechanism for productive mode
+./inc/classes/main/class_BaseFrameworkSystem.php:1267:                 // @TODO Finish this part!
+./inc/classes/main/class_BaseFrameworkSystem.php:185:  // @todo Try to clean these constants up
+./inc/classes/main/class_BaseFrameworkSystem.php:424:   * @todo        SearchableResult and UpdateableResult shall have a super interface to use here
 ./inc/classes/main/commands/web/class_WebLoginAreaCommand.php:64:       * @todo        Add some stuff here: Some personal data, app/game related data
 ./inc/classes/main/commands/web/class_WebProblemCommand.php:58:         * @todo        0% done
 ./inc/classes/main/commands/web/class_WebStatusCommand.php:58:  * @todo        0% done
 ./application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php:2:// @DEPRECATED
 ./application/hub/main/iterator/producer/class_TestUnitKeyProducerIterator.php:2:// @DEPRECATED
 ./application/hub/main/nodes/class_BaseHubNode.php:58:  * @deprecated
+./application/hub/main/streams/package/input/class_PackageInputStream.php:2:// @DEPRECATED
+./application/hub/main/streams/package/output/class_PackageOutputStream.php:2:// @DEPRECATED
 ./application/hub/main/template/announcement/class_AnnouncementTemplateEngine.php:2:// @DEPRECATED
 ./application/hub/main/template/connect/class_SelfConnectTemplateEngine.php:2:// @DEPRECATED
 ./application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php:2:// @DEPRECATED
 ./inc/classes/exceptions/main/class_MissingMethodException.php:14: * @deprecated       Please do no longer use this exception
 ./inc/classes/interfaces/helper/class_HelpableLogin.php:2:// @DEPRECATED
 ./inc/classes/interfaces/helper/class_HelpableTemplate.php:2:// @DEPRECATED
+./inc/classes/main/streams/input/class_BaseInputStream.php:2:// @DEPRECATED
+./inc/classes/main/streams/output/class_BaseOutputStream.php:2:// @DEPRECATED
 ./inc/classes.php:9: * @deprecated
 ./inc/database.php:10: * @deprecated
 ./inc/file_io.php:2:// @DEPRECATED