]> git.mxchange.org Git - hub.git/commitdiff
WIP:
authorRoland Häder <roland@mxchange.org>
Sun, 21 May 2017 11:37:33 +0000 (13:37 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 21 Aug 2020 16:50:05 +0000 (18:50 +0200)
- rewrite from unlData -> unlInstance (still open things)
- moved constants from class to interface LocateableNode
- moved UNL_REGEX to same interface for rewrite of those parse methods. They
  should be moved to a factory instead.

Signed-off-by: Roland Häder <roland@mxchange.org>
14 files changed:
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php
application/hub/classes/factories/socket/class_SocketFactory.php
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/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/info/connection/class_ConnectionInfo.php
application/hub/classes/locator/class_UniversalNodeLocator.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/interfaces/handler/protocol/class_HandleableProtocol.php
application/hub/interfaces/locator/class_LocateableNode.php
application/hub/interfaces/resolver/class_ProtocolResolver.php

index 95b79fc95c85c79094dad6c644b724ee3773fa2b..d23b46f6ec5db25f897a58d000695616681b7c47 100644 (file)
@@ -646,11 +646,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'connection timed out', but does not clear it for
         * later debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorConnectionTimedOut (array $unlData) {
+       protected function handleSocketErrorConnectionTimedOut (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -668,11 +668,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'resource temporary unavailable', but does not
         * clear it for later debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorResourceUnavailable (array $unlData) {
+       protected function handleSocketErrorResourceUnavailable (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -690,11 +690,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'connection refused', but does not clear it for
         * later debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorConnectionRefused (array $unlData) {
+       protected function handleSocketErrorConnectionRefused (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -712,11 +712,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'no route to host', but does not clear it for later
         * debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorNoRouteToHost (array $unlData) {
+       protected function handleSocketErrorNoRouteToHost (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -732,14 +732,14 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
 
        /**
         * Handles socket error 'operation already in progress' which happens in
-        * method connectToPeerByUnlData() on timed out connection
+        * method connectToPeerByUnlInstance() on timed out connection
         * attempts.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorOperationAlreadyProgress (array $unlData) {
+       protected function handleSocketErrorOperationAlreadyProgress (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -757,11 +757,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'connection reset by peer', but does not clear it for
         * later debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketConnectionException       The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorConnectionResetByPeer (array $unlData) {
+       protected function handleSocketErrorConnectionResetByPeer (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -779,11 +779,11 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket error 'operation not supported', but does not clear it for
         * later debugging purposes.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         * @throws      SocketOperationException        The connection attempts fails with a time-out
         */
-       protected function handleSocketErrorOperationNotSupported (array $unlData) {
+       protected function handleSocketErrorOperationNotSupported (array $socketData) {
                // Get socket error code for verification
                $socketError = $this->getLastSocketError();
 
@@ -801,10 +801,10 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable
         * Handles socket "error" 'operation now in progress' which can be safely
         * passed on with non-blocking connections.
         *
-        * @param       $unlData                        A valid UNL data array
+        * @param       $socketData             Valid socket data array
         * @return      void
         */
-       protected function handleSocketErrorOperationInProgress (array $unlData) {
+       protected function handleSocketErrorOperationInProgress (array $socketData) {
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
        }
 
index 48495b276c62ad8b6597cdebbda5d120233afb2c..e0b4d4856d0212ead7561d4235969509eeb6bc53 100644 (file)
@@ -110,7 +110,5 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNL-DISCOVERY:configKey=' . $configKey . ',unl=' . $GLOBALS[__METHOD__][$configKey] . ' - EXIT!');
                return $GLOBALS[__METHOD__][$configKey];
        }
-}
 
-// [EOF]
-?>
+}
index d62d7a55ab7a84a17c220e9961679a62672aa161..54dd00e326ca420ab83000697514dc62c1bfc606 100644 (file)
@@ -60,9 +60,6 @@ class SocketFactory extends ObjectFactory {
                // Init instance
                $socketInstance = NULL;
 
-               // Get an instance
-               $factoryInstance = new SocketFactory();
-
                // Construct registry key
                $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
 
@@ -84,13 +81,7 @@ class SocketFactory extends ObjectFactory {
                        //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Going to use class ' . $className . ' for creating a socket resource ...');
 
                        // And call the static method
-                       $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
-
-                       // Debug message
-                       //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
-
-                       // Construct container class, this won't be reached if an exception is thrown
-                       $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+                       $socketInstance = call_user_func($className . '::createConnectionFromPackageData', $packageData);
 
                        // Register it with the registry
                        Registry::getRegistry()->addInstance($registryKey, $socketInstance);
index 079ceea80567a0bdcc243b0313e00c257086ed03..8e59424f0ee33abec95d8fdef4cd20f6510fe413 100644 (file)
@@ -4,7 +4,7 @@ namespace Hub\Handler\Protocol;
 
 // Import application-specific sutff
 use Hub\Handler\Protocol\HandleableProtocol;
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 use Hub\Tools\HubTools;
 
 /**
@@ -90,13 +90,14 @@ class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
         *     'extra'    => 'port'
         * )
         *
-        * The value for 'extra' then must be handled by parseUniversalNodeLocator()
-        * of the individual protocol handler as this is protocol-specific.
+        * The value for 'extra' then must be handled by the overwriting
+        * parseUniversalNodeLocator() method of the individual protocol handler as
+        * this is protocol-specific.
         *
         * @param       $unl            Universal Node Locator (UNL) to "parse"
-        * @return      $unlData        Array with all components of the UNL
+        * @return      $unlInstance    An instance of a LocateableNode class
         */
-       protected function parseGenericUniversalNodeLocator ($unl) {
+       protected function parseUniversalNodeLocator ($unl) {
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!');
 
@@ -114,16 +115,20 @@ class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
 
                // Now there is an almost useable array which then can be copied to the "real" array.
                $unlData = array(
-                       UniversalNodeLocator::UNL_PART_PROTOCOL => $unlParts[0],
-                       UniversalNodeLocator::UNL_PART_ADDRESS  => $unlParts[1][0],
-                       UniversalNodeLocator::UNL_PART_EXTRA    => $unlParts[1][1]
+                       LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
+                       LocateableNode::UNL_PART_ADDRESS  => $unlParts[1][0],
+                       LocateableNode::UNL_PART_EXTRA    => $unlParts[1][1]
                );
 
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
 
-               // Return the generic array
-               return $unlData;
+               // Create instance from it
+               //$unlInstance = ;
+               $this->partialStub('Please rewrite this part.');
+
+               // Return instance
+               return $unlInstance;
        }
 
        /**
@@ -158,7 +163,7 @@ class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
         */
        public function getAddressPart () {
                // Return it
-               return $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_ADDRESS);
+               return $this->getUniversalNodeLocatorDataElement(LocateableNode::UNL_PART_ADDRESS);
        }
 
        /**
index 88954cebe9e0f94b9473617cbcc17307e91fb330..49a462c24378a35b744d52f88b00e5668735f1a0 100644 (file)
@@ -3,6 +3,7 @@
 namespace Hub\Handler\Protocol\;
 
 // Import application-specific stuff
+use Hub\Handler\Protocol\Network\IpV4\BaseIpV4Handler;
 
 // Import framework stuff
 
index 3a1ff1f4848ae9acb8fd160f88c796e3db519227..70056e2633312654483bd1889c6198bdb9d92735 100644 (file)
@@ -3,7 +3,7 @@
 namespace Hub\Handler\Protocol\Network\IpV4;
 
 // Import application-specific stuff
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 use Hub\Network\Package\NetworkPackage;
 
 /**
@@ -29,9 +29,6 @@ use Hub\Network\Package\NetworkPackage;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
-       // Regular expression for validating IP:port UNLs
-       const UNL_REGEX = '/^([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$/';
-
        /**
         * Port number
         */
@@ -48,7 +45,7 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
                parent::__construct($className);
 
                // Set regex
-               $this->setRegularExpression(self::UNL_REGEX);
+               $this->setRegularExpression(LocateableNode::UNL_REGEX);
        }
 
        /**
@@ -72,48 +69,6 @@ class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
                return $this->port;
        }
 
-       /**
-        * Parses the given UNL by splitting it up in its components. The UNL ...
-        *
-        * protocol://address[:port]
-        *
-        * ... becomes:
-        *
-        * array(
-        *     'protocol' => 'value',
-        *     'address'  => 'value',
-        *     'port'     => 123
-        * )
-        *
-        * @param       $unl            Universal Node Locator (UNL) to "parse"
-        * @return      $unlData        Array with all components of the UNL
-        */
-       protected function parseUniversalNodeLocator ($unl) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!');
-
-               // First generic parse
-               $unlData = parent::parseGenericUniversalNodeLocator($unl);
-
-               /*
-                * Make sure the generic parts are all there. In case of a rewrite,
-                * these assertitions will bail out on badly formed arrays.
-                */
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]));
-
-               // Copy 'extra' -> 'port' ...
-               $unlData[UniversalNodeLocator::UNL_PART_PORT] = $unlData[UniversalNodeLocator::UNL_PART_EXTRA];
-
-               // ... and drop 'extra'
-               unset($unlData[UniversalNodeLocator::UNL_PART_EXTRA]);
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
-               return $unlData;
-       }
-
        /**
         * Validates given 'recipient' if it is a valid UNL. This means that the UNL
         * can be parsed by the protocol handler.
@@ -140,9 +95,10 @@ 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
-                       $unlInstance = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+                       $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
 
-                       // Set whole UNL data array
+                       // Set whole UNL instance
+                       // @TODO don't do this in a isValidFoo() method
                        $this->setUniversalNodeLocatorInstance($unlInstance);
 
                        // Set port
index b9799d4dc6e1b148365ed598039cb58596abb75e..f906434f538c3c81256a6b5e3861f0aa6434a3f8 100644 (file)
@@ -5,7 +5,7 @@ namespace Hub\Helper\Connection\IpV4;
 // Import application-specific stuff
 use Hub\Container\Socket\StorableSocket;
 use Hub\Helper\Connection\BaseConnectionHelper;
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 
 /**
  * A ??? connection helper class
@@ -93,35 +93,35 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper {
        }
 
        /**
-        * Attempts to connect to a peer by given IP number and port from a valid
-        * unlData array with currently configured timeout.
+        * Attempts to connect to a peer by given IP number and port from an UNL
+        * instance with currently configured timeout.
         *
-        * @param       $unlData                Valid UNL data array
+        * @param       $unlInstance    An instance of a LocateableNode class
         * @return      $isConnected    Whether the connection went fine
         * @see         Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code
         * @todo        Rewrite the while() loop to a iterator to not let the software stay very long here
         */
-       protected function connectToPeerByUnlData (array $unlData) {
+       protected function connectToPeerByUnlInstance (LocateableNode $unlInstance) {
                // Only call this if the connection is initialized by initConnection()
                assert($this->isInitialized());
 
-               // Is unlData complete?
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
-               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+               // Is the UNL data complete?
+               assert($unlInstance->isValidUnl());
 
                // "Cache" socket resource and timeout config
                $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds');
 
                // Debug output
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Trying to connect to ' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ':' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' with socketResource[' . gettype($this->getSocketInstance()->getSocketResource() . ']=' . $this->getSocketInstance()->getSocketResource() . ' ...');
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Trying to connect to ' . $unlInstance->getUnlAddress() . ':' . $unlInstance->getUnlPort() . ' with socketResource[' . gettype($this->getSocketInstance()->getSocketResource() . ']=' . $this->getSocketInstance()->getSocketResource() . ' ...');
 
                // Get current time
                $hasTimedOut = FALSE;
                $time = time();
+               $this->partialStub('Please rewrite this part.');
+               return;
 
                // Try to connect until it is connected
-               while ($isConnected = !@socket_connect($this->getSocketInstance(), $unlData[UniversalNodeLocator::UNL_PART_ADDRESS], $unlData[UniversalNodeLocator::UNL_PART_PORT])) {
+               while ($isConnected = !@socket_connect($this->getSocketInstance(), $unlData[LocateableNode::UNL_PART_ADDRESS], $unlData[LocateableNode::UNL_PART_PORT])) {
                        // Get last socket error
                        $socketError = socket_last_error($this->getSocketInstance());
 
index d89f0f235dbe9055c53da8a32bcc5def18b787ea..212d97205aa63b8800c60f52afbf8d171b667ace 100644 (file)
@@ -4,10 +4,13 @@ namespace Hub\Helper\Connection\Tcp;
 
 // Import application-specific stuff
 use Hub\Helper\Connection\ConnectionHelper;
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 use Hub\Network\Package\NetworkPackage;
 use Hub\Tools\HubTools;
 
+// Import framework stuff
+use CoreFramework\Factory\ObjectFactory;
+
 /**
  * A TCP connection helper class
  *
@@ -63,8 +66,14 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                // Create a socket instance
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
+               // Debug message
+               //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
+
+               // Construct container class, this won't be reached if an exception is thrown
+               $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+
                // Is the socket resource valid?
-               if (!is_resource($socketResource)) {
+               if (!$socketInstance->isValidSocket()) {
                        /*
                         * Something bad happened, calling handleSocketError() is not
                         * possible here because that method would throw an
@@ -74,22 +83,22 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                } // END - if
 
                // Get socket error code for verification
-               $socketError = socket_last_error($socketResource);
+               $socketError = $socketInstance->getLastSocketError();
 
                // Check if there was an error else
                if ($socketError > 0) {
                        // Handle this socket error with a faked recipientData array
-                       $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
+                       $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketInstance, array('0.0.0.0', '0'));
 
                        // Then throw again
                        throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), StorableSocket::EXCEPTION_SOCKET_CREATION_FAILED);
                } // END - if
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Setting socket resource ... (' . gettype($socketResource) . ')');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Setting socket instance ... (' . $socketInstance->__toString() . ')');
 
                // Set the resource
-               $helperInstance->setSocketResource($socketResource);
+               $helperInstance->setSocketInstance($socketInstance);
 
                // Init connection
                $helperInstance->initConnection();
@@ -115,7 +124,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                        // Is the recipient equal as configured IP
                        if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
                                // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address
-                               $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] = HubTools::determineExternalAddress();
+                               $unlAddress = HubTools::determineExternalAddress();
 
                                // Do we have ip:port match?
                                // @TODO Rewrite this test for UNLs
@@ -129,7 +138,11 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                                $recipientArray = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
 
                                // Add the port
-                               $unlData[UniversalNodeLocator::UNL_PART_PORT] = $recipientArray[UniversalNodeLocator::UNL_PART_PORT];
+                               $unlPort = $recipientArray[LocateableNode::UNL_PART_PORT];
+
+                               // Create UNL instance
+                               $this->partialStub('Please rewrite this part.');
+                               //$unlInstance =;
                        } else {
                                // It doesn't match, we need to take care of this later
                                $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . '!=' . $helperInstance->getConfigInstance()->getConfigEntry('external_address'));
@@ -141,7 +154,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                $helperInstance->setConnectionPort($unlInstance->getUnlPort());
 
                // Now connect to it
-               if (!$helperInstance->connectToPeerByUnlData($unlData)) {
+               if (!$helperInstance->connectToPeerByUnlInstance($unlData)) {
                        // Debug message
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: helperInstance=' . $helperInstance->__toString() . ',unlData=' . print_r($unlData, TRUE));
 
index 0eb2b484f9c5f98ed53081c74abdc65140113f7c..3da29129c2bb02cb7d2829305e314125fafeb660 100644 (file)
@@ -6,7 +6,7 @@ namespace Hub\Information\Connection;
 use Hub\Helper\Connection\ConnectionHelper;
 use Hub\Information\BaseInfo;
 use Hub\Information\ShareableInfo;
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 
 // Import framework stuff
 use CoreFramework\Listener\Listenable;
@@ -70,8 +70,8 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
 
                // Fill the generic array with several data from the listener:
                $this->setProtocolName($listenerInstance->getProtocolName());
-               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
-               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $listenerInstance->getListenPort());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT    , $listenerInstance->getListenPort());
 
                // Set listener here
                $this->setListenerInstance($listenerInstance);
@@ -92,8 +92,8 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
 
                // Fill the generic array with several data from the listener:
                $this->setProtocolName($helperInstance->getProtocolName());
-               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $helperInstance->getAddress());
-               $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $helperInstance->getConnectionPort());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $helperInstance->getAddress());
+               $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT    , $helperInstance->getConnectionPort());
 
                // Set helper here
                $this->setHelperInstance($helperInstance);
@@ -109,7 +109,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
         */
        public final function getAddress () {
                // Return it from generic array
-               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
+               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS);
        }
 
        /**
@@ -119,7 +119,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
         */
        public final function getPort () {
                // Return it from generic array
-               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
+               return $this->getGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT);
        }
 
 }
index 999d95063e507a593c9c37ec92d7df24ea22027b..25d92a783f97699bf26a940a298dfc477717a988 100644 (file)
@@ -29,16 +29,6 @@ use Hub\Generic\BaseHubSystem;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class UniversalNodeLocator extends BaseHubSystem implements LocateableNode {
-       //------- UNL parts -------
-       // Protocol
-       const UNL_PART_PROTOCOL = 'protocol';
-       // Address
-       const UNL_PART_ADDRESS  = 'address';
-       // Extra part
-       const UNL_PART_EXTRA    = 'extra';
-       // Port (if any)
-       const UNL_PART_PORT     = 'port';
-
        /**
         * UNL data array
         */
index d8272757f3c2dda9964902e77c40edb4c2ba29ad..b5ee6eb7bc4ef1b9f9d689409e5b1cf30b7efdc4 100644 (file)
@@ -4,7 +4,7 @@ namespace Hub\Pool\Peer;
 
 // Import application-specific stuff
 use Hub\Container\Socket\StorableSocket;
-use Hub\Locator\Node\UniversalNodeLocator;
+use Hub\Locator\Node\LocateableNode;
 use Hub\Network\Package\NetworkPackage;
 use Hub\Pool\BasePool;
 use Hub\Pool\Peer\PoolablePeer;
@@ -227,12 +227,12 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                $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]));
+               assert(isset($unlData[LocateableNode::UNL_PART_PROTOCOL]));
+               assert(isset($unlData[LocateableNode::UNL_PART_ADDRESS]));
+               assert(isset($unlData[LocateableNode::UNL_PART_PORT]));
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . UniversalNodeLocator::UNL_PART_ADDRESS . ']=' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ',unlData[' . UniversalNodeLocator::UNL_PART_PORT . ']=' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . LocateableNode::UNL_PART_ADDRESS . ']=' . $unlData[LocateableNode::UNL_PART_ADDRESS] . ',unlData[' . LocateableNode::UNL_PART_PORT . ']=' . $unlData[LocateableNode::UNL_PART_PORT] . ' ...');
 
                // Default is all sockets
                $sockets = $this->getAllSockets();
@@ -267,7 +267,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
 
                        // Get
                        // If the "peer" IP and recipient is same, use it
-                       if ($peerAddress == $unlData[UniversalNodeLocator::UNL_PART_ADDRESS]) {
+                       if ($peerAddress == $unlData[LocateableNode::UNL_PART_ADDRESS]) {
                                // IPs match, so take the socket and quit this loop
                                $socketInstance = $socketArray[self::SOCKET_ARRAY_INSTANCE];
 
index 4e4ba6b2c863548a0bb2558eb2c60f6b4bfd455b..79575b8b871aadbd5f2affb903ad3f144d511b86 100644 (file)
@@ -31,7 +31,7 @@ interface HandleableProtocol extends Handleable {
        /**
         * Getter for UNL instance
         *
-        * @return      $unlData        An instance of a LocateableNode class
+        * @return      $unlInstance    An instance of a LocateableNode class
         */
        function getUniversalNodeLocatorInstance ();
 
index c9c98454abeeaa7ffbaa371155d444887224dc1f..6ae4a6ad55a454d7cdcc4f53fa95e2dce1beca47 100644 (file)
@@ -28,6 +28,21 @@ use Hub\Generic\HubInterface;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface LocateableNode extends HubInterface {
+       //------- UNL parts -------
+       // Protocol
+       const UNL_PART_PROTOCOL = 'protocol';
+       // Address
+       const UNL_PART_ADDRESS  = 'address';
+       // Extra part
+       const UNL_PART_EXTRA    = 'extra';
+       // Port (if any)
+       const UNL_PART_PORT     = 'port';
+
+       /**
+        * Regular expression for validating IP:port UNLs
+        */
+       const UNL_REGEX = '/^([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})$/';
+
        /**
         * Getter for external UNL
         *
index 624362f75d1a3cfec17fd282aa61c52c3ed638fe..0bea55e041426bd14d8b41425161b1e3e3783030 100644 (file)
@@ -46,7 +46,5 @@ interface ProtocolResolver extends HubInterface {
         * @return      $unl            Universal node locator
         */
        function resolveUniversalNodeLocatorFromConfigKey ($configKey);
-}
 
-// [EOF]
-?>
+}