From 785928b75c6a993d7c54ed9361337538619a5a29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 29 May 2017 18:21:42 +0200 Subject: [PATCH] Continued: - implemented UniversalNodeLocatorFactory + imported it - imported Registerable - imported NullPointerException - imported BaseIpV4ConnectionHelper - basically finished getUnlPort() and parse methods - basically finished DefaultPeerPool lookup loop - more debugging + getRequestInstance() - added missing namespaces - added getUnlPort() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../class_PackageRecipientDiscovery.php | 2 +- .../socket/class_PackageSocketDiscovery.php | 16 +- application/hub/classes/factories/class_ | 4 +- .../class_SocketDiscoveryFactory.php | 4 +- .../hub/classes/factories/locator/.htaccess | 1 + .../class_UniversalNodeLocatorFactory.php | 82 +++++++ .../class_AptProxyWelcomeTeaserFilter.php | 4 +- ...ProxyBootstrapExtraBootstrappingFilter.php | 4 +- ..._ChatBootstrapExtraBootstrappingFilter.php | 4 +- ...awlerBootstrapExtraBootstrappingFilter.php | 4 +- ...ncherBootstrapExtraBootstrappingFilter.php | 4 +- ...MinerBootstrapExtraBootstrappingFilter.php | 4 +- ..._NodeBootstrapExtraBootstrappingFilter.php | 4 +- ...lass_NodeBootstrapGenerateNodeIdFilter.php | 4 +- ...s_NodeBootstrapGenerateSessionIdFilter.php | 4 +- .../class_NodeBootstrapListenerPoolFilter.php | 4 +- .../chat/class_ChatWelcomeTeaserFilter.php | 4 +- application/hub/classes/filter/class_ | 4 +- .../class_CrawlerWelcomeTeaserFilter.php | 4 +- .../class_CruncherInitializationFilter.php | 4 +- .../class_CruncherWelcomeTeaserFilter.php | 4 +- .../miner/class_MinerInitializationFilter.php | 4 +- .../node/class_NodeInitializationFilter.php | 4 +- .../node/class_NodeWelcomeTeaserFilter.php | 4 +- .../class_AptProxyShutdownFilter.php | 4 +- .../chat/class_ChatShutdownFilter.php | 4 +- .../crawler/class_CrawlerShutdownFilter.php | 4 +- .../cruncher/class_CruncherShutdownFilter.php | 4 +- .../miner/class_MinerShutdownFilter.php | 4 +- .../filter/shutdown/node/class_NodeShutdown | 4 +- .../class_NodeShutdownFlushNodeListFilter.php | 4 +- .../node/class_NodeShutdownNodeFilter.php | 4 +- .../class_NodeShutdownTaskHandlerFilter.php | 4 +- .../class_BaseMessageHandler.php | 2 +- .../class_NodeMessageSelfConnectHandler.php | 2 +- .../protocol/class_BaseProtocolHandler.php | 73 +------ .../ipv4/class_BaseIpV4ProtocolHandler.php | 1 + .../ipv4/class_BaseIpV4ConnectionHelper.php | 2 +- .../ipv4/tcp/class_TcpConnectionHelper.php | 7 +- .../ipv4/udp/class_UdpConnectionHelper.php | 3 +- .../hub/classes/lists/hub/class_HubList.php | 2 +- .../lists/recipient/class_RecipientList.php | 2 +- .../locator/class_UniversalNodeLocator.php | 203 ++++++++++++++---- .../hub/classes/pools/class_BasePool.php | 2 +- .../pools/peer/class_DefaultPeerPool.php | 59 ++--- .../class_CruncherTestUnitProducer.php | 2 +- .../registry/socket/class_SocketRegistry.php | 2 +- .../tcp/class_TcpProtocolResolver.php | 3 +- .../class_CrawlerUploadedListUrlSource.php | 1 + .../template/class_BaseXmlTemplateEngine.php | 2 +- application/hub/config.php | 4 +- .../container/socket/class_StorableSocket.php | 6 +- .../locator/class_LocateableNode.php | 16 ++ .../hub/interfaces/pool/class_Poolable.php | 8 + .../pool/peer/class_PoolablePeer.php | 11 +- core | 2 +- index.php | 2 +- 57 files changed, 379 insertions(+), 255 deletions(-) create mode 100644 application/hub/classes/factories/locator/.htaccess create mode 100644 application/hub/classes/factories/locator/class_UniversalNodeLocatorFactory.php diff --git a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php index feb0bc4ee..bd6de781c 100644 --- a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php +++ b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -89,7 +89,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData); } catch (FrameworkException $e) { // Could not find class, what ever failed - $this->debugInstance($e->getMessage()); + $this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage())); } } } diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index 695a197fb..dc1205db1 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -15,6 +15,7 @@ use Hub\Listener\Listenable; use Hub\Network\Package\NetworkPackage; // Import framework stuff +use CoreFramework\Generic\NullPointerException; use CoreFramework\Registry\Registerable; use CoreFramework\Registry\Registry; use CoreFramework\Socket\InvalidSocketException; @@ -146,6 +147,9 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera // Determine protocol instance $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE)); + // Is it valid? assert($protocolInstance instanceof HandleableProtocol); @@ -158,15 +162,15 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera // Get the listener instance $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('listenerInstance=' . $listenerInstance . ',packageData=' . print_r($packageData, TRUE)); + // If there is no listener who wants to have that package, we simply drop it here if (is_null($listenerInstance)) { // Abort with no resource throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } // END - if - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE)); - /* * Now we have the listener instance, we can determine the right * resource to continue. The first step is to get the attached pool @@ -176,14 +180,14 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera $socketInstance = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: socketInstance[]=%s', gettype($socketInstance))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: socketInstance[]=%s', gettype($socketInstance))); // Is it FALSE, the recipient isn't known to us and we have no connection to it - if (($socketInstance instanceof StorableSocket) || (!$socketInstance->isValidSocket()) || ($socketInstance->getLastSocketErrorCode() > 0)) { + if (!($socketInstance instanceof StorableSocket) || ($socketInstance->isValidSocket()) || ($socketInstance->getLastSocketErrorCode() > 0)) { // Try to create a new socket resource try { // Possibly noisy debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...'); // Get a socket resource from our factory (if succeeded) $socketInstance = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance); diff --git a/application/hub/classes/factories/class_ b/application/hub/classes/factories/class_ index 0dbb3ddf8..8d01b5494 100644 --- a/application/hub/classes/factories/class_ +++ b/application/hub/classes/factories/class_ @@ -60,7 +60,5 @@ class ???Factory extends ObjectFactory { // Return the instance return $%%%Instance; } -} -// [EOF] -?> +} diff --git a/application/hub/classes/factories/discovery/class_SocketDiscoveryFactory.php b/application/hub/classes/factories/discovery/class_SocketDiscoveryFactory.php index 46ce751c4..6ae971b2f 100644 --- a/application/hub/classes/factories/discovery/class_SocketDiscoveryFactory.php +++ b/application/hub/classes/factories/discovery/class_SocketDiscoveryFactory.php @@ -62,7 +62,5 @@ class SocketDiscoveryFactory extends ObjectFactory { // Return the instance return $discoveryInstance; } -} -// [EOF] -?> +} diff --git a/application/hub/classes/factories/locator/.htaccess b/application/hub/classes/factories/locator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/classes/factories/locator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/classes/factories/locator/class_UniversalNodeLocatorFactory.php b/application/hub/classes/factories/locator/class_UniversalNodeLocatorFactory.php new file mode 100644 index 000000000..df00afa0d --- /dev/null +++ b/application/hub/classes/factories/locator/class_UniversalNodeLocatorFactory.php @@ -0,0 +1,82 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 . + */ +class UniversalNodeLocatorFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) LocateableNode instance + * + * @param $unl UNL address + * @return $unlInstance An instance of a LocateableNode class + */ + public static final function createUnlInstanceFromString ($unl) { + // If there is no handler? + if (Registry::getRegistry()->instanceExists('unl_' . $unl)) { + // Get handler from registry + $unlInstance = Registry::getRegistry()->getInstance('unl_' . $unl); + } else { + // Get the handler instance + $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class'); + + // Parse UNL string + $unlInstance->parseStringAsUnl($unl); + + // Add it to the registry + Registry::getRegistry()->addInstance('unl_' . $unl, $unlInstance); + } + + // Return the instance + return $unlInstance; + } + + /** + * Creates a UNL instance from given array + * + * @param $unlData Array with valid UNL data + * @return $unlInstance An instance of a LocateableNode class + */ + public static final function createUnlInstanceFromArray (array $unlData) { + // No "caching" for now + $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class', array($unlData)); + + // Return it + return $unlInstance; + } + +} diff --git a/application/hub/classes/filter/apt-proxy/class_AptProxyWelcomeTeaserFilter.php b/application/hub/classes/filter/apt-proxy/class_AptProxyWelcomeTeaserFilter.php index 262f87b33..e0272b931 100644 --- a/application/hub/classes/filter/apt-proxy/class_AptProxyWelcomeTeaserFilter.php +++ b/application/hub/classes/filter/apt-proxy/class_AptProxyWelcomeTeaserFilter.php @@ -70,7 +70,5 @@ class AptProxyWelcomeTeaserFilter extends BaseAptProxyFilter implements Filterab // Now output the teaser $proxyInstance->outputConsoleTeaser(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/apt-proxy/class_AptProxyBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/apt-proxy/class_AptProxyBootstrapExtraBootstrappingFilter.php index 21f72634f..11387169a 100644 --- a/application/hub/classes/filter/bootstrap/apt-proxy/class_AptProxyBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/apt-proxy/class_AptProxyBootstrapExtraBootstrappingFilter.php @@ -69,7 +69,5 @@ class AptProxyBootstrapExtraBootstrappingFilter extends BaseAptProxyFilter imple // Do some extra bootstrapping steps $proxyInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/chat/class_ChatBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/chat/class_ChatBootstrapExtraBootstrappingFilter.php index c230f6af0..626142f06 100644 --- a/application/hub/classes/filter/bootstrap/chat/class_ChatBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/chat/class_ChatBootstrapExtraBootstrappingFilter.php @@ -69,7 +69,5 @@ class ChatBootstrapExtraBootstrappingFilter extends BaseChatFilter implements Fi // Do some extra bootstrapping steps $chatInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/crawler/class_CrawlerBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/crawler/class_CrawlerBootstrapExtraBootstrappingFilter.php index 41cb1bf59..8ab733c1e 100644 --- a/application/hub/classes/filter/bootstrap/crawler/class_CrawlerBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/crawler/class_CrawlerBootstrapExtraBootstrappingFilter.php @@ -69,7 +69,5 @@ class CrawlerBootstrapExtraBootstrappingFilter extends BaseCrawlerFilter impleme // Do some extra bootstrapping steps $crawlerInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/cruncher/class_CruncherBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/cruncher/class_CruncherBootstrapExtraBootstrappingFilter.php index 8bd9c9470..8e3a5983d 100644 --- a/application/hub/classes/filter/bootstrap/cruncher/class_CruncherBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/cruncher/class_CruncherBootstrapExtraBootstrappingFilter.php @@ -69,7 +69,5 @@ class CruncherBootstrapExtraBootstrappingFilter extends BaseCruncherFilter imple // Do some extra bootstrapping steps $cruncherInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php index 50b2b6aa8..b6b15d394 100644 --- a/application/hub/classes/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/miner/class_MinerBootstrapExtraBootstrappingFilter.php @@ -69,7 +69,5 @@ class MinerBootstrapExtraBootstrappingFilter extends BaseMinerFilter implements // Do some extra bootstrapping steps $minerInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php index d29617999..ba33aa41c 100644 --- a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php +++ b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapExtraBootstrappingFilter.php @@ -72,7 +72,5 @@ class NodeBootstrapExtraBootstrappingFilter extends BaseNodeFilter implements Fi // Do some extra bootstrapping steps $nodeInstance->doBootstrapping(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php index fc56a95d5..4b2fcbe65 100644 --- a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php +++ b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateNodeIdFilter.php @@ -77,7 +77,5 @@ class NodeBootstrapGenerateNodeIdFilter extends BaseNodeFilter implements Filter */ $nodeInstance->bootstrapAcquireNodeId($requestInstance, $responseInstance); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php index f87c66fc2..a32e999e2 100644 --- a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php +++ b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapGenerateSessionIdFilter.php @@ -75,7 +75,5 @@ class NodeBootstrapGenerateSessionIdFilter extends BaseNodeFilter implements Fil */ $nodeInstance->bootstrapGenerateSessionId(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php index ced5bca0d..8307cd5e3 100644 --- a/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php +++ b/application/hub/classes/filter/bootstrap/node/class_NodeBootstrapListenerPoolFilter.php @@ -72,7 +72,5 @@ class NodeBootstrapListenerPoolFilter extends BaseNodeFilter implements Filterab // Now do something $nodeInstance->initializeListenerPool(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/chat/class_ChatWelcomeTeaserFilter.php b/application/hub/classes/filter/chat/class_ChatWelcomeTeaserFilter.php index 2250b18b8..e1f7b674d 100644 --- a/application/hub/classes/filter/chat/class_ChatWelcomeTeaserFilter.php +++ b/application/hub/classes/filter/chat/class_ChatWelcomeTeaserFilter.php @@ -70,7 +70,5 @@ class ChatWelcomeTeaserFilter extends BaseChatFilter implements Filterable { // Now output the teaser $chatInstance->outputConsoleTeaser(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/class_ b/application/hub/classes/filter/class_ index 0332b8470..ca5659676 100644 --- a/application/hub/classes/filter/class_ +++ b/application/hub/classes/filter/class_ @@ -73,7 +73,5 @@ class Hub!!!???Filter extends BaseHubFilter implements Filterable { // Now do something $this->partialStub('Please implement this step.'); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/crawler/class_CrawlerWelcomeTeaserFilter.php b/application/hub/classes/filter/crawler/class_CrawlerWelcomeTeaserFilter.php index ef6de3b1d..a79a21732 100644 --- a/application/hub/classes/filter/crawler/class_CrawlerWelcomeTeaserFilter.php +++ b/application/hub/classes/filter/crawler/class_CrawlerWelcomeTeaserFilter.php @@ -70,7 +70,5 @@ class CrawlerWelcomeTeaserFilter extends BaseCrawlerFilter implements Filterable // Now output the teaser $crawlerInstance->outputConsoleTeaser(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/cruncher/class_CruncherInitializationFilter.php b/application/hub/classes/filter/cruncher/class_CruncherInitializationFilter.php index 9316ab08c..d38626ec4 100644 --- a/application/hub/classes/filter/cruncher/class_CruncherInitializationFilter.php +++ b/application/hub/classes/filter/cruncher/class_CruncherInitializationFilter.php @@ -98,7 +98,5 @@ class CruncherInitializationFilter extends BaseCruncherFilter implements Filtera $this->debugBackTrace(': cruncher mode ' . $cruncherMode . ' is invalid.'); } } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/cruncher/class_CruncherWelcomeTeaserFilter.php b/application/hub/classes/filter/cruncher/class_CruncherWelcomeTeaserFilter.php index 3db78b402..9385a3e15 100644 --- a/application/hub/classes/filter/cruncher/class_CruncherWelcomeTeaserFilter.php +++ b/application/hub/classes/filter/cruncher/class_CruncherWelcomeTeaserFilter.php @@ -70,7 +70,5 @@ class CruncherWelcomeTeaserFilter extends BaseCruncherFilter implements Filterab // Now output the teaser $cruncherInstance->outputConsoleTeaser(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/miner/class_MinerInitializationFilter.php b/application/hub/classes/filter/miner/class_MinerInitializationFilter.php index 1c8224883..ec04df2f8 100644 --- a/application/hub/classes/filter/miner/class_MinerInitializationFilter.php +++ b/application/hub/classes/filter/miner/class_MinerInitializationFilter.php @@ -98,7 +98,5 @@ class MinerInitializationFilter extends BaseMinerFilter implements Filterable { $this->debugBackTrace(': miner mode ' . $minerMode . ' is invalid.'); } } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/node/class_NodeInitializationFilter.php b/application/hub/classes/filter/node/class_NodeInitializationFilter.php index d5230f65b..94df36328 100644 --- a/application/hub/classes/filter/node/class_NodeInitializationFilter.php +++ b/application/hub/classes/filter/node/class_NodeInitializationFilter.php @@ -78,7 +78,5 @@ class NodeInitializationFilter extends BaseNodeFilter implements Filterable { // Debug message //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-INIT-FILTER: Node ' . $nodeMode . ' has been added to registry.'); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/node/class_NodeWelcomeTeaserFilter.php b/application/hub/classes/filter/node/class_NodeWelcomeTeaserFilter.php index 9b33510e7..00659801d 100644 --- a/application/hub/classes/filter/node/class_NodeWelcomeTeaserFilter.php +++ b/application/hub/classes/filter/node/class_NodeWelcomeTeaserFilter.php @@ -73,7 +73,5 @@ class NodeWelcomeTeaserFilter extends BaseNodeFilter implements Filterable { // Now output the teaser $nodeInstance->outputConsoleTeaser(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/apt-proxy/class_AptProxyShutdownFilter.php b/application/hub/classes/filter/shutdown/apt-proxy/class_AptProxyShutdownFilter.php index c21995977..56e53830a 100644 --- a/application/hub/classes/filter/shutdown/apt-proxy/class_AptProxyShutdownFilter.php +++ b/application/hub/classes/filter/shutdown/apt-proxy/class_AptProxyShutdownFilter.php @@ -71,7 +71,5 @@ class AptProxyShutdownFilter extends BaseAptProxyFilter implements Filterable { // Shutdown the apt-proxy. This should be the last line $proxyInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/chat/class_ChatShutdownFilter.php b/application/hub/classes/filter/shutdown/chat/class_ChatShutdownFilter.php index c86a7f5fc..5e5be5092 100644 --- a/application/hub/classes/filter/shutdown/chat/class_ChatShutdownFilter.php +++ b/application/hub/classes/filter/shutdown/chat/class_ChatShutdownFilter.php @@ -71,7 +71,5 @@ class ChatShutdownFilter extends BaseChatFilter implements Filterable { // Shutdown the chat. This should be the last line $chatInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/crawler/class_CrawlerShutdownFilter.php b/application/hub/classes/filter/shutdown/crawler/class_CrawlerShutdownFilter.php index 93e3e5cf9..fa9587c02 100644 --- a/application/hub/classes/filter/shutdown/crawler/class_CrawlerShutdownFilter.php +++ b/application/hub/classes/filter/shutdown/crawler/class_CrawlerShutdownFilter.php @@ -71,7 +71,5 @@ class CrawlerShutdownFilter extends BaseCrawlerFilter implements Filterable { // Shutdown the crawler. This should be the last line $crawlerInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/cruncher/class_CruncherShutdownFilter.php b/application/hub/classes/filter/shutdown/cruncher/class_CruncherShutdownFilter.php index 4ab6c409d..e694295ad 100644 --- a/application/hub/classes/filter/shutdown/cruncher/class_CruncherShutdownFilter.php +++ b/application/hub/classes/filter/shutdown/cruncher/class_CruncherShutdownFilter.php @@ -71,7 +71,5 @@ class CruncherShutdownFilter extends BaseCruncherFilter implements Filterable { // Shutdown the cruncher. This should be the last line $cruncherInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/miner/class_MinerShutdownFilter.php b/application/hub/classes/filter/shutdown/miner/class_MinerShutdownFilter.php index 7bcbe0361..1b289d901 100644 --- a/application/hub/classes/filter/shutdown/miner/class_MinerShutdownFilter.php +++ b/application/hub/classes/filter/shutdown/miner/class_MinerShutdownFilter.php @@ -71,7 +71,5 @@ class MinerShutdownFilter extends BaseMinerFilter implements Filterable { // Shutdown the miner. This should be the last line $minerInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/node/class_NodeShutdown b/application/hub/classes/filter/shutdown/node/class_NodeShutdown index e42c1c5c7..f2ab02bdd 100644 --- a/application/hub/classes/filter/shutdown/node/class_NodeShutdown +++ b/application/hub/classes/filter/shutdown/node/class_NodeShutdown @@ -73,7 +73,5 @@ class HubShutdown???Filter extends BaseNodeFilter implements Filterable { // Now do something $this->partialStub('Please implement this step.'); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php b/application/hub/classes/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php index 5abd525ff..4edad0cec 100644 --- a/application/hub/classes/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php +++ b/application/hub/classes/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php @@ -73,7 +73,5 @@ class NodeShutdownFlushNodeListFilter extends BaseNodeFilter implements Filterab // Now do something $this->partialStub('Please implement this step.'); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/node/class_NodeShutdownNodeFilter.php b/application/hub/classes/filter/shutdown/node/class_NodeShutdownNodeFilter.php index 5b8d5c924..7cd5ea05e 100644 --- a/application/hub/classes/filter/shutdown/node/class_NodeShutdownNodeFilter.php +++ b/application/hub/classes/filter/shutdown/node/class_NodeShutdownNodeFilter.php @@ -74,7 +74,5 @@ class NodeShutdownNodeFilter extends BaseNodeFilter implements Filterable { // Shutdown the node. This should be the last line $nodeInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php b/application/hub/classes/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php index 087664187..63c3303ff 100644 --- a/application/hub/classes/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php +++ b/application/hub/classes/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php @@ -73,7 +73,5 @@ class NodeShutdownTaskHandlerFilter extends BaseNodeFilter implements Filterable // Shutdown the task manager and all its registered tasks $handlerInstance->doShutdown(); } -} -// [EOF] -?> +} diff --git a/application/hub/classes/handler/message-types/class_BaseMessageHandler.php b/application/hub/classes/handler/message-types/class_BaseMessageHandler.php index e2dee462e..4d5563741 100644 --- a/application/hub/classes/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/classes/handler/message-types/class_BaseMessageHandler.php @@ -57,7 +57,7 @@ abstract class BaseMessageHandler extends BaseDataHandler { // Is the last exception not NULL? if ($this->getLastException() instanceof FrameworkException) { // "Determine" the right status code (may differ from exception to exception) - $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!'); + $this->debugInstance(sprintf('[%s:%d]: lastException=%s,message=%s is unfinished.', __METHOD__, __LINE__, $this->getLastException()->__toString(), $this->getLastException()->getMessage())); } // END - if // Return the status code diff --git a/application/hub/classes/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php b/application/hub/classes/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php index 375e67736..b485f7b19 100644 --- a/application/hub/classes/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php +++ b/application/hub/classes/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php @@ -81,7 +81,7 @@ class NodeMessageSelfConnectHandler extends BaseMessageHandler implements Handle } else { // Something really horrible happened // @TODO Throw an exception here instead of dying - $this->debugInstance(__METHOD__ . ': ids mismatching! messageData=' . print_r($messageData, TRUE)); + $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE))); } } diff --git a/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php b/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php index 3e94c30de..8353fa0c9 100644 --- a/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php +++ b/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php @@ -85,74 +85,6 @@ abstract class BaseProtocolHandler extends BaseHandler implements HandleableProt return $isValid; } - /** - * Parses the given UNL by splitting it up in its components. The UNL ... - * - * protocol://address[:port] - * - * ... becomes: - * - * array( - * 'protocol' => 'value', - * 'address' => 'value', - * 'extra' => 'port' - * ) - * - * 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 $unlInstance An instance of a LocateableNode class - */ - protected function parseUniversalNodeLocator ($unl) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!'); - - // Make sure the UNL is valid - assert($this->isValidUniversalNodeLocator($unl)); - - /* - * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-( - * @TODO If you know why, please fix and explain it to me. - */ - $unlParts = explode('://', $unl); - - // Split again the last part as: address:port - $unlParts[1] = explode(':', $unlParts[1]); - - // Now there is an almost useable array which then can be copied to the "real" array. - $unlData = array( - 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!'); - - // Create instance from it - //$unlInstance = ; - $this->partialStub('Please rewrite this part.'); - - // Return instance - return $unlInstance; - } - - /** - * Gets an element from universalNodeLocatorData array - * - * @param $element Element in universalNodeLocatorData array - * @return $value Found value - */ - protected final function getUniversalNodeLocatorDataElement ($element) { - // Is the element there? - assert(isset($this->universalNodeLocatorData[$element])); - - // Return it - return $this->universalNodeLocatorData[$element]; - } - /** * Getter for protocol name * @@ -189,8 +121,9 @@ abstract class BaseProtocolHandler extends BaseHandler implements HandleableProt * @return $address Address part for the final UNL */ public function getAddressPart () { - // Return it - return $this->getUniversalNodeLocatorDataElement(LocateableNode::UNL_PART_ADDRESS); + // Get UNL instance + $unlInstance = $this->getUniversalNodeLocatorInstance(); + die(__METHOD__.':'.print_r($unlInstance, TRUE)); } /** diff --git a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php index e00ebb10a..2abc2e4a4 100644 --- a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php +++ b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php @@ -3,6 +3,7 @@ namespace Hub\Handler\Protocol\Network\IpV4; // Import application-specific stuff +use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Hub\Handler\Protocol\BaseProtocolHandler; use Hub\Locator\Node\LocateableNode; use Hub\Network\Package\NetworkPackage; diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index ca374da47..f40fb6d06 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -1,6 +1,6 @@ debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.'); + $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); } // END - if // "explode" the ip:port, so index 1 will be the port number @@ -109,7 +110,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection //$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')); + $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s!=%s', __METHOD__, __LINE__, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $helperInstance->getConfigInstance()->getConfigEntry('external_address'))); } } diff --git a/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php index bad59079f..32e286320 100644 --- a/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php @@ -1,10 +1,11 @@ debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); + $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__)); } /** diff --git a/application/hub/classes/lists/recipient/class_RecipientList.php b/application/hub/classes/lists/recipient/class_RecipientList.php index a6de87c58..8f3a2b75f 100644 --- a/application/hub/classes/lists/recipient/class_RecipientList.php +++ b/application/hub/classes/lists/recipient/class_RecipientList.php @@ -66,7 +66,7 @@ class RecipientList extends BaseList implements Listable, Registerable { * @return $iteratorInstance An instance of a Iterator class */ public function getListIterator () { - $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!'); + $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__)); } /** diff --git a/application/hub/classes/locator/class_UniversalNodeLocator.php b/application/hub/classes/locator/class_UniversalNodeLocator.php index 11d47f5d4..1a5ad11aa 100644 --- a/application/hub/classes/locator/class_UniversalNodeLocator.php +++ b/application/hub/classes/locator/class_UniversalNodeLocator.php @@ -6,8 +6,12 @@ namespace Hub\Locator\Node; use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper; use Hub\Generic\BaseHubSystem; +// Import framework stuff +use CoreFramework\Registry\Registerable; + // Import SPL stuff use \BadMethodCallException; +use \InvalidArgumentException; /** * A class for UNLs (Universal Node Locator) @@ -31,7 +35,7 @@ use \BadMethodCallException; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class UniversalNodeLocator extends BaseHubSystem implements LocateableNode { +class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Registerable { /** * UNL data array */ @@ -45,6 +49,9 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode { protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set regex for UNL-validation + $this->setRegularExpression(LocateableNode::UNL_REGEX); } /** @@ -64,45 +71,6 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode { return $unlInstance; } - /** - * Initializes the UNL instance by givena array. If an entry is found, it - * will be copied, otherwise the entry is set empty. - * - * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional. - * @return void - */ - private function initUniversalNodeLocator (array $current = array()) { - // Init UNL array - $this->unlData = array(); - - // Copy all found entries - foreach (array( - NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, - NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, - NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, - NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, - NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, - NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) { - // Init entry - $this->unlData[$key] = NULL; - - // Is the key found? - if (isset($current[$key])) { - // The copy the entry - $this->unlData[$key] = $current[$key]; - } // END - if - } // END - foreach - } - - /** - * Getter for UNL data array - * - * @return $unlData An array with UNL data - */ - private function getUnlData () { - return $this->unlData; - } - /** * Getter for external UNL * @@ -149,4 +117,159 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode { return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL]; } + /** + * Some "getter" for UNL port (if supported). If not supported, NULL is + * being returned. + * + * @return $unlPort Port number of UNL + */ + public function getUnlPort () { + // Get UNL data + $unlData = $this->getUnlData(); + + // Default value is NULL + $unlPort = NULL; + + // Is the element there? + if (isset($unlData[LocateableNode::UNL_PART_EXTRA])) { + // Use it + $unlPort = $unlData[LocateableNode::UNL_PART_EXTRA]; + } // END - if + + // Return it + return $unlPort; + } + + /** + * Parses given UNL string as UNL array + * + * @param $unl UNL string + * @return void + */ + public function parseStringAsUnl ($unl) { + // Is it basically valid? + if (!is_string($unl)) { + // Abort here + throw new InvalidArgumentException(sprintf('unl[]=%s is not string.', gettype($unl))); + } // END - if + + // Parse it + $this->parseUniversalNodeLocator($unl); + } + + /** + * Parses the given UNL by splitting it up in its components. The UNL ... + * + * protocol://address[:port] + * + * ... becomes: + * + * array( + * 'protocol' => 'value', + * 'address' => 'value', + * 'extra' => 'port' + * ) + * + * 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" + * @throws InvalidArgumentException If given UNL is not valid + */ + private function parseUniversalNodeLocator ($unl) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!'); + + // Make sure the UNL is valid + if (!$this->isValidUniversalNodeLocator($unl)) { + // UNL is not valid + throw new InvalidArgumentException(sprintf('unl[%s]=%s is not valid.', gettype($unl), $unl)); + } // END - if + + /* + * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-( + * @TODO If you know why, please fix and explain it to me. + */ + $unlParts = explode('://', $unl); + + // Split again the last part as: address:port + $unlParts[1] = explode(':', $unlParts[1]); + + // Now there is an almost useable array which then can be copied to the "real" array. + $unlData = array( + 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!'); + + // Call init method + $this->initUniversalNodeLocator($unlData); + } + + /** + * Initializes the UNL instance by givena array. If an entry is found, it + * will be copied, otherwise the entry is set empty. + * + * @param $unlData An array with "raw" data from the database layer for the UNL. This parameter is optional. + * @return void + */ + private function initUniversalNodeLocator (array $unlData = array()) { + // Init UNL array + $this->unlData = array(); + + // Copy all found entries + foreach (array( + LocateableNode::UNL_PART_PROTOCOL, + LocateableNode::UNL_PART_ADDRESS, + LocateableNode::UNL_PART_EXTRA, + NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, + NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, + NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, + NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, + NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, + NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) { + // Init entry + $this->unlData[$key] = NULL; + + // Is the key found? + if (isset($unlData[$key])) { + // The copy the entry + $this->unlData[$key] = $unlData[$key]; + } // END - if + } // END - foreach + } + + /** + * Getter for UNL data array + * + * @return $unlData An array with UNL data + */ + private function getUnlData () { + return $this->unlData; + } + + /** + * Validates given UNL very basicly by given regular expression. You + * normally don't need/want to overwrite this method as this is a very basic + * validation only based on a regex. + * + * @param $unl Universal Node Locator to validate + * @return $isValid Whether the UNL is valid + */ + private final function isValidUniversalNodeLocator ($unl) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ',regex=' . $regex . ' - CALLED!'); + + // Very basic regex check + $isValid = (preg_match($this->getRegularExpression(), $unl) === 1); + + // Return result + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': isValid=' . intval($isValid) . ' - EXIT!'); + return $isValid; + } + } diff --git a/application/hub/classes/pools/class_BasePool.php b/application/hub/classes/pools/class_BasePool.php index 837d47f46..39aca2d9e 100644 --- a/application/hub/classes/pools/class_BasePool.php +++ b/application/hub/classes/pools/class_BasePool.php @@ -98,7 +98,7 @@ abstract class BasePool extends BaseHubSystem implements Poolable, Visitable { * @param $list The list identifier we should return * @return $array The requested array */ - protected final function getArrayFromList ($list) { + public final function getArrayFromList ($list) { // Get the array $array = $this->getPoolEntriesInstance()->getArrayFromList($list); diff --git a/application/hub/classes/pools/peer/class_DefaultPeerPool.php b/application/hub/classes/pools/peer/class_DefaultPeerPool.php index 8bcb68880..e646b7138 100644 --- a/application/hub/classes/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/classes/pools/peer/class_DefaultPeerPool.php @@ -16,6 +16,9 @@ use Hub\Pool\Peer\PoolablePeer; // Import framework stuff use CoreFramework\Socket\InvalidSocketException; +// Import SPL stuff +use \LogicException; + /** * A default peer pool class * @@ -218,8 +221,12 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { * @param $connectionType Type of connection, can be 'incoming', 'outgoing', 'server' or default * @return $socketInstance An instance of a StorableSocket class * @throws InvalidConnectionTypeException If the provided connection type is not valid + * @throws LogicException If an expected array element is missing */ public function getSocketFromPackageData (array $packageData, $connectionType = NULL) { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType)); + // Default is no socket $socketInstance = NULL; @@ -227,36 +234,38 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $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[LocateableNode::UNL_PART_PROTOCOL])); - assert(isset($unlData[LocateableNode::UNL_PART_ADDRESS])); - assert(isset($unlData[LocateableNode::UNL_PART_PORT])); + $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance(); // Debug message - //* 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] . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlInstance.unl=' . $unlInstance->generateUnl() . ' ...'); // Default is all sockets $sockets = $this->getAllSockets(); - // Is connection type set? - if ((is_string($connectionType)) && ($this->isValidConnectionType($connectionType))) { - // Then get a list of this type - $sockets = $this->getSocketsByConnectionType($connectionType); - } elseif (is_string($connectionType)) { - // Is not a valid connection type! - throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE); - } - // Get all sockets and check them, skip the server socket foreach ($sockets as $socketArray) { - // Is this a server socket? - if ($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) { - // Skip 'server' sockets (local socket) - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...'); + // Debugging: + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketArray(%d)=%s', count($socketArray), implode(',', $socketArray))); + //* DEBUG-DIE: */ die(__METHOD__.':connectionType='.$connectionType.',socketArray='.print_r($socketArray, TRUE)); + + // Is connection type set? + if (!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) { + // Important array element missing + throw new LogicException(sprintf('socketArray[%s] is not set.', Poolable::SOCKET_ARRAY_INSTANCE)); + } elseif (!isset($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE])) { + // Important array element missing + throw new LogicException(sprintf('socketArray[%s] is not set.', Poolable::SOCKET_ARRAY_CONN_TYPE)); + } elseif ((!empty($connectionType)) && (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->isValidConnectionType($connectionType))) { + // Is not a valid connection type! + throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE); + } elseif ((!empty($connectionType)) && ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] !== $connectionType)) { + // Skip unwanted sockets + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType)); continue; - } // END - if + } + + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketInstance.socketResource=%s,socketInstance.socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE])); // Init peer address/port $peerAddress = '0.0.0.0'; @@ -268,14 +277,16 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); } // END - if - // Get + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s,peerPort=%d,unlInstance.addressPart=%s', $peerAddress, $peerPort, $unlInstance->getAddressPart())); + // If the "peer" IP and recipient is same, use it - if ($peerAddress == $unlData[LocateableNode::UNL_PART_ADDRESS]) { + if ($peerAddress == $unlInstance->getAddressPart()) { // IPs match, so take the socket and quit this loop $socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]; // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE])); break; } // END - if } // END - foreach diff --git a/application/hub/classes/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/classes/producer/cruncher/work_units/class_CruncherTestUnitProducer.php index e34d5b8ba..2c8d8bb74 100644 --- a/application/hub/classes/producer/cruncher/work_units/class_CruncherTestUnitProducer.php +++ b/application/hub/classes/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -96,7 +96,7 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, if ($wrapperInstance->isTestUnitProduced()) { // Entries found // @TODO Unfinished work here - $this->debugInstance(); + $this->debugInstance(sprintf('[%s:%d]: stateInstance=%s - Unfinished!', __METHOD__, __LINE__, $stateInstance->__toString())); // The state must be changed because ... $stateInstance->someFooStateChange(); diff --git a/application/hub/classes/registry/socket/class_SocketRegistry.php b/application/hub/classes/registry/socket/class_SocketRegistry.php index d3de513d7..d191433c7 100644 --- a/application/hub/classes/registry/socket/class_SocketRegistry.php +++ b/application/hub/classes/registry/socket/class_SocketRegistry.php @@ -328,7 +328,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke $infoInstance->fillWithConnectionHelperInformation($helperInstance); } else { // Not supported state! - $this->debugInstance(': Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL); + $this->debugInstance(sprintf('[%s:%d]: Invalid state found, please report this to the developers with full debug infos.', __METHOD__, __LINE__)); } // Debug message diff --git a/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php index 9b6842d46..1e8afedcf 100644 --- a/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php +++ b/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php @@ -4,6 +4,7 @@ namespace Hub\Resolver\Protocol\Tcp; // Import application-specific stuff use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper; +use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Hub\Helper\Node\NodeHelper; use Hub\Resolver\Protocol\BaseProtocolResolver; use Hub\Resolver\Protocol\ProtocolResolver; @@ -93,7 +94,7 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]); // Get UNL instance and handle over all data - $unlInstance = ObjectFactory::createObjectByConfiguredName('universal_node_locator_class', array($current)); + $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromArray($current); // Return resolved instance return $unlInstance; diff --git a/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php b/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php index 252b7c0ee..36b772a7c 100644 --- a/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php +++ b/application/hub/classes/source/urls/class_CrawlerUploadedListUrlSource.php @@ -4,6 +4,7 @@ namespace Hub\Crawler\Source\Url\UploadList; // Import framework stuff use CoreFramework\Factory\ObjectFactory; +use CoreFramework\Generic\NullPointerException; use CoreFramework\Registry\Registerable; /** diff --git a/application/hub/classes/template/class_BaseXmlTemplateEngine.php b/application/hub/classes/template/class_BaseXmlTemplateEngine.php index 22e3c5282..43ee5efbd 100644 --- a/application/hub/classes/template/class_BaseXmlTemplateEngine.php +++ b/application/hub/classes/template/class_BaseXmlTemplateEngine.php @@ -237,7 +237,7 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { // Is this null? if (is_null($value)) { // Bah, needs fixing. - $this->debugInstance('key=' . $key . ' returns NULL'); + $this->debugInstance(sprintf('[%s:%d]: key=%s returns NULL', __METHOD__, __LINE__, $key)); } // END - if // Return value diff --git a/application/hub/config.php b/application/hub/config.php index 1d015adc9..16cfc7cff 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -745,10 +745,10 @@ $cfg->setConfigEntry('recipient_list_class', 'Hub\Lists\Recipient\RecipientList' $cfg->setConfigEntry('package_tags_class', 'Hub\Tag\Package\PackageTags'); // CFG: TCP-CONNECTION-HELPER-CLASS -$cfg->setConfigEntry('tcp_connection_helper_class', 'TcpConnectionHelper'); +$cfg->setConfigEntry('tcp_connection_helper_class', 'Hub\Helper\Connection\Network\IpV4\Tcp\TcpConnectionHelper'); // CFG: UDP-CONNECTION-HELPER-CLASS -$cfg->setConfigEntry('udp_connection_helper_class', 'UdpConnectionHelper'); +$cfg->setConfigEntry('udp_connection_helper_class', 'Hub\Helper\Connection\Network\IpV4\Udp\UdpConnectionHelper'); // CFG: HUB-COMMUNICATION-PROTOCOL-TYPE $cfg->setConfigEntry('hub_communication_protocol_type', 'tcp'); diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index 67797780d..bc02cb2b4 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -129,21 +129,21 @@ interface StorableSocket extends FrameworkInterface { * * @return $result Whether the peer has been identified */ - function identifySocketPeer(); + function identifySocketPeer (); /** * Tries to set socket timeout option * * @return $result Whether the option has been set */ - function setSocketTimeoutOptions(); + function setSocketTimeoutOptions (); /** * Tries to enable out-of-band (OOB) data * * @return $result Whether OOB has been enabled */ - function enableSocketOutOfBandData(); + function enableSocketOutOfBandData (); /** * Getter for socket procotol field diff --git a/application/hub/interfaces/locator/class_LocateableNode.php b/application/hub/interfaces/locator/class_LocateableNode.php index 6ae4a6ad5..39a89bd7a 100644 --- a/application/hub/interfaces/locator/class_LocateableNode.php +++ b/application/hub/interfaces/locator/class_LocateableNode.php @@ -59,4 +59,20 @@ interface LocateableNode extends HubInterface { */ function getInternalUnl (); + /** + * Some "getter" for UNL port (if supported). If not supported, NULL is + * being returned. + * + * @return $unlPort Port number of UNL + */ + function getUnlPort (); + + /** + * Parses given UNL string as UNL array + * + * @param $unl UNL string + * @return void + */ + function parseStringAsUnl ($unl); + } diff --git a/application/hub/interfaces/pool/class_Poolable.php b/application/hub/interfaces/pool/class_Poolable.php index 5f764a0cf..3277f278d 100644 --- a/application/hub/interfaces/pool/class_Poolable.php +++ b/application/hub/interfaces/pool/class_Poolable.php @@ -32,6 +32,14 @@ interface Poolable extends HubInterface { const SOCKET_ARRAY_INSTANCE = 'instance'; const SOCKET_ARRAY_CONN_TYPE = 'connection_type'; + /** + * Gets the array from specified list + * + * @param $list The list identifier we should return + * @return $array The requested array + */ + function getArrayFromList ($list); + /** * Getter for pool entries instance * diff --git a/application/hub/interfaces/pool/peer/class_PoolablePeer.php b/application/hub/interfaces/pool/peer/class_PoolablePeer.php index 6414010a4..02f73672c 100644 --- a/application/hub/interfaces/pool/peer/class_PoolablePeer.php +++ b/application/hub/interfaces/pool/peer/class_PoolablePeer.php @@ -36,22 +36,21 @@ interface PoolablePeer extends Poolable, SocketTag { * @param $socketInstance An instance of a StorableSocket class * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server' * @return void - * @throws InvalidSocketException If the given resource is invalid or errorous * @throws InvalidConnectionTypeException If the provided connection type is not valid */ function addPeer (StorableSocket $socketInstance, $connectionType); /** - * Getter for array of all socket resource arrays + * Getter for array of all socket resources * - * @return $sockets An array with all socket arrays + * @return $sockets An array with all sockets */ function getAllSockets (); /** - * Getter for array of all socket resources + * Getter for array of all socket arrays * - * @return $sockets An array with all sockets + * @return $sockets An array with all socket arrays */ function getAllSingleSockets (); @@ -60,7 +59,7 @@ interface PoolablePeer extends Poolable, SocketTag { * * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server' * @return $sockets An array with sockets of given type - * @throws InvalidConnectionTypeException If the provided connection type is not valid + * @throws InvalidConnectionTypeException If the found connection type is not valid */ function getSocketsByConnectionType ($connectionType); diff --git a/core b/core index ba6776b5d..fd5598626 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit ba6776b5d9b04fd6916224c088cabf255643c6d7 +Subproject commit fd5598626e163040b19bf8e153d4898a49038b23 diff --git a/index.php b/index.php index 61d534732..753e54afe 100644 --- a/index.php +++ b/index.php @@ -91,7 +91,7 @@ final class ApplicationEntryPoint { $templateInstance = NULL; // Get response instance - $responseInstance = ApplicationHelper::getSelfInstance()->getResponseInstance(); + $responseInstance = FrameworkBootstrap::getResponseInstance(); // Is the template engine loaded? if ((class_exists($tpl)) && (is_object($languageInstance))) { -- 2.39.5