]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 20 May 2017 19:47:20 +0000 (21:47 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:04 +0000 (18:50 +0200)
- imported HandleableProtocol
- imported Registerable (only templates)
- created some namespaces
- the "new" exception is coming back from 'core' as it is not generic
- updated core

Signed-off-by: Roland Häder <roland@mxchange.org>
20 files changed:
application/hub/classes/class_BaseHubSystem.php
application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php
application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php
application/hub/classes/factories/client/class_ClientFactory.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/handler/protocol/class_
application/hub/classes/handler/protocol/class_BaseProtocolHandler.php
application/hub/classes/handler/protocol/ipv4/class_
application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php
application/hub/classes/handler/protocol/ipv4/tcp/class_TcpProtocolHandler.php
application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/tags/package/class_PackageTags.php
application/hub/exceptions/socket/.htaccess [new file with mode: 0644]
application/hub/exceptions/socket/class_NoSocketRegisteredException.php [new file with mode: 0644]
application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php
application/hub/interfaces/handler/protocol/class_HandleableProtocol.php
application/hub/interfaces/helper/connections/class_ConnectionHelper.php
application/hub/interfaces/tags/class_Tagable.php
core

index e81113d924dba95baefe6bcabd391fcd3cbde001..1f100e258c0ef726693d9fce76f5e9359ea62d6c 100644 (file)
@@ -4,6 +4,7 @@ namespace Hub\Generic;
 
 // Import application-specific stuff
 use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Protocol\HandleableProtocol;
 use Hub\Handler\RawData\BaseRawDataHandler;
 use Hub\Information\ShareableInfo;
 use Hub\Listener\BaseListener;
@@ -102,6 +103,16 @@ class BaseHubSystem extends BaseFrameworkSystem implements HubInterface {
         */
        private $listenerInstance = NULL;
 
+       /**
+        * A HandleableProtocol instance
+        */
+       private $protocolInstance = NULL;
+
+       /**
+        * Name of used protocol
+        */
+       private $protocolName = 'invalid';
+
        /**
         * Protected constructor
         *
@@ -391,4 +402,42 @@ class BaseHubSystem extends BaseFrameworkSystem implements HubInterface {
                return $this->listenerInstance;
        }
 
+       /**
+        * Setter for HandleableProtocol instance
+        *
+        * @param       $protocolInstance       An instance of an HandleableProtocol
+        * @return      void
+        */
+       public final function setProtocolInstance (HandleableProtocol $protocolInstance) {
+               $this->protocolInstance = $protocolInstance;
+       }
+
+       /**
+        * Getter for HandleableProtocol instance
+        *
+        * @return      $protocolInstance       An instance of an HandleableProtocol
+        */
+       public final function getProtocolInstance () {
+               return $this->protocolInstance;
+       }
+
+       /**
+        * 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;
+       }
+
 }
index acae4da49ef19f1fd2a9bd267cfc07dd4d21de5b..f49bdc812eaf2e275629d7fc2f10db572e5bafbd 100644 (file)
@@ -104,7 +104,5 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
                // @TODO Add some validation here???
                return $protocolType;
        }
-}
 
-// [EOF]
-?>
+}
index c08c97f1aee708323fc38560564a209b2c0ba432..4a57ec5e4811526ed2b86aefdc5673467c87b04d 100644 (file)
@@ -7,6 +7,7 @@ use Hub\Container\Socket\StorableSocket;
 use Hub\Factory\Node\NodeObjectFactory;
 use Hub\Factory\Socket\SocketFactory;
 use Hub\Generic\BaseHubSystem;
+use Hub\Handler\Protocol\HandleableProtocol;
 use Hub\Helper\Connection\BaseConnectionHelper;
 use Hub\Network\Package\NetworkPackage;
 
index b40974d2adf7c5ab98c3b1b10d040f527cc29084..d5e9c457b4e3432251d0c44f5639272a83c9380e 100644 (file)
@@ -4,6 +4,7 @@ namespace Hub\Factory\Client;
 
 // Import application-specific stuff
 use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Protocol\HandleableProtocol;
 
 // Import framework stuff
 use CoreFramework\Factory\ObjectFactory;
index 297342a5b038bf604260cbaadec3b2988ed7f9d0..dfacab06b3b950dfadc8277175e3200afe16bd80 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Factory\Socket;
 
 // Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
 use Hub\Listener\BaseListener;
 use Hub\Network\Package\NetworkPackage;
 
index 66531659360abbeb571678f409ce01284b7a7e92..beada8cf3eb7daa0682f62426377e065958206d0 100644 (file)
@@ -1,4 +1,13 @@
 <?php
+// Own namespace
+namespace Hub\Handler\Protocol\;
+
+// Import appplication-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
+// Import framework stuff
+use CoreFramework\Registry\Registerable;
+
 /**
  * A ??? protocol handler
  *
@@ -47,7 +56,5 @@ class ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtoc
                // Return the prepared instance
                return $handlerInstance;
        }
-}
 
-// [EOF]
-?>
+}
index 222b467cfdf9d373373eb84e6ddbd8ebbdd71f3b..079ceea80567a0bdcc243b0313e00c257086ed03 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Handler\Protocol;
 
 // Import application-specific sutff
+use Hub\Handler\Protocol\HandleableProtocol;
 use Hub\Locator\Node\UniversalNodeLocator;
 use Hub\Tools\HubTools;
 
@@ -28,11 +29,11 @@ use Hub\Tools\HubTools;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseProtocolHandler extends BaseHandler {
+class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
        /**
-        * Whole UNL data array
+        * Whole UNL instance
         */
-       private $universalNodeLocatorData = array();
+       private $universalNodeLocatorInstance = NULL;
 
        /**
         * Protected constructor
@@ -46,24 +47,14 @@ class BaseProtocolHandler extends BaseHandler {
        }
 
        /**
-        * Setter for UNL data array to satify HandleableProtocol
+        * Setter for UNL instance
         *
-        * @para        $unlData        The UNL data array
+        * @para        $unlInstance    An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorData (array $unlData) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
                // Set new UNL data array
-               $this->universalNodeLocatorData = $unlData;
-       }
-
-       /**
-        * Getter for UNL data array to satify HandleableProtocol
-        *
-        * @return      $unlData        The UNL data array
-        */
-       public final function getUniversalNodeLocatorDataArray () {
-               // Return UNL data array
-               return $this->universalNodeLocatorData;
+               $this->universalNodeLocatorInstance = $unlInstance;
        }
 
        /**
@@ -150,19 +141,13 @@ class BaseProtocolHandler extends BaseHandler {
        }
 
        /**
-        * "Getter" for currently saved UNL
+        * Getter for UNL instance
         *
-        * @return      $unl    Currently saved Universal Node Locator
+        * @return      $unlData        An instance of a LocateableNode class
         */
-       public final function getCurrentUniversalNodeLocator () {
-               // Construct generic UNL
-               $unl = sprintf('%s://%s',
-                       $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
-                       $this->getAddressPart()
-               );
-
-               // Return it
-               return $unl;
+       public final function getUniversalNodeLocatorInstance () {
+               // Return UNL data array
+               return $this->universalNodeLocatorInstance;
        }
 
        /**
@@ -202,7 +187,5 @@ class BaseProtocolHandler extends BaseHandler {
                // Return result
                return $ifMatches;
        }
-}
 
-// [EOF]
-?>
+}
index 66531659360abbeb571678f409ce01284b7a7e92..88954cebe9e0f94b9473617cbcc17307e91fb330 100644 (file)
@@ -1,4 +1,11 @@
 <?php
+// Own namespace
+namespace Hub\Handler\Protocol\;
+
+// Import application-specific stuff
+
+// Import framework stuff
+
 /**
  * A ??? protocol handler
  *
@@ -21,7 +28,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
+class ???ProtocolHandler extends BaseIpV4Handler {
        /**
         * Protected constructor
         *
@@ -47,7 +54,5 @@ class ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtoc
                // Return the prepared instance
                return $handlerInstance;
        }
-}
 
-// [EOF]
-?>
+}
index 2ab056d74a7190e8556a6da816ab08c291999782..3a1ff1f4848ae9acb8fd160f88c796e3db519227 100644 (file)
@@ -52,7 +52,7 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
        }
 
        /**
-        * Setter for port number to satify HandleableProtocol
+        * Setter for port number
         *
         * @para        $port   The port number
         * @return      void
@@ -63,7 +63,7 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
        }
 
        /**
-        * Getter for port number to satify HandleableProtocol
+        * Getter for port number
         *
         * @return      $port   The port number
         */
@@ -140,20 +140,13 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
                // If this doesn't fail, continue validating the IP:port combination
                if ($isValid === TRUE) {
                        // ... and validate IP:port, first "parse" the UNL
-                       $unlData = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
-                       /*
-                        * Make sure the extra field 'port' is there. This may look
-                        * superflious but in case of a rewrite this assert will stop at
-                        * badly formated arrays.
-                        */
-                       assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+                       $unlInstance = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
 
                        // Set whole UNL data array
-                       $this->setUniversalNodeLocatorData($unlData);
+                       $this->setUniversalNodeLocatorInstance($unlInstance);
 
                        // Set port
-                       $this->setPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+                       $this->setPort($unlInstance->getUnlPort());
                } // END - if
 
                // Return result
@@ -171,13 +164,11 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
                // Construct address
                $address = sprintf('%s:%s',
                        parent::getAddressPart(),
-                       $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PORT)
+                       $this->getUniversalNodeLocatorInstance()->getUnlPort()
                );
 
                // Return it
                return $address;
        }
-}
 
