X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fclass_BaseHubSystem.php;h=77bf1c3456bf5096e76cb203d92354e44a250413;hb=8d9a1956c3b9e27e37ba12810b165f41e7643196;hp=ad83f7de251cfed72af6a9b0b9c7315a655c4111;hpb=7197fb51286b0e475cc621fe009d091af9db3afc;p=hub.git diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index ad83f7de2..77bf1c345 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -34,6 +34,7 @@ class BaseHubSystem extends BaseFrameworkSystem { const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x908; const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x909; const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x90a; + const EXCEPTION_INVALID_UNL = 0x90b; // Message status codes const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; @@ -48,31 +49,6 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $nodeInstance = NULL; - /** - * An instance of a communicator - */ - private $communicatorInstance = NULL; - - /** - * An instance of a crawler - */ - private $crawlerInstance = NULL; - - /** - * An instance of a cruncher - */ - private $cruncherInstance = NULL; - - /** - * An instance of a miner - */ - private $minerInstance = NULL; - - /** - * Listener instance - */ - private $listenerInstance = NULL; - /** * A network package handler instance */ @@ -83,11 +59,6 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $receiverInstance = NULL; - /** - * State instance - */ - private $stateInstance = NULL; - /** * Listener pool instance */ @@ -99,14 +70,14 @@ class BaseHubSystem extends BaseFrameworkSystem { private $fragmenterInstance = NULL; /** - * Decoder instance + * Assembler instance */ - private $decoderInstance = NULL; + private $assemblerInstance = NULL; /** - * Assembler instance + * Info instance */ - private $assemblerInstance = NULL; + private $infoInstance = NULL; /** * Protected constructor @@ -119,120 +90,6 @@ class BaseHubSystem extends BaseFrameworkSystem { parent::__construct($className); } - /** - * Getter for node instance - * - * @return $nodeInstance An instance of a node node - */ - public final function getNodeInstance () { - return $this->nodeInstance; - } - - /** - * Setter for node instance - * - * @param $nodeInstance An instance of a node node - * @return void - */ - protected final function setNodeInstance (NodeHelper $nodeInstance) { - $this->nodeInstance = $nodeInstance; - } - - /** - * Getter for communicator instance - * - * @return $communicatorInstance An instance of a Communicator class - */ - public final function getCommunicatorInstance () { - return $this->communicatorInstance; - } - - /** - * Setter for communicator instance - * - * @param $communicatorInstance An instance of a Communicator class - * @return void - */ - protected final function setCommunicatorInstance (Communicator $communicatorInstance) { - $this->communicatorInstance = $communicatorInstance; - } - - /** - * Getter for crawler instance - * - * @return $crawlerInstance An instance of a Crawler class - */ - public final function getCrawlerInstance () { - return $this->crawlerInstance; - } - - /** - * Setter for crawler instance - * - * @param $crawlerInstance An instance of a Crawler class - * @return void - */ - protected final function setCrawlerInstance (Crawler $crawlerInstance) { - $this->crawlerInstance = $crawlerInstance; - } - - /** - * Getter for cruncher instance - * - * @return $cruncherInstance An instance of a cruncher cruncher - */ - public final function getCruncherInstance () { - return $this->cruncherInstance; - } - - /** - * Setter for cruncher instance - * - * @param $cruncherInstance An instance of a cruncher cruncher - * @return void - */ - protected final function setCruncherInstance (CruncherHelper $cruncherInstance) { - $this->cruncherInstance = $cruncherInstance; - } - - /** - * Getter for miner instance - * - * @return $minerInstance An instance of a miner miner - */ - public final function getMinerInstance () { - return $this->minerInstance; - } - - /** - * Setter for miner instance - * - * @param $minerInstance An instance of a miner miner - * @return void - */ - protected final function setMinerInstance (MinerHelper $minerInstance) { - $this->minerInstance = $minerInstance; - } - - /** - * Setter for listener instance - * - * @param $listenerInstance A Listenable instance - * @return void - */ - protected final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; - } - - /** - * Getter for listener instance - * - * @return $listenerInstance A Listenable instance - */ - protected final function getListenerInstance () { - return $this->listenerInstance; - } - /** * Setter for network package handler instance * @@ -271,25 +128,6 @@ class BaseHubSystem extends BaseFrameworkSystem { return $this->receiverInstance; } - /** - * Setter for state instance - * - * @param $stateInstance A Stateable instance - * @return void - */ - public final function setStateInstance (Stateable $stateInstance) { - $this->stateInstance = $stateInstance; - } - - /** - * Getter for state instance - * - * @return $stateInstance A Stateable instance - */ - public final function getStateInstance () { - return $this->stateInstance; - } - /** * Setter for listener pool instance * @@ -329,41 +167,41 @@ class BaseHubSystem extends BaseFrameworkSystem { } /** - * Setter for decoder instance + * Setter for assembler instance * - * @param $decoderInstance A Decodeable instance + * @param $assemblerInstance An instance of an Assembler class * @return void */ - protected final function setDecoderInstance (Decodeable $decoderInstance) { - $this->decoderInstance = $decoderInstance; + protected final function setAssemblerInstance (Assembler $assemblerInstance) { + $this->assemblerInstance = $assemblerInstance; } /** - * Getter for decoder instance + * Getter for assembler instance * - * @return $decoderInstance A Decodeable instance + * @return $assemblerInstance An instance of an Assembler class */ - protected final function getDecoderInstance () { - return $this->decoderInstance; + protected final function getAssemblerInstance () { + return $this->assemblerInstance; } /** - * Setter for assembler instance + * Setter for info instance * - * @param $assemblerInstance A Decodeable instance + * @param $infoInstance A ShareableInfo instance * @return void */ - protected final function setAssemblerInstance (Assembler $assemblerInstance) { - $this->assemblerInstance = $assemblerInstance; + protected final function setInfoInstance (ShareableInfo $infoInstance) { + $this->infoInstance = $infoInstance; } /** - * Getter for assembler instance + * Getter for info instance * - * @return $assemblerInstance A Decodeable instance + * @return $infoInstance An instance of a ShareableInfo class */ - protected final function getAssemblerInstance () { - return $this->assemblerInstance; + public final function getInfoInstance () { + return $this->infoInstance; } /** @@ -432,7 +270,7 @@ class BaseHubSystem extends BaseFrameworkSystem { /** * Setter for session id * - * @param $sessionId The new session id + * @param $sessionId The new session id * @return void */ protected final function setSessionId ($sessionId) { @@ -442,7 +280,7 @@ class BaseHubSystem extends BaseFrameworkSystem { /** * Getter for session id * - * @return $sessionId Current session id + * @return $sessionId Current session id */ public final function getSessionId () { return $this->getConfigInstance()->getConfigEntry('session_id'); @@ -458,7 +296,7 @@ class BaseHubSystem extends BaseFrameworkSystem { */ protected function getSocketErrorHandlerFromCode ($errorCode) { // Create a name from translated error code - $handlerName = 'socketError' . $this->convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler'; + $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler'; // Is the call-back method there? if (!method_exists($this, $handlerName)) { @@ -479,20 +317,23 @@ class BaseHubSystem extends BaseFrameworkSystem { * @param $method Value of __METHOD__ from calling method * @param $line Value of __LINE__ from calling method * @param $socketResource A valid socket resource - * @param $recipientData An array with two elements: 0=IP number, 1=port number + * @param $unlData A valid UNL data array * @return void * @throws InvalidSocketException If $socketResource is no socket resource * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back */ - protected final function handleSocketError ($method, $line, $socketResource, array $recipientData) { + protected final function handleSocketError ($method, $line, $socketResource, array $unlData) { // This method handles only socket resources if (!is_resource($socketResource)) { // No resource, abort here throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET); } // END - if - // Check count of array, should be two - assert(count($recipientData) == 2); + // Check UNL array + //* DEBUG-DIE: */ die(__METHOD__ . ':unlData=' . print_r($unlData, TRUE)); + assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL])); + assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS])); + assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT])); // Get error code for first validation (0 is not an error) $errorCode = socket_last_error($socketResource); @@ -507,42 +348,12 @@ class BaseHubSystem extends BaseFrameworkSystem { $handlerName = $this->getSocketErrorHandlerFromCode($errorCode); // Call-back the error handler method - call_user_func_array(array($this, $handlerName), array($socketResource, $recipientData)); + call_user_func_array(array($this, $handlerName), array($socketResource, $unlData)); // Finally clear the error because it has been handled socket_clear_error($socketResource); } - /** - * Checks whether the final (last) chunk is valid - * - * @param $chunks An array with chunks and (hopefully) a valid final chunk - * @return $isValid Whether the final (last) chunk is valid - */ - protected function isValidFinalChunk (array $chunks) { - // Default is all fine - $isValid = TRUE; - - // Split the (possible) EOP chunk - $chunkSplits = explode(PackageFragmenter::CHUNK_DATA_HASH_SEPARATOR, $chunks[count($chunks) - 1]); - - // Make sure chunks with only 3 elements are parsed (for details see ChunkHandler) - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits, TRUE)); - assert(count($chunkSplits) == 3); - - // Validate final chunk - if (substr($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], 0, strlen(PackageFragmenter::END_OF_PACKAGE_IDENTIFIER)) != PackageFragmenter::END_OF_PACKAGE_IDENTIFIER) { - // Not fine - $isValid = FALSE; - } elseif (substr_count($chunkSplits[ChunkHandler::CHUNK_SPLITS_INDEX_RAW_DATA], PackageFragmenter::CHUNK_HASH_SEPARATOR) != 1) { - // CHUNK_HASH_SEPARATOR shall only be found once - $isValid = FALSE; - } - - // Return status - return $isValid; - } - /** * Translates socket error codes into our own internal names which can be * used for call-backs.