]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/handler/protocol/class_BaseProtocolHandler.php
Lesser noisy debug messages + updated 'core'.
[hub.git] / application / hub / main / handler / protocol / class_BaseProtocolHandler.php
index 242ca0ae5ad07d82d4703d394ae0a2f0fb84c822..5be57dc746816e8afaf824033705d41e2a80dd05 100644 (file)
@@ -54,7 +54,7 @@ class BaseProtocolHandler extends BaseHandler {
         *
         * @return      $unlData        The UNL data array
         */
-       public final function getUniversalNodeLocatorData () {
+       public final function getUniversalNodeLocatorDataArray () {
                // Return UNL data array
                return $this->universalNodeLocatorData;
        }
@@ -127,6 +127,76 @@ class BaseProtocolHandler extends BaseHandler {
                // Return the generic array
                return $unlData;
        }
+
+       /**
+        * Gets an element from universalNodeLocatorData array
+        *
+        * @param       $element        Element in universalNodeLocatorData array
+        * @return      $value          Found value
+        */
+       protected final function getUniversalNodeLocatorDataElement ($element) {
+               // Is the element there?
+               assert(isset($this->universalNodeLocatorData[$element]));
+
+               // Return it
+               return $this->universalNodeLocatorData[$element];
+       }
+
+       /**
+        * "Getter" for currently saved UNL
+        *
+        * @return      $unl    Currently saved Universal Node Locator
+        */
+       public final function getCurrentUniversalNodeLocator () {
+               // Construct generic UNL
+               $unl = sprintf('%s://%s',
+                       $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
+                       $this->getAddressPart()
+               );
+
+               // Return it
+               return $unl;
+       }
+
+       /**
+        * Default implementation for returning address part, may not be suitable
+        * for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
+        *
+        * @return      $address        Address part for the final UNL
+        */
+       public function getAddressPart () {
+               // Return it
+               return $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_ADDRESS);
+       }
+
+       /**
+        * If the found UNL (address) matches own external or internal address
+        *
+        * @return      $ifMatches      Whether the found UNL matches own addresss
+        */
+       public function isOwnAddress () {
+               // Get current UNL (from universalNodeLocatorData array)
+               $currentUnl = $this->getCurrentUniversalNodeLocator();
+
+               // Get own external UNL
+               $externalUnl = HubTools::determineOwnExternalAddress();
+
+               // Get internal UNL
+               $internalUnl = HubTools::determineOwnInternalAddress();
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: currentUnl=' . $currentUnl . ',externalUnl=' . $externalUnl . ',internalUnl=' . $internalUnl);
+               //* DIE-DEBUG: */ die(__METHOD__.':currentUnl=' . $currentUnl . ',this='.print_r($this, TRUE));
+
+               // Is it the same?
+               $ifMatches = (($currentUnl === $externalUnl) || ($currentUnl === $internalUnl));
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ifMatches=' . intval($ifMatches));
+
+               // Return result
+               return $ifMatches;
+       }
 }
 
 // [EOF]