]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/class_BaseHubSystem.php
Publication of DHT entries requires a fully booted DHT as else it will only find...
[hub.git] / application / hub / main / class_BaseHubSystem.php
index 11155907a23fc76f31ba38eca5598fd5edf01eee..a14384e1cfa5d9db6e036d168645a412dedb38c5 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A general hub system class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
  * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @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
  */
 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_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 SOCKET_ERROR_CONNECTION_RESET_BY_PEER   = 0x908;
 
        // Message status codes
        const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
@@ -398,7 +403,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
         * count($recipientData) is always 2.
         *
         * @param       $method                         Value of __METHOD__ from calling method
-        * @param       $line                           Source code line where this method was called
+        * @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
         * @return      void
@@ -428,7 +433,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
                $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
 
                // Call-back the error handler method
-               call_user_func(array($this, $handlerName), $socketResource);
+               call_user_func_array(array($this, $handlerName), array($socketResource, $recipientData));
 
                // Finally clear the error because it has been handled
                socket_clear_error($socketResource);
@@ -442,22 +447,22 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        protected function isValidFinalChunk (array $chunks) {
                // Default is all fine
-               $isValid = true;
+               $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: */ $this->debugOutput('eopChunk=' . $chunks[count($chunks) - 1] . ',chunkSplits=' . print_r($chunkSplits,true));
+               //* 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;
+                       $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;
+                       $isValid = FALSE;
                }
 
                // Return status
@@ -484,6 +489,10 @@ class BaseHubSystem extends BaseFrameworkSystem {
                                $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
                                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?
@@ -512,7 +521,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
-                               $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
+                               self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
 
                                // Change it only in this class
                                $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
@@ -532,7 +541,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        public function shutdownSocket ($socketResource) {
                // Debug message
-               $this->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
 
                // Set socket resource
                $this->setSocketResource($socketResource);
@@ -541,7 +550,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
 
                // Debug output
-               $this->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
 
                // Call the visitor
                $this->accept($visitorInstance);
@@ -556,7 +565,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        public function halfShutdownSocket ($socketResource) {
                // Debug message
-               $this->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
 
                // Set socket resource
                $this->setSocketResource($socketResource);
@@ -565,7 +574,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
 
                // Debug output
-               $this->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
 
                // Call the visitor
                $this->accept($visitorInstance);