* @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)) {
} // 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
// 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());