From: Roland Häder Date: Sun, 12 Feb 2012 22:40:48 +0000 (+0000) Subject: 'hub' continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cca8969ebc91f96bde655a82db81c923d5d9a2ad;p=hub.git 'hub' continued: - New chunk handler class + factory added (no interface yet) - FinalChunkVerificationException simplified (to make usage of it in chunk handler) - TODOs.txt updated --- diff --git a/.gitattributes b/.gitattributes index b6aa3f2cc..aba2aab57 100644 --- a/.gitattributes +++ b/.gitattributes @@ -193,6 +193,8 @@ application/hub/main/discovery/package/class_PackageRecipientDiscovery.php svneo application/hub/main/discovery/socket/.htaccess -text svneol=unset#text/plain application/hub/main/discovery/socket/class_PackageSocketDiscovery.php svneol=native#text/plain application/hub/main/factories/.htaccess -text svneol=unset#text/plain +application/hub/main/factories/chunks/.htaccess -text svneol=unset#text/plain +application/hub/main/factories/chunks/class_ChunkHandlerFactory.php svneol=native#text/plain application/hub/main/factories/discovery/.htaccess -text svneol=unset#text/plain application/hub/main/factories/discovery/class_PackageDiscoveryFactory.php svneol=native#text/plain application/hub/main/factories/discovery/class_SocketDiscoveryFactory.php svneol=native#text/plain @@ -292,6 +294,8 @@ application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFi application/hub/main/filter/task/node/.htaccess svneol=native#text/plain application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php svneol=native#text/plain application/hub/main/handler/.htaccess -text svneol=unset#text/plain +application/hub/main/handler/chunks/.htaccess -text svneol=unset#text/plain +application/hub/main/handler/chunks/class_ChunkHandler.php svneol=native#text/plain application/hub/main/handler/class_ svneol=native#text/plain application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 7a0d2f040..09d31a793 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -531,6 +531,9 @@ $cfg->setConfigEntry('socket_timeout_seconds', 3); // CFG: SOCKET-TIMEOUT-MICROSECONDS $cfg->setConfigEntry('socket_timeout_microseconds', 0); +// CFG: CHUNK-HANDLER-CLASS +$cfg->setConfigEntry('chunk_handler_class', 'ChunkHandler'); + /////////////////////////////////////////////////////////////////////////////// // Peer states /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/exceptions/package/class_FinalChunkVerificationException.php b/application/hub/exceptions/package/class_FinalChunkVerificationException.php index e08647d99..51beaf6b3 100644 --- a/application/hub/exceptions/package/class_FinalChunkVerificationException.php +++ b/application/hub/exceptions/package/class_FinalChunkVerificationException.php @@ -32,13 +32,12 @@ class FinalChunkVerificationException extends FrameworkException { */ 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", + $message = sprintf("[%s:%d] The final chunk %s is not a valid EOP (%s) chunk. Total chunks: %s", $messageArray[0]->__toString(), $this->getLine(), - $messageArray[2][count($messageArray[2]) - 1], + $messageArray[1][count($messageArray[2]) - 1], PackageFragmenter::END_OF_PACKAGE_IDENTIFIER, - $messageArray[1][BaseRawDataHandler::PACKAGE_DECODED_DATA] - count($messageArray[2]) + count($messageArray[1]) ); // Call parent exception constructor diff --git a/application/hub/main/factories/chunks/.htaccess b/application/hub/main/factories/chunks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/chunks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/chunks/class_ChunkHandlerFactory.php b/application/hub/main/factories/chunks/class_ChunkHandlerFactory.php new file mode 100644 index 000000000..621b024c7 --- /dev/null +++ b/application/hub/main/factories/chunks/class_ChunkHandlerFactory.php @@ -0,0 +1,59 @@ + + * @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 ChunkHandlerFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) chunk handler instance + * + * @return $handlerInstance An instance of a chunk handler class + */ + public static final function createChunkHandlerInstance () { + // If there is no handler? + if (Registry::getRegistry()->instanceExists('chunk_handler')) { + // Get handler from registry + $handlerInstance = Registry::getRegistry()->getInstance('chunk_handler'); + } else { + // Get the handler instance + $handlerInstance = self::createObjectByConfiguredName('chunk_handler_class'); + + // Add it to the registry + Registry::getRegistry()->addInstance('chunk_handler', $handlerInstance); + } + + // Return the instance + return $handlerInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/chunks/.htaccess b/application/hub/main/handler/chunks/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/handler/chunks/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php new file mode 100644 index 000000000..1c753a32b --- /dev/null +++ b/application/hub/main/handler/chunks/class_ChunkHandler.php @@ -0,0 +1,71 @@ + + * @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 ChunkHandler extends BaseHandler implements Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set handler name + $this->setHandlerName('chunk'); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a chunk Handler class + */ + public final static function createChunkHandler () { + // Get new instance + $handlerInstance = new ChunkHandler(); + + // Return the prepared instance + return $handlerInstance; + } + + /** + * Adds all chunks if the last one verifies as a 'final chunk'. + * + * @param $chunks An array with chunks, the last one should be a 'final' + * @return void + * @throws FinalChunkVerificationException If the final chunk does not start with 'EOP:' + */ + public function addAllChunksWithFinal (array $chunks) { + // 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, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION); + } // END - if + + // Not yet finished + $this->partialStub('Not yet implemented.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/package/assembler/class_PackageAssembler.php b/application/hub/main/package/assembler/class_PackageAssembler.php index 04195d0c5..430ed7109 100644 --- a/application/hub/main/package/assembler/class_PackageAssembler.php +++ b/application/hub/main/package/assembler/class_PackageAssembler.php @@ -101,10 +101,14 @@ class PackageAssembler extends BaseFrameworkSystem implements Assembler, Registe // 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); + throw new FinalChunkVerificationException(array($this, $chunks), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION); } // END - if - die('chunks='.print_r($chunks,true)); + // Now get a chunk handler instance + $handlerInstance = ChunkHandlerFactory::createChunkHandlerInstance(); + + // Add all chunks because the last final chunk is found + $handlerInstance->addAllChunksWithFinal($chunks); } } diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 7e88dab52..ae4c6baea 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -96,11 +96,11 @@ ./application/hub/main/package/class_NetworkPackage.php:222: // @TODO crc32() is very weak, 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:386: // @TODO We may want to do somthing more here? -./application/hub/main/package/class_NetworkPackage.php:486: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:512: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:616: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:695: // @TODO Add some content here -./application/hub/main/package/class_NetworkPackage.php:745: * @todo This may be enchanced for outgoing packages? +./application/hub/main/package/class_NetworkPackage.php:492: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:518: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:622: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:716: // @TODO Add some content here +./application/hub/main/package/class_NetworkPackage.php:766: * @todo This may be enchanced for outgoing packages? ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:427: * @todo $helperInstance is unused ./application/hub/main/pools/peer/class_DefaultPeerPool.php:160: // @TODO Check for IP ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106: // @TODO Do something with it @@ -249,6 +249,7 @@ ./application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php:2:// @DEPRECATED +./application/hub/main/factories/fragmenter/class_FragmenterFactory.php:2:// @DEPRECATED ./application/hub/main/factories/states/class_StateFactory.php:2:// @DEPRECATED ./application/hub/main/filter/activation/class_HubActivationSelfAnnouncementFilter.php:2:// @DEPRECATED ./application/hub/main/filter/bootstrap/class_HubBootstrapAquireHubIdFilter.php:2:// @DEPRECATED @@ -298,6 +299,7 @@ ./inc/classes/exceptions/language/class_MissingLanguageHandlerException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ClassNotFoundException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php:2:// @DEPRECATED +./inc/classes/exceptions/main/class_MissingDecimalsThousandsSeperatorException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_MissingMethodException.php:14: * @deprecated Please do no longer use this exception ./inc/classes/exceptions/state/class_InvalidStateException.php:2:// @DEPRECATED ./inc/classes/interfaces/helper/class_HelpableLogin.php:2:// @DEPRECATED