From fd7231cc8372a5289c405fe7ad2f8227a86362fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 11 Feb 2012 23:31:26 +0000 Subject: [PATCH] Removed package status from packageData array because recipients doesn't need this, moved (not really) fragmenter classes, added assembler class/interface, handling of undeclared package codes added (unfinished) --- .gitattributes | 9 ++ application/hub/config.php | 3 + .../class_FinalChunkVerificationException.php | 50 ++++++++ ...UnsupportedPackageCodeHandlerException.php | 47 ++++++++ .../interfaces/package/assembler/.htaccess | 1 + .../package/assembler/class_Assembler.php | 36 ++++++ application/hub/main/class_BaseHubSystem.php | 2 +- .../fragmenter/class_FragmenterFactory.php | 61 +--------- .../factories/package/assembler/.htaccess | 1 + .../class_PackageAssemblerFactory.php | 61 ++++++++++ .../factories/package/fragmenter/.htaccess | 1 + .../fragmenter/class_FragmenterFactory.php | 62 ++++++++++ .../hub/main/listener/class_BaseListener.php | 13 ++- .../hub/main/package/assembler/.htaccess | 1 + .../assembler/class_PackageAssembler.php | 109 ++++++++++++++++++ .../hub/main/package/class_NetworkPackage.php | 21 +++- .../fragmenter/class_PackageFragmenter.php | 4 + 17 files changed, 411 insertions(+), 71 deletions(-) create mode 100644 application/hub/exceptions/package/class_FinalChunkVerificationException.php create mode 100644 application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php create mode 100644 application/hub/interfaces/package/assembler/.htaccess create mode 100644 application/hub/interfaces/package/assembler/class_Assembler.php create mode 100644 application/hub/main/factories/package/assembler/.htaccess create mode 100644 application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.php create mode 100644 application/hub/main/factories/package/fragmenter/.htaccess create mode 100644 application/hub/main/factories/package/fragmenter/class_FragmenterFactory.php create mode 100644 application/hub/main/package/assembler/.htaccess create mode 100644 application/hub/main/package/assembler/class_PackageAssembler.php diff --git a/.gitattributes b/.gitattributes index 906de4510..b6aa3f2cc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -17,7 +17,9 @@ application/hub/exceptions/lists/class_InvalidListHashException.php svneol=nativ 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 @@ -70,6 +72,8 @@ application/hub/interfaces/messages/class_MessageHelper.php svneol=native#text/p 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 @@ -196,7 +200,10 @@ application/hub/main/factories/fragmenter/.htaccess -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/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 @@ -396,6 +403,8 @@ application/hub/main/nodes/master/class_HubMasterNode.php svneol=native#text/pla 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 diff --git a/application/hub/config.php b/application/hub/config.php index 2bbb4a634..7a0d2f040 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -510,6 +510,9 @@ $cfg->setConfigEntry('external_ip', ''); // 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); diff --git a/application/hub/exceptions/package/class_FinalChunkVerificationException.php b/application/hub/exceptions/package/class_FinalChunkVerificationException.php new file mode 100644 index 000000000..e08647d99 --- /dev/null +++ b/application/hub/exceptions/package/class_FinalChunkVerificationException.php @@ -0,0 +1,50 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php b/application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php new file mode 100644 index 000000000..6e288b4e2 --- /dev/null +++ b/application/hub/exceptions/package/class_UnsupportedPackageCodeHandlerException.php @@ -0,0 +1,47 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/interfaces/package/assembler/.htaccess b/application/hub/interfaces/package/assembler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/package/assembler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/package/assembler/class_Assembler.php b/application/hub/interfaces/package/assembler/class_Assembler.php new file mode 100644 index 000000000..38fc930c4 --- /dev/null +++ b/application/hub/interfaces/package/assembler/class_Assembler.php @@ -0,0 +1,36 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index b0abb8c4a..ca002ebda 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -214,7 +214,7 @@ class BaseHubSystem extends BaseFrameworkSystem { * 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) { diff --git a/application/hub/main/factories/fragmenter/class_FragmenterFactory.php b/application/hub/main/factories/fragmenter/class_FragmenterFactory.php index 0436b76f1..f551ef47b 100644 --- a/application/hub/main/factories/fragmenter/class_FragmenterFactory.php +++ b/application/hub/main/factories/fragmenter/class_FragmenterFactory.php @@ -1,62 +1,3 @@ - * @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 . - */ -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 ?> diff --git a/application/hub/main/factories/package/assembler/.htaccess b/application/hub/main/factories/package/assembler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/package/assembler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.php b/application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.php new file mode 100644 index 000000000..62fc0e523 --- /dev/null +++ b/application/hub/main/factories/package/assembler/class_PackageAssemblerFactory.php @@ -0,0 +1,61 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/factories/package/fragmenter/.htaccess b/application/hub/main/factories/package/fragmenter/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/package/fragmenter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/package/fragmenter/class_FragmenterFactory.php b/application/hub/main/factories/package/fragmenter/class_FragmenterFactory.php new file mode 100644 index 000000000..0436b76f1 --- /dev/null +++ b/application/hub/main/factories/package/fragmenter/class_FragmenterFactory.php @@ -0,0 +1,62 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 8e232d4b2..e7de4c07a 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -23,12 +23,13 @@ */ 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...) diff --git a/application/hub/main/package/assembler/.htaccess b/application/hub/main/package/assembler/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/package/assembler/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/package/assembler/class_PackageAssembler.php b/application/hub/main/package/assembler/class_PackageAssembler.php new file mode 100644 index 000000000..2255fe1f1 --- /dev/null +++ b/application/hub/main/package/assembler/class_PackageAssembler.php @@ -0,0 +1,109 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 9b96b2fb9..631d0101b 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -630,7 +630,11 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva $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 @@ -683,15 +687,24 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva /** * 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)); } /** diff --git a/application/hub/main/package/fragmenter/class_PackageFragmenter.php b/application/hub/main/package/fragmenter/class_PackageFragmenter.php index e8e62aaad..a2f721b4b 100644 --- a/application/hub/main/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/main/package/fragmenter/class_PackageFragmenter.php @@ -429,6 +429,9 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg 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); @@ -466,6 +469,7 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg * * @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 { -- 2.39.5