// CFG: UNL-DISCOVERY-CLASS
$cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery');
-// CFG: PROTOCOL-DISCOVERY-CLASS
-$cfg->setConfigEntry('protocol_discovery_class', 'ProtocolDiscovery');
-
// CFG: TCP-PROTOCOL-HANDLER-CLASS
$cfg->setConfigEntry('tcp_protocol_handler_class', 'TcpProtocolHandler');
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface DiscoverableProtocol extends Discoverable {
- /**
- * "Discovers" the protocol type from given raw package data. This is done
- * by looking at the 'recipient' field and extract the first part from it.
- *
- * @param $packageData Raw package data
- * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
- */
- function discoverProtocolByPackageData (array $packageData);
}
// [EOF]
/**
* Fills the information class with data from a Listenable instance
*
- * @param $listenerInstanc An instance of a Listenable class
+ * @param $listenerInstance An instance of a Listenable class
* @return void
*/
function fillWithListenerInformation (Listenable $listenerInstance);
+
+ /**
+ * Fills the information class with data from a ConnectionHelper instance
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance);
}
// [EOF]
*/
private $assemblerInstance = NULL;
+ /**
+ * Info instance
+ */
+ private $infoInstance = NULL;
+
/**
* Name of used protocol
*/
return $this->assemblerInstance;
}
+ /**
+ * Setter for info instance
+ *
+ * @param $infoInstance A ShareableInfo instance
+ * @return void
+ */
+ protected final function setInfoInstance (ShareableInfo $infoInstance) {
+ $this->infoInstance = $infoInstance;
+ }
+
+ /**
+ * Getter for info instance
+ *
+ * @return $infoInstance A Decodeable instance
+ */
+ public final function getInfoInstance () {
+ return $this->infoInstance;
+ }
+
/**
* Setter for node id
*
return $discoveryInstance;
}
+ /**
+ * Determines the protoctol name
+ *
+ * @param $packageData Valid package data
+ * @return $protocolInstance An instance of a HandleableProtocol class
+ */
+ public static final function determineProtocolByPackageData (array $packageData) {
+ // First we need a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ /*
+ * We need to decide here which socket (TCP or UDP) should be used for
+ * the actual data transmission. In this process we will find out if
+ * the recipient of this package has already a known (registered) socket
+ * and if so we can re-use it. If there is no socket registered, we try
+ * to make a new connection to the given Universal Node Locator.
+ */
+ $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
+
+ // Return it
+ return $protocolInstance;
+ }
+
/**
* "Discovers" the protocol type from given raw package data. This is done
* by looking at the 'recipient' field and extract the first part from it.
* @param $packageData Raw package data
* @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
*/
- public function discoverProtocolByPackageData (array $packageData) {
+ public static final function discoverProtocolByPackageData (array $packageData) {
//* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
/*
$this->setListInstance($listInstance);
}
- /**
- * Determines the protoctol name
- *
- * @param $packageData Valid package data
- * @return $protocolInstance An instance of a HandleableProtocol class
- */
- protected function determineProtocolByPackageData (array $packageData) {
- // First we need a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- /*
- * We need to decide here which socket (TCP or UDP) should be used for
- * the actual data transmission. In this process we will find out if
- * the recipient of this package has already a known (registered) socket
- * and if so we can re-use it. If there is no socket registered, we try
- * to make a new connection to the given Universal Node Locator.
- */
- $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
-
- // Return it
- return $protocolInstance;
- }
-
/**
* "Getter" for recipient iterator
*
*/
public function discoverRawRecipients (array $decodedData) {
// This must be available
- die(__METHOD__ . ': Unfinished' . PHP_EOL);
assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
// First clear all recipients
$this->clearRecipients();
- // Explode 'recipient', first element is the IP/hostname
- $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ // Get a protocol handler back from decoded data
+ $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($decodedData);
// Is the 'recipient' field same as this peer's IP?
- if ((($recipient[0] == HubTools::determineOwnExternalAddress()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) {
+ if ($handlerInstance->isOwnAddress()) {
/*
* Is same as own external address + TCP/UDP listen port or
* internal address, don't do anything here so other classes found
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
// This package is to be delivered to someone else, so add it
- $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ //$this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
}
+ die(__METHOD__ . ': Unfinished!' . PHP_EOL);
}
}
assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
// Determine protocol instance
- $protocolInstance = $this->determineProtocolByPackageData($packageData);
+ $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData);
// Is it valid?
assert($protocolInstance instanceof HandleableProtocol);
* @return $handlerInstance A protocol handler instance
*/
public static final function createProtocolHandlerFromPackageData (array $packageData) {
- // Now that there is no direct node instance available, a protocol discovery class is required
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('protocol_discovery_class');
-
// "Discover" the protocol type
- $protocolType = $discoveryInstance->discoverProtocolByPackageData($packageData);
+ $protocolType = ProtocolDiscovery::discoverProtocolByPackageData($packageData);
// Call super factory method
return self::createProtocolHandlerByType($protocolType);
/**
* Returns a singleton (registry-based) ShareableInfo instance
*
+ * @param $protocolName Name of protocol (e.g. 'tcp')
+ * @param $type Connection type ('listener' or 'helper')
* @return $infoInstance An instance of a ShareableInfo class
*/
- public static final function createConnectionInfoInstance () {
+ public static final function createConnectionInfoInstance ($protocolName, $type) {
+ // Generate key
+ $key = 'connection_info_' . $protocolName . '_' . $type;
+
// If there is no info?
- if (Registry::getRegistry()->instanceExists('connection_info')) {
+ if (Registry::getRegistry()->instanceExists($key)) {
// Get info from registry
- $infoInstance = Registry::getRegistry()->getInstance('connection_info');
+ $infoInstance = Registry::getRegistry()->getInstance($key);
} else {
// Get the info instance
$infoInstance = self::createObjectByConfiguredName('connection_info_class');
// Add it to the registry
- Registry::getRegistry()->addInstance('connection_info', $infoInstance);
+ Registry::getRegistry()->addInstance($key, $infoInstance);
}
// Return the instance
// Try to solve the recipient
try {
- // Resolve any session ids; 0 = IP, 1 = Port
+ // Get protocol handler back from package data
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
// Get UNL data
/**
* Fills the information class with data from a Listenable instance
*
- * @param $listenerInstanc An instance of a Listenable class
+ * @param $listenerInstance An instance of a Listenable class
* @return void
*/
public function fillWithListenerInformation (Listenable $listenerInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $listenerInstance->getProtocolName() . ',listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
+
// Fill the generic array with several data from the listener:
$this->setProtocolName($listenerInstance->getProtocolName());
- $this->setGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
- $this->setGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $listenerInstance->getListenPort());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT , $listenerInstance->getListenPort());
// Set listener here
$this->setListenerInstance($listenerInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ }
+
+ /**
+ * Fills the information class with data from a ConnectionHelper instance
+ *
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @return void
+ */
+ public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!');
+
+ // 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());
+
+ // Set helper here
+ $this->setHelperInstance($helperInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
*/
public final function getAddress () {
// Return it from generic array
- return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
+ return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
}
/**
*/
public final function getPort () {
// Return it from generic array
- return $this->getGenericArrayElement('listen', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
+ return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
}
}
$registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
// Get a connection info instance
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
// Will the info instance with listener data
$infoInstance->fillWithListenerInformation($this);
$registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
// Get a connection info instance
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
// Will the info instance with listener data
$infoInstance->fillWithListenerInformation($this);
);
// Get a connection info instance
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
// Will the info instance with listener data
$infoInstance->fillWithListenerInformation($this);
$unl = $this->detectOwnUniversalNodeLocator();
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
// Now check if the IP address matches one of the bootstrap nodes
if ($this->ifAddressMatchesBootstrapNodes($unl)) {
assert($helperInstance instanceof ConnectionHelper);
// Get connection info class
- $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance();
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
// Will the info instance with connection helper data
$infoInstance->fillWithConnectionHelperInformation($helperInstance);
$sentBytes = 0;
// Get the right connection instance
- $helperInstance = SocketRegistryFactory::createSocketRegistryInstance()->getHandlerInstanceFromPackageData($packageData);
+ $infoInstance = SocketRegistryFactory::createSocketRegistryInstance()->getInfoInstanceFromPackageData($packageData);
// Test helper instance
+ assert($infoInstance instanceof ShareableInfo);
+
+ // Get helper instance
+ $helperInstance = $infoInstance->getHelperInstance();
+
+ // Some sanity-checks on the object
+ //* DEBUG-DIE: */ die('[' . __METHOD__ . ':' . __LINE__ . ']: p1=' . $infoInstance->getProtocolName() . ',p2=' . $helperInstance->getProtocolName() . ',infoInstance=' . print_r($infoInstance, TRUE));
assert($helperInstance instanceof ConnectionHelper);
+ assert($infoInstance->getProtocolName() == $helperInstance->getProtocolName());
// Is this connection still alive?
if ($helperInstance->isShuttedDown()) {
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A Connection registry
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 ConnectionRegistry extends BaseRegistry implements Register, RegisterableConnection {
- // Exception constants
- const CONNECTION_NOT_REGISTERED = 0xd100;
-
- /**
- * Instance of this class
- */
- private static $registryInstance = NULL;
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates a singleton instance of this registry class
- *
- * @return $registryInstance An instance of this class
- */
- public static final function createConnectionRegistry () {
- // Is an instance there?
- if (is_null(self::$registryInstance)) {
- // Not yet, so create one
- self::$registryInstance = new ConnectionRegistry();
- } // END - if
-
- // Return the instance
- return self::$registryInstance;
- }
-
- /**
- * "Getter" to get a string respresentation for a key for the sub-registry
- * in this format: class:type:port
- *
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @return $key A string representation of the socket for the registry
- */
- private function getSubRegistryKey (ConnectionHelper $connectionInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: connectionInstance=' . $connectionInstance->__toString() . ' CALLED!');
-
- // Get connection type and port number and add both together
- $key = sprintf('%s:%s:%s',
- $connectionInstance->__toString(),
- $connectionInstance->getConnectionType(),
- $connectionInstance->getConnectionPort()
- );
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ' - EXIT!');
-
- // Return resulting key
- return $key;
- }
-
- /**
- * "Getter" to get a string respresentation of the protocol
- *
- * @param $infoInstance An instance of a ShareableInfo class
- * @return $key A string representation of the protocol for the registry
- */
- private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) {
- // Get the key
- $key = $infoInstance->getProtocolName();
-
- // Return resulting key
- return $key;
- }
-
- /**
- * Checks whether the given protocol is registered
- *
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @return $isRegistered Whether the protocol is registered
- */
- private function isConnectionRegistered (ConnectionHelper $connectionInstance) {
- // Get the key
- $key = $this->getRegistryKeyFromInfo($connectionInstance);
-
- // Determine it
- $isRegistered = $this->instanceExists($key);
-
- // Return result
- return $isRegistered;
- }
-
- /**
- * Checks whether given socket resource is registered. If $socketResource is
- * FALSE only the instance will be checked.
- *
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @param $socketResource A valid socket resource
- * @return $isRegistered Whether the given socket resource is registered
- */
- public function isConnectionRegistered (ConnectionHelper $connectionInstance, $socketResource) {
- // Default is not registered
- $isRegistered = FALSE;
-
- // First, check for the instance, there can be only once
- if ($this->isConnectionRegistered($connectionInstance)) {
- // That one is found so "get" a registry key from it
- $key = $this->getRegistryKeyFromInfo($connectionInstance);
-
- // Get the registry
- $registryInstance = $this->getInstance($key);
-
- // "Get" a key for the socket
- $socketKey = $this->getSubRegistryKey($connectionInstance);
-
- // And simply ask it
- $isRegistered = $registryInstance->instanceExists($socketKey);
- } // END - if
-
- // Return the result
- return $isRegistered;
- }
-
- /**
- * Registeres given socket for listener or throws an exception if it is already registered
- *
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @param $socketResource A valid socket resource
- * @param $packageData Optional raw package data
- * @throws ConnectionAlreadyRegisteredException If the given socket is already registered
- * @return void
- */
- public function registerConnection (ConnectionHelper $connectionInstance, $socketResource, array $packageData = array()) {
- // Is the socket already registered?
- if ($this->isConnectionRegistered($connectionInstance, $socketResource)) {
- // Throw the exception
- throw new ConnectionAlreadyRegisteredException(array($connectionInstance, $socketResource), BaseListener::EXCEPTION_CONNECTION_ALREADY_REGISTERED);
- } // END - if
-
- // Does the instance exist?
- if (!$this->isConnectionRegistered($connectionInstance)) {
- // No, not found so we create a sub registry (not needed to configure!)
- $registryInstance = SubRegistry::createSubRegistry();
-
- // Now we can create the sub-registry for this protocol
- $this->addInstance($this->getRegistryKeyFromInfo($connectionInstance), $registryInstance);
- } else {
- // Get the sub-registry back
- $registryInstance = $this->getInstance($this->getRegistryKeyFromInfo($connectionInstance));
- }
-
- // Get a key for sub-registries
- $socketKey = $this->getSubRegistryKey($connectionInstance);
-
- // Get a socket container
- $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $connectionInstance, $packageData));
-
- // We have a sub-registry, the socket key and the socket, now we need to put all together
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource=' . $socketResource . ' - adding socket container instance ...');
- $registryInstance->addInstance($socketKey, $socketInstance);
- }
-
- /**
- * Getter for given listener's socket resource
- *
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @return $socketResource A valid socket resource
- * @throws NoConnectionRegisteredException If the requested socket is not registered
- */
- public function getRegisteredConnectionResource (ConnectionHelper $connectionInstance) {
- // The socket must be registered before we can return it
- if (!$this->isConnectionRegistered($connectionInstance, FALSE)) {
- // Throw the exception
- throw new NoConnectionRegisteredException ($connectionInstance, self::CONNECTION_NOT_REGISTERED);
- } // END - if
-
- // Now get the key from the protocol
- $key = $this->getRegistryKeyFromInfo($connectionInstance);
-
- // And get the registry
- $registryInstance = $this->getInstance($key);
-
- // Get a socket key
- $socketKey = $this->getSubRegistryKey($connectionInstance);
-
- // And the final socket resource
- $socketResource = $registryInstance->getInstance($socketKey)->getConnectionResource();
-
- // Return the resource
- return $socketResource;
- }
-
- /**
- * "Getter" for protocol/connection instance from given package data
- *
- * @param $packageData Raw package data
- * @return $connectionInstance An instance of a ConnectionHelper class
- */
- public function getHandlerInstanceFromPackageData (array $packageData) {
- // Init protocol instance
- $connectionInstance = NULL;
-
- // Get all keys and check them
- foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
-
- // This is always a SubRegistry instance
- foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
-
- // This is a ConnectionContainer instance, so does the recipient match?
- if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
- // Found one, so get the protocol instance and abort any further search
- $connectionInstance = $containerInstance->getProtocolInstance();
- break;
- } // END - if
- } // END - foreach
- } // END - foreach
-
- // Return the protocol instance
- return $connectionInstance;
- }
-}
-
-// [EOF]
-?>
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: infoInstance=' . $infoInstance->__toString() . ' - ENTERED!');
- // Default address is invalid
- $address = '*invalid*';
- $port = 0;
-
// Get address and port
$address = $infoInstance->getAddress();
$port = $infoInstance->getPort();
*/
private function isInfoRegistered (ShareableInfo $infoInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ' - ENTERED!');
// Get the key
$key = $this->getRegistryKeyFromInfo($infoInstance);
$isRegistered = $this->instanceExists($key);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return result
return $isRegistered;
*/
public function isSocketRegistered (ShareableInfo $infoInstance, $socketResource) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
// Default is not registered
$isRegistered = FALSE;
$key = $this->getRegistryKeyFromInfo($infoInstance);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
// Get the registry
$registryInstance = $this->getInstance($key);
$socketKey = $this->getSubRegistryKey($infoInstance);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: this=' . $this->__toString() . ',info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
// Is it there?
if ($registryInstance->instanceExists($socketKey)) {
} // END - if
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return the result
return $isRegistered;
*/
public function registerSocket (ShareableInfo $infoInstance, $socketResource, array $packageData = array()) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:info=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
// Is the socket already registered?
if ($this->isSocketRegistered($infoInstance, $socketResource)) {
}
/**
- * "Getter" for protocol/connection instance from given package data
+ * "Getter" for info instance from given package data
*
- * @param $packageData Raw package data
- * @return $protocolInstance An instance of a HandleableProtocol class
+ * @param $packageData Raw package data
+ * @return $infoInstance An instance of a ShareableInfo class
*/
- public function getHandlerInstanceFromPackageData (array $packageData) {
- // Init protocol instance
- $protocolInstance = NULL;
- //* DIE-DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+ public function getInfoInstanceFromPackageData (array $packageData) {
+ // Init info instance
+ $infoInstance = NULL;
+ //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get all keys and check them
foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
// This is always a SubRegistry instance
foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
// Is this a SocketContainer instance and is the address the same?
if (($containerInstance instanceof SocketContainer) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) {
- // Found one, so get the protocol instance and abort any further search
- $protocolInstance = $containerInstance->getProtocolInstance();
+ // Debug die
+ //* DEBUG-DIE: */ die(__METHOD__ . ': containerInstance=' . print_r($containerInstance, TRUE));
+
+ // Get listener and helper instances
+ $listenerInstance = $containerInstance->getListenerInstance();
+ $helperInstance = $containerInstance->getHelperInstance();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+
+ // Is a listener or helper set?
+ if ($listenerInstance instanceof Listenable) {
+ // Found a listener, so get the info instance first
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($listenerInstance->getProtocolName(), 'helper');
+
+ // Fill info instance with listener data
+ $infoInstance->fillWithListenerInformation($listenerInstance);
+ } elseif ($helperInstance instanceof ConnectionHelper) {
+ // Found a helper, so get the info instance first
+ $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($helperInstance->getProtocolName(), 'helper');
+
+ // Helper is found
+ $infoInstance->fillWithConnectionHelperInformation($helperInstance);
+ } else {
+ // Not supported state!
+ $this->debugInstance('[' . __METHOD__ . ':' . __LINE__ . ']: Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL);
+ }
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',protocolInstance[]=' . gettype($protocolInstance) . ' - FOUND!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: key=' . $key . ',subKey=' . $subKey . ',infoInstance[' . gettype($infoInstance) . ']=' . $infoInstance->__toString() . ' with protocol ' . $infoInstance->getProtocolName() . ' - FOUND!');
break;
} // END - if
} // END - foreach
+
+ // Is no longer NULL set?
+ if (!is_null($infoInstance)) {
+ // Then skip here, too
+ break;
+ } // END - if
} // END - foreach
- // Return the protocol instance
- return $protocolInstance;
+ // Return the info instance
+ return $infoInstance;
}
}
-Subproject commit fd8bfc0a9fdc898d7158029673b9dc42ad7fdf01
+Subproject commit 12417a7382d7ab76dacb985819e30b57db01f1fd