From de422c8546aaa73115d45310dd5848f1d7d09b31 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 12 Sep 2015 21:13:32 +0200 Subject: [PATCH] Continued with project: - moved some classes/files/methods to 'core' - added file-based socket listener (floods output, unfinished) - updated 'core' Signed-off-by: Roland Haeder --- .../hub/classes/class_BaseHubSystem.php | 230 +----------------- .../classes/handler/class_BaseDataHandler.php | 197 --------------- .../hub/classes/handler/network/class_ | 3 - .../network/class_BaseRawDataHandler.php | 182 -------------- .../classes/handler/network/socket/.htaccess | 1 + .../socket/class_SocketRawDataHandler.php | 69 ++++++ .../hub/classes/nodes/class_BaseHubNode.php | 5 +- application/hub/config.php | 12 + core | 2 +- 9 files changed, 99 insertions(+), 602 deletions(-) delete mode 100644 application/hub/classes/handler/class_BaseDataHandler.php delete mode 100644 application/hub/classes/handler/network/class_ delete mode 100644 application/hub/classes/handler/network/class_BaseRawDataHandler.php create mode 100644 application/hub/classes/handler/network/socket/.htaccess create mode 100644 application/hub/classes/handler/network/socket/class_SocketRawDataHandler.php diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index bcdb5581d..da5841a67 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -23,19 +23,18 @@ */ class BaseHubSystem extends BaseFrameworkSystem { // Exception codes - const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x900; - const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901; - const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902; - const EXCEPTION_INVALID_CONNECTION_TYPE = 0x903; - const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x904; - const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x905; - const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x906; - const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x907; - 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; - const EXCEPTION_INVALID_PRIVATE_KEY_HASH = 0x90c; + const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x900; + const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x901; + const EXCEPTION_INVALID_CONNECTION_TYPE = 0x902; + const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x903; + const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x904; + const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x905; + const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x906; + const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x907; + const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x908; + const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x909; + const EXCEPTION_INVALID_UNL = 0x90a; + const EXCEPTION_INVALID_PRIVATE_KEY_HASH = 0x90b; // Message status codes const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; @@ -286,211 +285,6 @@ class BaseHubSystem extends BaseFrameworkSystem { public final function getSessionId () { return $this->getConfigInstance()->getConfigEntry('session_id'); } - - /** - * Constructs a callable method name from given socket error code. If the - * method is not found, a generic one is used. - * - * @param $errorCode Error code from socket_last_error() - * @return $handlerName Call-back method name for the error handler - * @throws UnsupportedSocketErrorHandlerException If the error handler is not implemented - */ - protected function getSocketErrorHandlerFromCode ($errorCode) { - // Create a name from translated error code - $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler'; - - // Is the call-back method there? - if (!method_exists($this, $handlerName)) { - // Please implement this - throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), self::EXCEPTION_UNSUPPORTED_ERROR_HANDLER); - } // END - if - - // Return it - return $handlerName; - } - - /** - * Handles socket error for given socket resource and peer data. This method - * validates $socketResource if it is a valid resource (see is_resource()) - * but assumes valid data in array $recipientData, except that - * count($recipientData) is always 2. - * - * @param $method Value of __METHOD__ from calling method - * @param $line Value of __LINE__ from calling method - * @param $socketResource A valid socket resource - * @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 $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 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); - - // If the error code is zero, someone called this method without an error - if ($errorCode == 0) { - // No error detected (or previously cleared outside this method) - throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR); - } // END - if - - // Get handler (method) name - $handlerName = $this->getSocketErrorHandlerFromCode($errorCode); - - // Call-back the error handler method - call_user_func_array(array($this, $handlerName), array($socketResource, $unlData)); - - // Finally clear the error because it has been handled - socket_clear_error($socketResource); - } - - /** - * Translates socket error codes into our own internal names which can be - * used for call-backs. - * - * @param $errorCode The error code from socket_last_error() to be translated - * @return $errorName The translated name (all lower-case, with underlines) - */ - public function translateSocketErrorCodeToName ($errorCode) { - // Nothing bad happened by default - $errorName = BaseRawDataHandler::SOCKET_CONNECTED; - - // Is the code a number, then we have to change it - switch ($errorCode) { - case 0: // Silently ignored, the socket is connected - break; - - case 11: // "Resource temporary unavailable" - $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE; - break; - - case 32: // "Broken pipe" - $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE; - break; - - case 104: // "Connection reset by peer" - $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER; - break; - - case 107: // "Transport end-point not connected" - case 134: // On some (?) systems for 'transport end-point not connected' - // @TODO On some systems it is 134, on some 107? - $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT; - break; - - case 110: // "Connection timed out" - $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT; - break; - - case 111: // "Connection refused" - $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED; - break; - - case 113: // "No route to host" - $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST; - break; - - case 114: // "Operation already in progress" - $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS; - break; - - case 115: // "Operation now in progress" - $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS; - break; - - default: // Everything else <> 0 - // Unhandled error code detected, so first debug it because we may want to handle it like the others - self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode)); - - // Change it only in this class - $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN; - break; - } - - // Return translated name - return $errorName; - } - - /** - * Shuts down a given socket resource. This method does only ease calling - * the right visitor. - * - * @param $socketResource A valid socket resource - * @return void - */ - public function shutdownSocket ($socketResource) { - // Debug message - self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); - - // Set socket resource - $this->setSocketResource($socketResource); - - // Get a visitor instance - $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class'); - - // Debug output - self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); - - // Call the visitor - $this->accept($visitorInstance); - } - - /** - * Half-shuts down a given socket resource. This method does only ease calling - * an other visitor than shutdownSocket() does. - * - * @param $socketResource A valid socket resource - * @return void - */ - public function halfShutdownSocket ($socketResource) { - // Debug message - self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...'); - - // Set socket resource - $this->setSocketResource($socketResource); - - // Get a visitor instance - $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class'); - - // Debug output - self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString()); - - // Call the visitor - $this->accept($visitorInstance); - } - - /** - * "Getter" for a printable state name - * - * @return $stateName Name of the node's state in a printable format - */ - public final function getPrintableState () { - // Default is 'null' - $stateName = 'null'; - - // Get the state instance - $stateInstance = $this->getStateInstance(); - - // Is it an instance of Stateable? - if ($stateInstance instanceof Stateable) { - // Then use that state name - $stateName = $stateInstance->getStateName(); - } // END - if - - // Return result - return $stateName; - } } // [EOF] diff --git a/application/hub/classes/handler/class_BaseDataHandler.php b/application/hub/classes/handler/class_BaseDataHandler.php deleted file mode 100644 index 7b6b1d7d5..000000000 --- a/application/hub/classes/handler/class_BaseDataHandler.php +++ /dev/null @@ -1,197 +0,0 @@ - - * @version 0.0.0 - * @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 - * - * 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 . - */ -abstract class BaseDataHandler extends BaseHandler { - /** - * Last exception instance from database layer or NULL (default) - */ - private $lastException = NULL; - - /** - * Array with search criteria elements - */ - protected $searchData = array(); - - /** - * Array with all data XML nodes (which hold the actual data) and their values - */ - protected $messageDataElements = array(); - - /** - * Array for translating message data elements (other node's data mostly) - * into configuration elements. - */ - protected $messageToConfig = array(); - - /** - * Array for copying configuration entries - */ - protected $configCopy = array(); - - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - - // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtInstance('node'); - - // Set it here - $this->setDhtInstance($dhtInstance); - } - - /** - * Getter for search data array - * - * @return $searchData Search data array - */ - public final function getSearchData () { - return $this->searchData; - } - - /** - * Getter for last exception - * - * @return $lastException Last thrown exception - */ - public final function getLastException () { - return $this->lastException; - } - - /** - * Setter for last exception - * - * @param $lastException Last thrown exception - * @return void - */ - public final function setLastException (FrameworkException $exceptionInstance = NULL) { - $this->lastException = $exceptionInstance; - } - - /** - * Prepares a message as answer for given message data for delivery. - * - * @param $messageData An array with all message data - * @param $packageInstance An instance of a Deliverable instance - * @return void - */ - protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send an answer message for ' . $this->getHandlerName() . ' ...'); - - // Get a helper instance based on this handler's name - $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData)); - - // Get node instance - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Load descriptor XML - $helperInstance->loadDescriptorXml($nodeInstance); - - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageData); - - // Compile any configuration variables - $helperInstance->getTemplateInstance()->compileConfigInVariables(); - - // Deliver the package - $helperInstance->sendPackage($nodeInstance); - - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageData); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Answer message has been prepared.'); - } - - /** - * Prepares the next message - * - * @param $messageData An array with all message data - * @param $packageInstance An instance of a Deliverable instance - * @return void - */ - protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) { - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Going to send next message ...'); - - // Get a helper instance based on this handler's name - $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData)); - - // Get node instance - $nodeInstance = NodeObjectFactory::createNodeInstance(); - - // Load descriptor XML - $helperInstance->loadDescriptorXml($nodeInstance); - - /* - * Set missing (temporary) configuration data, mostly it needs to be - * copied from message data array. - */ - $this->initMessageConfigurationData($messageData); - - // Compile any configuration variables - $helperInstance->getTemplateInstance()->compileConfigInVariables(); - - // Deliver the package - $helperInstance->sendPackage($nodeInstance); - - /* - * Remove temporary configuration - */ - $this->removeMessageConfigurationData($messageData); - - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER[' . __METHOD__ . ':' . __LINE__ . ']: Next message has been prepared.'); - } - - /** - * Initializes configuration data from given message data array - * - * @param $messageData An array with all message data - * @return void - */ - abstract protected function initMessageConfigurationData (array $messageData); - - /** - * Removes configuration data with given message data array from global - * configuration - * - * @param $messageData An array with all message data - * @return void - */ - abstract protected function removeMessageConfigurationData (array $messageData); -} - -// [EOF] -?> diff --git a/application/hub/classes/handler/network/class_ b/application/hub/classes/handler/network/class_ deleted file mode 100644 index f551ef47b..000000000 --- a/application/hub/classes/handler/network/class_ +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/application/hub/classes/handler/network/class_BaseRawDataHandler.php b/application/hub/classes/handler/network/class_BaseRawDataHandler.php deleted file mode 100644 index 6c4b37936..000000000 --- a/application/hub/classes/handler/network/class_BaseRawDataHandler.php +++ /dev/null @@ -1,182 +0,0 @@ - - * @version 0.0.0 - * @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 - * - * 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 BaseRawDataHandler extends BaseHandler { - // 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_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) - const SOCKET_ERROR_CONNECTION_REFUSED = 'connection_refused'; // The name says it: connection refused - const SOCKET_ERROR_CONNECTION_TIMED_OUT = 'connection_timed_out'; // The name says it: connection attempt has timed-out - const SOCKET_ERROR_OPERATION_IN_PROGRESS = 'operation_in_progress'; // 'Operation now in progress' - const SOCKET_ERROR_OPERATION_ALREADY_PROGRESS = 'operation_already_progress'; // 'Operation already in progress' - const SOCKET_ERROR_RESOURCE_UNAVAILABLE = 'resource_unavailable'; // 'Resource temporary unavailable' - const SOCKET_ERROR_NO_ROUTE_TO_HOST = 'no_route_to_host'; // The name says it: no route to host - const SOCKET_ERROR_CONNECTION_RESET_BY_PEER = 'connection_reset_by_peer'; // Connection reset by peer - const SOCKET_ERROR_BROKEN_PIPE = 'broken_pipe'; // Broken pipe - const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected - - // - 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 - - // Package data - const PACKAGE_RAW_DATA = 'raw_data'; - const PACKAGE_ERROR_CODE = 'error_code'; - - // Start/end marker - const STREAM_START_MARKER = '[[S]]'; - const STREAM_END_MARKER = '[[E]]'; - - /** - * Stacker for raw data - */ - const STACKER_NAME_RAW_DATA = 'raw_data'; - - /** - * Error code from socket - */ - private $errorCode = -1; - - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - - // Set error code to 'unknown' - $this->setErrorCode(self::SOCKET_ERROR_UNKNOWN); - - // Init stacker instance for processed raw data - $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class'); - - // Remember this in this package handler - $this->setStackInstance($stackInstance); - - // Init stacker - $this->initStack(); - } - - /** - * Initializes the stacker for raw data - * - * @return void - */ - protected function initStack () { - $this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA); - } - - /** - * Adds given raw data to the raw data stacker - * - * @param $rawData raw data from the socket resource - * @return void - */ - protected function addRawDataToStacker ($rawData) { - /* - * Add the deocoded data and error code to the stacker so other classes - * (e.g. NetworkPackage) can "pop" it from the stacker. - */ - $this->getStackInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array( - self::PACKAGE_RAW_DATA => $rawData, - self::PACKAGE_ERROR_CODE => $this->getErrorCode() - )); - } - - /** - * Checks whether raw data is pending for further processing. - * - * @return $isPending Whether raw data is pending - */ - public function isRawDataPending () { - // Does the stacker have some entries (not empty)? - $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA)); - - // Return it - return $isPending; - } - - /** - * "Getter" for next raw data from the stacker - * - * @return $rawData Raw data from the stacker - */ - public function getNextRawData () { - // "Pop" the raw data from the stacker - $rawData = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA); - - // And return it - return $rawData; - } - - /** - * Checks whether the 'recipient' field matches our own an universal node - * locator. - * - * @param $packageData Raw package data - * @return $matches Whether it matches - * @todo This method will be moved to a better place - */ - protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) { - // Construct own address first - $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator(); - - // Does it match? - $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); - - // Return result - return $matches; - } - - /** - * Setter for error code - * - * @param $errorCode The error code we shall set - * @return void - */ - public final function setErrorCode ($errorCode) { - $this->errorCode = $errorCode; - } - - /** - * Getter for error code - * - * @return $errorCode The error code - */ - public final function getErrorCode () { - return $this->errorCode; - } -} - -// [EOF] -?> diff --git a/application/hub/classes/handler/network/socket/.htaccess b/application/hub/classes/handler/network/socket/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/classes/handler/network/socket/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/classes/handler/network/socket/class_SocketRawDataHandler.php b/application/hub/classes/handler/network/socket/class_SocketRawDataHandler.php new file mode 100644 index 000000000..79abf4390 --- /dev/null +++ b/application/hub/classes/handler/network/socket/class_SocketRawDataHandler.php @@ -0,0 +1,69 @@ + + * @version 0.0.0 + * @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 + * + * 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 SocketRawDataHandler extends BaseRawDataHandler implements Networkable { + /** + * Last socket error (default: Success) + */ + private $lastSocketError = 0; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set handler name + $this->setHandlerName('socket'); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a Networkable class + */ + public static final function createSocketRawDataHandler () { + // Get new instance + $handlerInstance = new SocketRawDataHandler(); + + // Return the prepared instance + return $handlerInstance; + } + + /** + * Processes raw data from given resource. This is mostly useful for TCP + * package handling and is implemented in the ???Listener class + * + * @param $resource A valid socket resource array + * @return void + */ + public function processRawDataFromResource (array $socketArray) { + $this->partialStub('socketArray=' . print_r($socketArray, TRUE)); + } +} + +// [EOF] +?> diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index 2d6116746..c7677c91f 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -537,8 +537,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { // Initialize the listener $listenerInstance->initListener(); + // Get a decorator class + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('socket_file_decorator_listener_class', array($listenerInstance)); + // Add this listener to the pool - $this->getListenerPoolInstance()->addListener($listenerInstance); + $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get an instance of the low-level listener $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class'); diff --git a/application/hub/config.php b/application/hub/config.php index 4f27e854f..727c01d0e 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -72,6 +72,9 @@ $cfg->setConfigEntry('udp_listener_class', 'UdpListener'); // CFG: SOCKET-FILE-LISTENER-CLASS $cfg->setConfigEntry('socket_file_listener_class', 'SocketFileListener'); +// CFG: SOCKET-FILE-DECORATOR-LISTENER-CLASS +$cfg->setConfigEntry('socket_file_decorator_listener_class', 'SocketFileListenerDecorator'); + // CFG: NODE-TCP-LISTENER-CLASS $cfg->setConfigEntry('node_tcp_listener_class', 'HubTcpListenerDecorator'); @@ -87,6 +90,9 @@ $cfg->setConfigEntry('client_udp_listener_class', 'ClientUdpListenerDecorator'); // CFG: NODE-POOL-CLASS $cfg->setConfigEntry('node_pool_class', 'DefaultPeerPool'); +// CFG: APPLICATION-POOL-CLASS +$cfg->setConfigEntry('application_pool_class', 'DefaultPeerPool'); + // CFG: POOL-ENTRIES-LIST-CLASS $cfg->setConfigEntry('pool_entries_list_class', 'PoolEntriesList'); @@ -99,12 +105,18 @@ $cfg->setConfigEntry('handler_pool_iterator_class', 'HandlerPoolIterator'); // CFG: NETWORK-LISTEN-ITERATOR-CLASS $cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator'); +// CFG: SOCKET-LISTEN-ITERATOR-CLASS +$cfg->setConfigEntry('socket_listen_iterator_class', 'DefaultIterator'); + // CFG: TCP-RAW-DATA-HANDLER-CLASS $cfg->setConfigEntry('tcp_raw_data_handler_class', 'TcpRawDataHandler'); // CFG: UDP-RAW-DATA-HANDLER-CLASS $cfg->setConfigEntry('udp_raw_data_handler_class', 'UdpRawDataHandler'); +// CFG: SOCKET-RAW-DATA-HANDLER-CLASS +$cfg->setConfigEntry('socket_raw_data_handler_class', 'SocketRawDataHandler'); + // CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS $cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor'); diff --git a/core b/core index 5aad6a4af..b9a937c5f 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 5aad6a4af62531050475887f66910b835f287452 +Subproject commit b9a937c5f2112e92cecc00b02a4206fbb643e4ec -- 2.39.5