-// [EOF]
-?>
+}
index cc4469f12106eb4903fbc4d1cbbff499d70ebaa0..332a995a93a7171179cb0a94c6beb4529a0522b9 100644 (file)
@@ -2,6 +2,9 @@
 // Own namespace
 namespace Hub\Handler\Protocol\Tcp;
 
+// Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
 // Import framework stuff
 use CoreFramework\Registry\Registerable;
 
index 8445a5696ec6ce8cd6f4b2ce7bfe5766ddc2e423..3bd76448237915513967e4a36c0ae4141929eb85 100644 (file)
@@ -48,7 +48,7 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
        }
 
        /**
-        * Getter for port number to satify HandleableProtocol
+        * Getter for port number to
         *
         * @return      $connectionPort The port number
         */
@@ -57,7 +57,7 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
        }
 
        /**
-        * Setter for port number to satify HandleableProtocol
+        * Setter for port number
         *
         * @param       $connectionPort The port number
         * @return      void
index 00229855eb943b03586a41352d766007e194c077..6859446f1d19bca53a212191d914bff6a97b7540 100644 (file)
@@ -97,20 +97,15 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
 
                // @TODO The whole resolving part should be moved out and made more configurable
                // Init recipient data
-               $unlData = array();
+               $unlInstance = NULL;
 
                // Try to solve the recipient
                try {
                        // Get protocol handler back from package data
                        $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
 
-                       // Get UNL data
-                       $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
-
-                       // Make sure it is a valid Universal Node Locator array (3 elements)
-                       assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
-                       assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
-                       assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+                       // Get UNL instance
+                       $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
 
                        // Set handler instance
                        $helperInstance->setHandlerInstance($handlerInstance);
@@ -143,8 +138,8 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                }
 
                // Set address and maybe port
-               $helperInstance->setAddress($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]);
-               $helperInstance->setConnectionPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+               $helperInstance->setAddress($unlInstance->getUnlAddress());
+               $helperInstance->setConnectionPort($unlInstance->getUnlPort());
 
                // Now connect to it
                if (!$helperInstance->connectToPeerByUnlData($unlData)) {
index 1bb2d03bb92aaf15c69b2964328efd19bcc02549..f1e67b1fef99da6ff63256c02d8c90d10020293d 100644 (file)
@@ -194,7 +194,5 @@ class PackageTags extends BaseTag implements Tagable {
                // And return the result
                return $accepts;
        }
-}
 
-// [EOF]
-?>
+}
diff --git a/application/hub/exceptions/socket/.htaccess b/application/hub/exceptions/socket/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/exceptions/socket/class_NoSocketRegisteredException.php b/application/hub/exceptions/socket/class_NoSocketRegisteredException.php
new file mode 100644 (file)
index 0000000..cbce9f0
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+// Own namespace
+namespace Hub\Socket;
+
+// Inport application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
+/**
+ * This exception is thrown when the requested socket is not thrown
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 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 <http://www.gnu.org/licenses/>.
+ */
+class NoSocketRegisteredException extends AbstractSocketException {
+       /**
+        * A Constructor for this exception
+        *
+        * @param       $protocolInstance       An instance of a HandleableProtocol class
+        * @param       $code                           Error code
+        * @return      void
+        */
+       public function __construct (HandleableProtocol $protocolInstance, $code) {
+               // Construct the message
+               $message = sprintf('[%s:] Requested socket is not yet registered.',
+                       $protocolInstance->__toString()
+               );
+
+               // Call parent exception constructor
+               parent::__construct($message, $code);
+       }
+
+}
index c88c73d3bef2545b7514e73570b7482bea3715bf..95dd2de72e83b0291534e268547f5a952f4e1616 100644 (file)
@@ -1,4 +1,10 @@
 <?php
