X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fclass_BaseHubSystem.php;h=885abc5d08b959e66b8611b317fd8cfba71a7e14;hb=424faec1c51eb20cadc5149777f08fd1befa4fd0;hp=fdfb615f86ff28b273eea8d30aa4bf305cb5abce;hpb=3e5e829a9284c30b1a24b720f9c43a68d920d973;p=hub.git diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index fdfb615f8..885abc5d0 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 * @@ -31,6 +31,10 @@ class BaseHubSystem extends BaseFrameworkSystem { 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; // Message status codes const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; @@ -45,15 +49,25 @@ 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; /** - * Listener instance + * An instance of a miner */ - private $listenerInstance = NULL; + private $minerInstance = NULL; /** * A network package handler instance @@ -90,6 +104,16 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $assemblerInstance = NULL; + /** + * Info instance + */ + private $infoInstance = NULL; + + /** + * Name of used protocol + */ + private $protocolName = 'invalid'; + /** * Protected constructor * @@ -120,6 +144,44 @@ class BaseHubSystem extends BaseFrameworkSystem { $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 * @@ -140,22 +202,22 @@ class BaseHubSystem extends BaseFrameworkSystem { } /** - * Setter for listener instance + * Getter for miner instance * - * @param $listenerInstance A Listenable instance - * @return void + * @return $minerInstance An instance of a miner miner */ - protected final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; + public final function getMinerInstance () { + return $this->minerInstance; } /** - * Getter for listener instance + * Setter for miner instance * - * @return $listenerInstance A Listenable instance + * @param $minerInstance An instance of a miner miner + * @return void */ - protected final function getListenerInstance () { - return $this->listenerInstance; + protected final function setMinerInstance (MinerHelper $minerInstance) { + $this->minerInstance = $minerInstance; } /** @@ -291,6 +353,25 @@ class BaseHubSystem extends BaseFrameworkSystem { return $this->assemblerInstance; } + /** + * Setter for info instance + * + * @param $infoInstance A ShareableInfo instance + * @return void + */ + protected final function setInfoInstance (ShareableInfo $infoInstance) { + $this->infoInstance = $infoInstance; + } + + /** + * Getter for info instance + * + * @return $infoInstance A Decodeable instance + */ + public final function getInfoInstance () { + return $this->infoInstance; + } + /** * Setter for node id * @@ -357,7 +438,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) { @@ -367,12 +448,31 @@ 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'); } + /** + * Getter for protocol name + * + * @return $protocolName Name of used protocol + */ + public final function getProtocolName () { + return $this->protocolName; + } + + /** + * Setter for protocol name + * + * @param $protocolName Name of used protocol + * @return void + */ + protected final function setProtocolName ($protocolName) { + $this->protocolName = $protocolName; + } + /** * Constructs a callable method name from given socket error code. If the * method is not found, a generic one is used. @@ -404,20 +504,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); @@ -432,7 +535,7 @@ 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); @@ -488,6 +591,14 @@ class BaseHubSystem extends BaseFrameworkSystem { $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? @@ -516,7 +627,7 @@ class BaseHubSystem extends BaseFrameworkSystem { 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('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode)); + 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;