application/hub/exceptions/lists/class_ListGroupAlreadyAddedException.php svneol=native#text/plain
application/hub/exceptions/lists/class_NoListGroupException.php svneol=native#text/plain
application/hub/exceptions/package/.htaccess -text svneol=unset#text/plain
+application/hub/exceptions/package/class_FinalChunkVerificationException.php svneol=native#text/plain
application/hub/exceptions/package/class_UnexpectedPackageStatusException.php -text
+application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php svneol=native#text/plain
application/hub/exceptions/peer/.htaccess -text svneol=unset#text/plain
application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php svneol=native#text/plain
application/hub/exceptions/resolver/.htaccess svneol=native#text/plain
application/hub/interfaces/nodes/.htaccess -text svneol=unset#text/plain
application/hub/interfaces/nodes/class_NodeHelper.php svneol=native#text/plain
application/hub/interfaces/package/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/package/assembler/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/package/assembler/class_Assembler.php svneol=native#text/plain
application/hub/interfaces/package/class_Deliverable.php svneol=native#text/plain
application/hub/interfaces/package/fragmenter/.htaccess -text svneol=unset#text/plain
application/hub/interfaces/pool/.htaccess -text svneol=unset#text/plain
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/assembler/.htaccess -text svneol=unset#text/plain
+application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.php svneol=native#text/plain
application/hub/main/factories/package/class_NetworkPackageFactory.php svneol=native#text/plain
+application/hub/main/factories/package/fragmenter/.htaccess -text
application/hub/main/factories/producer/.htaccess -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/nodes/regular/.htaccess -text svneol=unset#text/plain
application/hub/main/nodes/regular/class_HubRegularNode.php svneol=native#text/plain
application/hub/main/package/.htaccess -text svneol=unset#text/plain
+application/hub/main/package/assembler/.htaccess -text svneol=unset#text/plain
+application/hub/main/package/assembler/class_PackageAssembler.php svneol=native#text/plain
application/hub/main/package/class_NetworkPackage.php svneol=native#text/plain
application/hub/main/package/fragmenter/.htaccess -text svneol=unset#text/plain
application/hub/main/pools/.htaccess -text svneol=unset#text/plain
// CFG: PACKAGE-FRAGMENTER-CLASS
$cfg->setConfigEntry('package_fragmenter_class', 'PackageFragmenter');
+// CFG: PACKAGE-ASSEMBLER-CLASS
+$cfg->setConfigEntry('package_assembler_class', 'PackageAssembler');
+
// CFG: PACKAGE-CHUNK-SIZE
$cfg->setConfigEntry('package_chunk_size', 256*8);
--- /dev/null
+<?php
+/**
+ * This exception is thrown when the final (last) chunks does not contain the
+ * "End-Of-Package-Identifier".
+ *
+ * @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 FinalChunkVerificationException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Raw content: %s, total chunks: %s",
+ $messageArray[0]->__toString(),
+ $this->getLine(),
+ $messageArray[2][count($messageArray[2]) - 1],
+ PackageFragmenter::END_OF_PACKAGE_IDENTIFIER,
+ $messageArray[1][BaseRawDataHandler::PACKAGE_DECODED_DATA]
+ count($messageArray[2])
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * This exception is thrown when an unexpected package status was detected.
+ *
+ * @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 UnsupportedPackageCodeHandlerException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf("[%s:%d] Unsupported package code handler %s for package code %s detected.",
+ $messageArray[0]->__toString(),
+ $this->getLine(),
+ $messageArray[2],
+ $messageArray[1][BaseRawDataHandler::PACKAGE_ERROR_CODE]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for a package assembler
+ *
+ * @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 Assembler extends FrameworkInterface {
+ /**
+ * Assembles the content from $packageContent into a raw package data array.
+ * This method may throw exceptions if some checks fails.
+ *
+ * @param $packageContent An array with two elements: 'decoded_data' and 'error_code'
+ * @return $packageData A valid raw package data array
+ */
+ function assemblePackageDataArrayFromContent (array $packageContent);
+}
+
+// [EOF]
+?>
* method is not found, a generic one is used.
*
* @param $errorCode Error code from socket_last_error()
- * @return $methodName Call-back method name for the error handler
+ * @return $handlerName Call-back method name for the error handler
* @throws UnsupportedSocketErrorHandlerException If the error handler is not implemented
*/
protected function getSocketErrorHandlerFromCode ($errorCode) {
<?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 $fragmenterType The fragmenter's type
- * @return $fragmenterInstance A fragmenter instance
- */
- public static final function createFragmenterInstance ($fragmenterType) {
- // If there is no fragmenter?
- if (Registry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
- // Get fragmenter from registry
- $fragmenterInstance = Registry::getRegistry()->getInstance($fragmenterType . '_fragmenter');
- } else {
- // Get the fragmenter instance
- $fragmenterInstance = self::createObjectByConfiguredName($fragmenterType . '_fragmenter_class');
-
- // Add it to the registry
- Registry::getRegistry()->addInstance($fragmenterType . '_fragmenter', $fragmenterInstance);
- }
-
- // Return the instance
- return $fragmenterInstance;
- }
-}
-
-// [EOF]
+// @DEPRECATED
?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for package assembler
+ *
+ * @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 PackageAssemblerFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton assembler instance. If no instance is found, it fill
+ * be generated and stored in registry, else the assembler from the
+ * registry will be returned.
+ *
+ * @return $assemblerInstance An assembler instance
+ */
+ public static final function createAssemblerInstance () {
+ // If there is no assembler?
+ if (Registry::getRegistry()->instanceExists('package_assembler')) {
+ // Get assembler from registry
+ $assemblerInstance = Registry::getRegistry()->getInstance('package_assembler');
+ } else {
+ // Get the assembler instance
+ $assemblerInstance = self::createObjectByConfiguredName('package_assembler_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('package_assembler', $assemblerInstance);
+ }
+
+ // Return the instance
+ return $assemblerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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 $fragmenterType The fragmenter's type
+ * @return $fragmenterInstance A fragmenter instance
+ */
+ public static final function createFragmenterInstance ($fragmenterType) {
+ // If there is no fragmenter?
+ if (Registry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
+ // Get fragmenter from registry
+ $fragmenterInstance = Registry::getRegistry()->getInstance($fragmenterType . '_fragmenter');
+ } else {
+ // Get the fragmenter instance
+ $fragmenterInstance = self::createObjectByConfiguredName($fragmenterType . '_fragmenter_class');
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance($fragmenterType . '_fragmenter', $fragmenterInstance);
+ }
+
+ // Return the instance
+ return $fragmenterInstance;
+ }
+}
+
+// [EOF]
+?>
*/
class BaseListener extends BaseHubSystem implements Visitable {
// Exception code constants
- const EXCEPTION_INVALID_SOCKET = 0xa00;
- const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01;
- const EXCEPTION_SOCKET_CREATION_FAILED = 0xa02;
- const EXCEPTION_NO_SOCKET_ERROR = 0xa03;
- const EXCEPTION_CONNECTION_ALREADY_REGISTERED = 0xa04;
- const EXCEPTION_UNEXPECTED_PACKAGE_STATUS = 0xa05;
+ const EXCEPTION_INVALID_SOCKET = 0xa00;
+ const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01;
+ const EXCEPTION_SOCKET_CREATION_FAILED = 0xa02;
+ const EXCEPTION_NO_SOCKET_ERROR = 0xa03;
+ const EXCEPTION_CONNECTION_ALREADY_REGISTERED = 0xa04;
+ const EXCEPTION_UNEXPECTED_PACKAGE_STATUS = 0xa05;
+ const EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER = 0xa06;
/**
* Used protocol (Default: invalid, which is indeed invalid...)
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageAssembler class to assemble a package content stream fragemented
+ * by PackageFragmenter back to a raw package data array.
+ *
+ * @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 PackageAssembler extends BaseFrameworkSystem implements Assembler, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $assemblerInstance An instance of a Fragmentable class
+ */
+ public static final function createPackageAssembler () {
+ // Get new instance
+ $assemblerInstance = new PackageAssembler();
+
+ // Return the prepared instance
+ return $assemblerInstance;
+ }
+
+ /**
+ * Assembles the content from $packageContent. This method does only
+ * initialize the whole process by creating a call-back which will then
+ * itself (99.9% of all cases) "explode" the decoded data stream and add
+ * it to a chunk assembler queue.
+ *
+ * If the call-back method or this would attempt to assemble the package
+ * chunks and (maybe) re-request some chunks from the sender, this would
+ * take to much time and therefore slow down this node again.
+ *
+ * @param $packageContent An array with two elements: 'decoded_data' and 'error_code'
+ * @return void
+ * @throws UnsupportedPackageCodeHandlerException If the package code handler is not implemented
+ */
+ public function assemblePackageDataArrayFromContent (array $packageContent) {
+ // Validate the package content array again
+ assert(
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_DECODED_DATA])) &&
+ (isset($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
+ );
+
+ // Construct call-back name from package error code
+ $methodName = 'handlePackageBy' . $this->convertToClassName($packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]);
+
+ // Abort if the call-back method is not there
+ if (!method_exists($this, $methodName)) {
+ // Throw an exception
+ throw new UnsupportedPackageCodeHandlerException(array($this, $packageContent, $methodName), BaseListener::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
+ } // END - if
+
+ // Call it back
+ call_user_func(array($this, $methodName), $packageContent);
+ }
+
+ /**
+ * Call-back handler to handle unhandled packages
+ *
+ * @param $packageContent An array with two elements: 'decoded_data' and 'error_code'
+ * @return void
+ * @throws FinalChunkVerificationException If the final chunk does not start with 'EOP:'
+ */
+ private function handlePackageByUnhandledPackage (array $packageContent) {
+ /*
+ * "explode" the string from 'decoded_data' with chunk separator to
+ * get an array of chunks. These chunks must then be verified by
+ * their checksums. Also the final chunk must be handled.
+ */
+ $chunks = explode(PackageFragmenter::CHUNK_SEPARATOR, $packageContent[BaseRawDataHandler::PACKAGE_DECODED_DATA]);
+
+ // Validate final chunk
+ if (substr($chunks[count($chunks) - 1], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) {
+ // Last chunk is not valid
+ throw new FinalChunkVerificationException(array($this, $packageContent, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+ } // END - if
+
+ die('chunks='.print_r($chunks,true));
+ }
+}
+
+// [EOF]
+?>
$decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING);
// Make sure both array elements are there
- assert((is_array($decodedData)) && (isset($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA])) && (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE])));
+ assert(
+ (is_array($decodedData)) &&
+ (isset($decodedData[BaseRawDataHandler::PACKAGE_DECODED_DATA])) &&
+ (isset($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]))
+ );
/*
* Also make sure the error code is SOCKET_ERROR_UNHANDLED because we
/**
* Assembles incoming decoded data so it will become an abstract network
- * package again.
+ * package again. The assembler does later do it's job by an other task,
+ * not this one to keep best speed possible.
*
* @return void
*/
public function assembleDecodedDataToPackage () {
// Make sure the raw decoded package data is handled
assert($this->isIncomingDecodedDataHandled());
- $this->getStackerInstance()->debugInstance();
- $this->partialStub('Please implement this method.');
+
+ // Get current package content (an array with two elements; see handleIncomingDecodedData() for details)
+ $packageContent = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECODED_HANDLED);
+
+ // Get a package assembler instance from factory
+ $assemblerInstance = PackageAssemblerFactory::createAssemblerInstance();
+
+ // Start assembling the raw package data array
+ $assemblerInstance->assemblePackageDataArrayFromContent($packageContent);
+ die(__METHOD__.': BACK!' . chr(10));
}
/**
public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
// Is this package already fragmented?
if (!$this->isPackageProcessed($packageData)) {
+ // Remove package status, the recipient doesn't need this
+ unset($packageData[NetworkPackage::PACKAGE_DATA_STATUS]);
+
// First we need to "implode" the array
$rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData);
*
* @param $finalHash Final hash for faster lookup
* @return $rawDataChunk Raw package data chunk
+ * @throws AssertionException If $finalHash was not 'true'
*/
public function getNextRawDataChunk ($finalHash) {
try {