+// Own namespace
+namespace Hub\Discovery\Socket;
+
+// Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
 /**
  * An interface for socket discovery
  *
index 26327d566d9649caee9fb4a0a05d6a21d667c574..4e4ba6b2c863548a0bb2558eb2c60f6b4bfd455b 100644 (file)
@@ -28,6 +28,13 @@ use CoreFramework\Handler\Handleable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface HandleableProtocol extends Handleable {
+       /**
+        * Getter for UNL instance
+        *
+        * @return      $unlData        An instance of a LocateableNode class
+        */
+       function getUniversalNodeLocatorInstance ();
+
        /**
         * Getter for port number to satify HandleableProtocol
         *
@@ -42,6 +49,14 @@ interface HandleableProtocol extends Handleable {
         */
        function getProtocolName ();
 
+       /**
+        * 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 UNL
+        */
+       function getAddressPart ();
+
        /**
         * Validates given 'recipient' if it is a valid UNL. This means that the UNL
         * can be parsed by the protocol handler.
index fbbc630ca99720767b18cd3d2f16f2ef0942294d..a053edcea10be9821c8100aa1350b2a9ae06ca48 100644 (file)
@@ -48,7 +48,7 @@ interface ConnectionHelper extends HubHelper {
        function doShutdown ();
 
        /**
-        * Getter for port number to satify HandleableProtocol
+        * Getter for port number
         *
         * @return      $port   The port number
         */
index 5ece046b6826fc92666522e4e8384e0aa5609525..0a683eb52cb7e976e5809b79dfb298e193fe9caa 100644 (file)
@@ -49,6 +49,3 @@ interface Tagable extends HubInterface {
        function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance);
 
 }
-
-// [EOF]
-?>
diff --git a/core b/core
index aa76ddf7f1d5d302f1d752efcd113515ecf152a2..8d7422139a55477388fcd6a30a1ce41d83780e5e 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit aa76ddf7f1d5d302f1d752efcd113515ecf152a2
+Subproject commit 8d7422139a55477388fcd6a30a1ce41d83780e5e