]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php
Continued refacturing:
[hub.git] / application / hub / main / discovery / recipient / socket / class_PackageSocketDiscovery.php
index b36aee53aedfb3a88942d11a19d094caea0592d8..7d2d8bfac9c6b44f2e8e95e46c82aa8d40c24504 100644 (file)
@@ -101,21 +101,30 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
         * @return      $socketResource         A valid socket resource or FALSE if an error occured
         * @throws      NoListGroupException    If the procol group is not found in peer list
         * @throws      NullPointerException    If listenerInstance is NULL
+        * @throws      InvalidUnlException             If the provided UNL cannot be validated by the protocol handler
         */
        public function discoverSocket (array $packageData, $connectionType) {
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!');
 
-               // Assert on type
+               // Assert on type and recipient
                assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
+               assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
-               // Determine protocol name
-               $protocolName = $this->determineProtocolByPackageData($packageData);
+               // Determine protocol instance
+               $protocolInstance = $this->determineProtocolByPackageData($packageData);
 
-               // Is it the same?
-               assert(strtoupper($protocolName) == $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]);
+               // Is it valid?
+               assert($protocolInstance instanceof HandleableProtocol);
+
+               // Does the UNL validate?
+               if (!$protocolInstance->isValidUniversalNodeLocatorByPackageData($packageData)) {
+                       // Not valid, throw exception
+                       throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL);
+               } // END - if
+               die(__METHOD__ . ':protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
 
                // Get the listener instance
-               $listenerInstance = $this->discoverListenerInstance($protocolName, $packageData);
+               $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);
 
                // If there is no listener who wants to have that package, we simply drop it here
                if (is_null($listenerInstance)) {
@@ -124,7 +133,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
                } // END - if
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, TRUE));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
 
                /*
                 * Now we have the listener instance, we can determine the right
@@ -146,10 +155,10 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
                        // Try to create a new socket resource
                        try {
                                // Possibly noisy debug message
-                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+                               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
 
                                // Get a socket resource from our factory (if succeeded)
-                               $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
+                               $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance);
                        } catch (SocketConnectionException $e) {
                                // The connection fails of being established, so log it away
                                self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());