]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/class_BaseHubSystem.php
Merge branch 'refacuring/protocol_handler' into latest-core/crawler
[hub.git] / application / hub / main / class_BaseHubSystem.php
index dbc12da1e5d73dda169d6875a69a3990e7831497..885abc5d08b959e66b8611b317fd8cfba71a7e14 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @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';
@@ -68,11 +69,6 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        private $minerInstance = NULL;
 
-       /**
-        * Listener instance
-        */
-       private $listenerInstance = NULL;
-
        /**
         * A network package handler instance
         */
@@ -108,6 +104,11 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        private $assemblerInstance = NULL;
 
+       /**
+        * Info instance
+        */
+       private $infoInstance = NULL;
+
        /**
         * Name of used protocol
         */
@@ -219,25 +220,6 @@ class BaseHubSystem extends BaseFrameworkSystem {
                $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
         *
@@ -371,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
         *
@@ -437,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) {
@@ -447,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.
@@ -484,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);
@@ -512,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);
@@ -684,25 +707,6 @@ class BaseHubSystem extends BaseFrameworkSystem {
                // Return result
                return $stateName;
        }
-
-       /**
-        * 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;
-       }
 }
 
 // [EOF]