From: Roland Häder Date: Wed, 19 May 2010 10:44:58 +0000 (+0000) Subject: A lot 'FooClientBar' classes renamed to 'FooPeerBar' for naming convention, added... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3cdf3e24c3e85f8f98c5e0522d65d9a29ace1e0e;p=hub.git A lot 'FooClientBar' classes renamed to 'FooPeerBar' for naming convention, added more missing methods for socket discovery (still incomplete/dying code) --- diff --git a/.gitattributes b/.gitattributes index 07b514819..3bd89630d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -40,10 +40,10 @@ application/hub/interfaces/package/.htaccess -text application/hub/interfaces/package/class_Deliverable.php -text application/hub/interfaces/pool/.htaccess -text application/hub/interfaces/pool/class_Poolable.php -text -application/hub/interfaces/pool/client/.htaccess -text -application/hub/interfaces/pool/client/class_PoolableClient.php -text application/hub/interfaces/pool/listener/.htaccess -text application/hub/interfaces/pool/listener/class_PoolableListener.php -text +application/hub/interfaces/pool/peer/.htaccess -text +application/hub/interfaces/pool/peer/class_PoolablePeer.php -text application/hub/interfaces/protocol/.htaccess -text application/hub/interfaces/query/.htaccess -text application/hub/interfaces/query/class_Queryable.php -text @@ -196,14 +196,14 @@ application/hub/main/listener/tcp/.htaccess -text application/hub/main/listener/tcp/class_ -text application/hub/main/listener/tcp/class_TcpListener.php -text application/hub/main/listener/tcp/decorators/.htaccess -text -application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php -text application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php -text +application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php -text application/hub/main/listener/udp/.htaccess -text application/hub/main/listener/udp/class_ -text application/hub/main/listener/udp/class_UdpListener.php -text application/hub/main/listener/udp/decorators/.htaccess -text -application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php -text application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php -text +application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php -text application/hub/main/lists/.htaccess -text application/hub/main/lists/class_ -text application/hub/main/lists/class_BaseList.php -text @@ -234,10 +234,10 @@ application/hub/main/package/class_NetworkPackage.php -text application/hub/main/pools/.htaccess -text application/hub/main/pools/class_ -text application/hub/main/pools/class_BasePool.php -text -application/hub/main/pools/client/.htaccess -text -application/hub/main/pools/client/class_DefaultClientPool.php -text application/hub/main/pools/listener/.htaccess -text application/hub/main/pools/listener/class_DefaultListenerPool.php -text +application/hub/main/pools/peer/.htaccess -text +application/hub/main/pools/peer/class_DefaultPeerPool.php -text application/hub/main/queries/.htaccess -text application/hub/main/queries/class_ -text application/hub/main/queries/class_BaseQuery.php -text @@ -246,8 +246,8 @@ application/hub/main/queries/local/class_LocalQuery.php -text application/hub/main/queues/.htaccess -text application/hub/main/queues/class_ -text application/hub/main/queues/class_BaseQueue.php -text -application/hub/main/queues/client/.htaccess -text -application/hub/main/queues/client/class_LocalClientQueue.php -text +application/hub/main/queues/peer/.htaccess -text +application/hub/main/queues/peer/class_LocalPeerQueue.php -text application/hub/main/registry/.htaccess -text application/hub/main/registry/objects/.htaccess -text application/hub/main/resolver/.htaccess -text @@ -264,8 +264,6 @@ application/hub/main/resolver/state/network/class_NetworkStateResolver.php -text application/hub/main/states/.htaccess -text application/hub/main/states/class_ -text application/hub/main/states/class_BaseState.php -text -application/hub/main/states/client/.htaccess -text -application/hub/main/states/client/class_BaseClientState.php -text application/hub/main/states/generic/.htaccess -text application/hub/main/states/hub/.htaccess -text application/hub/main/states/hub/class_BaseHubState.php -text @@ -279,6 +277,8 @@ application/hub/main/states/node/init/.htaccess -text application/hub/main/states/node/init/class_NodeInitState.php -text application/hub/main/states/node/virgin/.htaccess -text application/hub/main/states/node/virgin/class_NodeVirginState.php -text +application/hub/main/states/peer/.htaccess -text +application/hub/main/states/peer/class_BasePeerState.php -text application/hub/main/tags/.htaccess -text application/hub/main/tags/class_ -text application/hub/main/tags/package/.htaccess -text diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 46343ff37..523c39cfd 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -202,7 +202,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); // -------------------------- Shutdown phase -------------------------- - // Shutting down the hub by saying "good bye" to all connected clients + // Shutting down the hub by saying "good bye" to all connected peers // and other hubs, flushing all queues and caches. $this->debugOutput('MAIN: Shutdown in progress, main loop exited.'); $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); diff --git a/application/hub/config.php b/application/hub/config.php index 45a0dd544..1f4741eea 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -76,13 +76,13 @@ $cfg->setConfigEntry('hub_tcp_listener_class', 'HubTcpListenerDecorator'); $cfg->setConfigEntry('hub_udp_listener_class', 'HubUdpListenerDecorator'); // CFG: CLIENT-TCP-LISTENER-CLASS -$cfg->setConfigEntry('client_tcp_listener_class', 'ClientTcpListenerDecorator'); +$cfg->setConfigEntry('peer_tcp_listener_class', 'PeerTcpListenerDecorator'); // CFG: CLIENT-UDP-LISTENER-CLASS -$cfg->setConfigEntry('client_udp_listener_class', 'ClientUdpListenerDecorator'); +$cfg->setConfigEntry('peer_udp_listener_class', 'PeerUdpListenerDecorator'); // CFG: CLIENT-POOL-CLASS -$cfg->setConfigEntry('client_pool_class', 'DefaultClientPool'); +$cfg->setConfigEntry('peer_pool_class', 'DefaultPeerPool'); // CFG: POOL-ENTRIES-LIST-CLASS $cfg->setConfigEntry('pool_entries_list_class', 'PoolEntriesList'); @@ -366,9 +366,6 @@ $cfg->setConfigEntry('deco_package_compressor_class', 'NetworkPackageCompressorD // CFG: RAW-PACKAGE-COMPRESSOR-CLASS $cfg->setConfigEntry('raw_package_compressor_class', 'GzipCompressor'); -// CFG: HUB-LIST-CLASS -$cfg->setConfigEntry('hub_list_class', 'HubList'); - // CFG: SOCKET-REGISTRY-CLASS $cfg->setConfigEntry('socket_registry_class', 'SocketRegistry'); diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index ae2aca028..f299712d1 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -35,6 +35,14 @@ interface Listenable extends ProtocolHandler { * @return void */ function doListen(); + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + function ifListenerAcceptsPackageData (array $packageData); } // [EOF] diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index d85aa626d..5ca4ba82b 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -69,7 +69,7 @@ interface NodeHelper extends FrameworkInterface { function activateHub (Requestable $requestInstance, Responseable $responseInstance); /** - * Generates a session id which will be sent to the other hubs and clients + * Generates a session id which will be sent to the other hubs and peers * * @return void */ diff --git a/application/hub/interfaces/pool/client/.htaccess b/application/hub/interfaces/pool/client/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/application/hub/interfaces/pool/client/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/hub/interfaces/pool/client/class_PoolableClient.php b/application/hub/interfaces/pool/client/class_PoolableClient.php deleted file mode 100644 index 607c5af52..000000000 --- a/application/hub/interfaces/pool/client/class_PoolableClient.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 . - */ -interface PoolableClient extends Poolable { - /** - * Adds a socket resource to the client pool - * - * @param $socketResource A valid (must be!) socket resource - * @return void - */ - function addClient ($socketResource); -} - -// [EOF] -?> diff --git a/application/hub/interfaces/pool/peer/.htaccess b/application/hub/interfaces/pool/peer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/pool/peer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/pool/peer/class_PoolablePeer.php b/application/hub/interfaces/pool/peer/class_PoolablePeer.php new file mode 100644 index 000000000..6d91da516 --- /dev/null +++ b/application/hub/interfaces/pool/peer/class_PoolablePeer.php @@ -0,0 +1,35 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 . + */ +interface PoolablePeer extends Poolable { + /** + * Adds a socket resource to the peer pool + * + * @param $socketResource A valid (must be!) socket resource + * @return void + */ + function addPeer ($socketResource); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/tags/class_Tagable.php b/application/hub/interfaces/tags/class_Tagable.php index c00b71010..c87c42967 100644 --- a/application/hub/interfaces/tags/class_Tagable.php +++ b/application/hub/interfaces/tags/class_Tagable.php @@ -22,6 +22,22 @@ * along with this program. If not, see . */ interface Tagable extends FrameworkInterface { + /** + * Chooses the right protocol from given package data + * + * @param $packageData Raw package data + * @return $protocolName Name of the choosen procotol + */ + function chooseProtocolFromPackageData (array $packageData); + + /** + * Checks wether the given package data is accepted by the listener + * + * @param $packageData Raw package data + * @param $listenerInstance A Listenable instance + * @return $accepts Wether it is accepted + */ + function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance); } // [EOF] diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index 8903a43e2..2435a4d67 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -54,6 +54,7 @@ class PackageSocketDiscovery extends BaseDiscovery implements DiscoverableSocket * * @param $packageData Raw package data array * @return $socketResource A valid socket resource + * @throws NoListGroupException If the procol group is not found in peer list */ public function discoverSocket (array $packageData) { // First we need a tags instance @@ -68,8 +69,32 @@ class PackageSocketDiscovery extends BaseDiscovery implements DiscoverableSocket */ $protocolName = $tagsInstance->chooseProtocolFromPackageData($packageData); - // Abort here - die(__METHOD__ . ':' . $protocolName . "\n"); + /* + * Get the listener pool instance, we need to lookup the matching + * listener->poolInstance chain there. + */ + $poolInstance = Registry::getRegistry()->getInstance('node')->getListenerPoolInstance(); + + // So get the pool entries list first + $poolEntriesInstance = $poolInstance->getPoolEntriesInstance(); + + /* + * Now we need to choose again. It is wether we are speaking with a hub + * or with a client. So just handle it over to all listeners in that + * pool. + */ + foreach ($poolEntriesInstance->getArrayFromGroup($protocolName) as $listenerInstance) { + // Does the listener want that package? + if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) { + // This listener likes our package data! + die(print_r($listenerInstance, true)); + break; + } // END - if + } // END - foreach + die(); + + // And return it + return $socketResource; } } diff --git a/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php b/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php index 76832a6e1..0d91d1024 100644 --- a/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php +++ b/application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php @@ -71,7 +71,7 @@ class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED); // Debug message - $this->debugOutput('HANDLER: Handling TCP package from client ' . $resource); + $this->debugOutput('HANDLER: Handling TCP package from peer ' . $resource); // Read the raw data from socket $rawData = socket_read($resource, 1500, PHP_NORMAL_READ); @@ -93,6 +93,7 @@ class TcpNetworkPackageHandler extends BaseNetworkPackageHandler implements Netw // Get a state from the resolver for this package $stateInstance = $this->getResolverInstance()->resolveStateByPackage($this, $rawData); + die('UNFINISHED:'.$stateInstance->__toString()); } } diff --git a/application/hub/main/iterator/network/class_NetworkListenIterator.php b/application/hub/main/iterator/network/class_NetworkListenIterator.php index 82aae6723..11c48f5a4 100644 --- a/application/hub/main/iterator/network/class_NetworkListenIterator.php +++ b/application/hub/main/iterator/network/class_NetworkListenIterator.php @@ -112,7 +112,7 @@ class NetworkListenIterator extends BaseIterator implements Iterator { * @return $isValid Wether the current entry is there */ public function valid () { - // Check for total active clients and if we are not at the end + // Check for total active peers and if we are not at the end $isValid = ($this->key() < $this->getListInstance()->count()); // Return result diff --git a/application/hub/main/iterator/pool/class_DefaultIterator.php b/application/hub/main/iterator/pool/class_DefaultIterator.php index 949c6c188..c40dbd9d6 100644 --- a/application/hub/main/iterator/pool/class_DefaultIterator.php +++ b/application/hub/main/iterator/pool/class_DefaultIterator.php @@ -110,7 +110,7 @@ class DefaultIterator extends BaseIterator implements Iterator { * @return $isValid Wether the current entry is there */ public function valid () { - // Check for total active clients and if we are not at the end + // Check for total active peers and if we are not at the end $isValid = ($this->key() < $this->getListInstance()->count()); // Return result diff --git a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php index 2a7b124b5..50f12c991 100644 --- a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php +++ b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php @@ -112,7 +112,7 @@ class HandlerPoolIterator extends BaseIterator implements Iterator { * @return $isValid Wether the current entry is there */ public function valid () { - // Check for total active clients and if we are not at the end + // Check for total active peers and if we are not at the end $isValid = ($this->key() < $this->getListInstance()->count()); // Return result diff --git a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php index 39d4041ea..d3e269183 100644 --- a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php +++ b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php @@ -110,7 +110,7 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator { * @return $isValid Wether the current entry is there */ public function valid () { - // Check for total active clients and if we are not at the end + // Check for total active peers and if we are not at the end $isValid = ($this->key() < $this->getListInstance()->count()); // Return result diff --git a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php index f037f26ea..205738b0a 100644 --- a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php +++ b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php @@ -112,7 +112,7 @@ class TaskPoolIterator extends BaseIterator implements Iterator { * @return $isValid Wether the current entry is there */ public function valid () { - // Check for total active clients and if we are not at the end + // Check for total active peers and if we are not at the end $isValid = ($this->key() < $this->getListInstance()->count()); // Return result diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 284bb9987..1a767f9cb 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -47,7 +47,7 @@ class BaseListener extends BaseHubSystem implements Visitable { private $blockingMode = false; /** - * A client pool instance + * A peer pool instance */ private $poolInstance = null; @@ -197,21 +197,21 @@ class BaseListener extends BaseHubSystem implements Visitable { } /** - * Setter for client pool instance + * Setter for peer pool instance * - * @param $poolInstance The client pool instance we shall set + * @param $poolInstance The peer pool instance we shall set * @return void */ - protected final function setPoolInstance (PoolableClient $poolInstance) { + protected final function setPoolInstance (Poolablepeer $poolInstance) { $this->poolInstance = $poolInstance; } /** - * Getter for client pool instance + * Getter for peer pool instance * - * @return $poolInstance The client pool instance we shall set + * @return $poolInstance The peer pool instance we shall set */ - protected final function getPoolInstance () { + public final function getPoolInstance () { return $this->poolInstance; } diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index 953c131cd..5b4d71845 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class BaseListenerDecorator extends BaseDecorator implements Visitable { + /** + * Listener type + */ + private $listenerType = 'invalid'; + /** * Protected constructor * @@ -82,6 +87,25 @@ class BaseListenerDecorator extends BaseDecorator implements Visitable { // Visit the covered class $visitorInstance->visitListener($this->getListenerInstance()); } + + /** + * Getter for listener type. + * + * @return $listenerType The listener's type (hub/peer) + */ + public final function getListenerType () { + return $this->listenerType; + } + + /** + * Setter for listener type. + * + * @param $listenerType The listener's type (hub/peer) + * @return void + */ + protected final function setListenerType ($listenerType) { + $this->listenerType = $listenerType; + } } // [EOF] diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php index 1149a734b..6cbe71b3b 100644 --- a/application/hub/main/listener/tcp/class_TcpListener.php +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -145,11 +145,11 @@ class TcpListener extends BaseListener implements Listenable { // Set the main socket $this->registerServerSocketResource($mainSocket); - // Initialize the client pool instance - $poolInstance = ObjectFactory::createObjectByConfiguredName('client_pool_class', array($this)); + // Initialize the peer pool instance + $poolInstance = ObjectFactory::createObjectByConfiguredName('peer_pool_class', array($this)); // Add main socket - $poolInstance->addClient($mainSocket); + $poolInstance->addPeer($mainSocket); // And add it to this listener $this->setPoolInstance($poolInstance); @@ -182,7 +182,7 @@ class TcpListener extends BaseListener implements Listenable { $writers = array(); $excepts = array(); - // Check if we have some clients left + // Check if we have some peers left $left = socket_select( $readers, $writers, @@ -191,13 +191,13 @@ class TcpListener extends BaseListener implements Listenable { 150 ); - // Some new clients found? + // Some new peers found? if ($left < 1) { // Nothing new found return; } // END - if - // Do we have changed clients? + // Do we have changed peers? if (in_array($this->getSocketResource(), $readers)) { // Then accept it $newSocket = socket_accept($this->getSocketResource()); @@ -217,8 +217,8 @@ class TcpListener extends BaseListener implements Listenable { throw new InvalidSocketException(array($this, gettype($newSocket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); } // END - if - // Add it to the clients - $this->getPoolInstance()->addClient($newSocket); + // Add it to the peers + $this->getPoolInstance()->addPeer($newSocket); } // END - if // Do we have to rewind? @@ -239,6 +239,16 @@ class TcpListener extends BaseListener implements Listenable { // Advance to next entry. This should be the last line $this->getIteratorInstance()->next(); } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + function ifListenerAcceptsPackageData (array $packageData) { + $this->partialStub('This call should not happen. Please report.'); + } } // [EOF] diff --git a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php deleted file mode 100644 index a55e2d413..000000000 --- a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 ClientTcpListenerDecorator extends BaseListenerDecorator implements Listenable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $listenerInstance A Listener instance - * @return $decoratorInstance An instance a prepared listener decorator class - */ - public final static function createClientTcpListenerDecorator (Listenable $listenerInstance) { - // Get new instance - $decoratorInstance = new ClientTcpListenerDecorator(); - - // Set the application instance - $decoratorInstance->setListenerInstance($listenerInstance); - - // Return the prepared instance - return $decoratorInstance; - } - - /** - * Initializes the listener by setting up the required socket server - * - * @return void - */ - public function initListener() { - $this->partialStub('WARNING: This method should not be called.'); - } - - /** - * "Listens" for incoming network packages - * - * @return void - */ - public function doListen() { - // Handle generic TCP package - $this->getListenerInstance()->doListen(); - - // Handle client TCP package - $this->partialStub('Need to handle client TCP package.'); - } -} - -// [EOF] -?> diff --git a/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php index b3a6013c7..d6e65827b 100644 --- a/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php +++ b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php @@ -30,6 +30,9 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('hub'); } /** @@ -54,7 +57,7 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function initListener() { + public function initListener () { $this->partialStub('WARNING: This method should not be called.'); } @@ -63,13 +66,30 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function doListen() { + public function doListen () { // Handle generic TCP package $this->getListenerInstance()->doListen(); // Handle hub TCP package $this->partialStub('Need to handle hub TCP package.'); } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + public function ifListenerAcceptsPackageData (array $packageData) { + // Get a tags instance + $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); + + // So is the package accepted with this listener? + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + + // Return the result + return $accepts; + } } // [EOF] diff --git a/application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php new file mode 100644 index 000000000..cdabf6e6d --- /dev/null +++ b/application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php @@ -0,0 +1,96 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PeerTcpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('peer'); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createPeerTcpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new PeerTcpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + */ + public function initListener() { + $this->partialStub('WARNING: This method should not be called.'); + } + + /** + * "Listens" for incoming network packages + * + * @return void + */ + public function doListen() { + // Handle generic TCP package + $this->getListenerInstance()->doListen(); + + // Handle peer TCP package + $this->partialStub('Need to handle peer TCP package.'); + } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + public function ifListenerAcceptsPackageData (array $packageData) { + // Get a tags instance + $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); + + // So is the package accepted with this listener? + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + + // Return the result + return $accepts; + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/udp/class_UdpListener.php b/application/hub/main/listener/udp/class_UdpListener.php index 1f34a8b1a..c17064c50 100644 --- a/application/hub/main/listener/udp/class_UdpListener.php +++ b/application/hub/main/listener/udp/class_UdpListener.php @@ -133,7 +133,7 @@ class UdpListener extends BaseListener implements Listenable { * @todo ~50% done */ public function doListen() { - // Read a package and determine the client + // Read a package and determine the peer $amount = @socket_recvfrom($this->getSocketResource(), $pkt, 1500, 0, $peer, $port); // Get last error @@ -165,6 +165,16 @@ class UdpListener extends BaseListener implements Listenable { // Debug only $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer . ':' . $port); } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + function ifListenerAcceptsPackageData (array $packageData) { + $this->partialStub('This call should not happen. Please report it.'); + } } // [EOF] diff --git a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php deleted file mode 100644 index b6d2fdaf1..000000000 --- a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 ClientUdpListenerDecorator extends BaseListenerDecorator implements Listenable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $listenerInstance A Listener instance - * @return $decoratorInstance An instance a prepared listener decorator class - */ - public final static function createClientUdpListenerDecorator (Listenable $listenerInstance) { - // Get new instance - $decoratorInstance = new ClientUdpListenerDecorator(); - - // Set the application instance - $decoratorInstance->setListenerInstance($listenerInstance); - - // Return the prepared instance - return $decoratorInstance; - } - - /** - * Initializes the listener by setting up the required socket server - * - * @return void - */ - public function initListener() { - $this->partialStub('WARNING: This method should not be called.'); - } - - /** - * "Listens" for incoming network packages - * - * @return void - */ - public function doListen() { - // Handle generic UDP packages first - $this->getListenerInstance()->doListen(); - - // Handle this client UDP package - $this->partialStub('Need to handle client UDP package.'); - } -} - -// [EOF] -?> diff --git a/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php index 4595ab6b3..2f30e00d6 100644 --- a/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php +++ b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php @@ -30,6 +30,9 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('hub'); } /** @@ -70,6 +73,23 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl // Handle hub UDP package $this->partialStub('Need to handle hub UDP package.'); } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + public function ifListenerAcceptsPackageData (array $packageData) { + // Get a tags instance + $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); + + // So is the package accepted with this listener? + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + + // Return the result + return $accepts; + } } // [EOF] diff --git a/application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php new file mode 100644 index 000000000..6bf5f9c69 --- /dev/null +++ b/application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php @@ -0,0 +1,96 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PeerUdpListenerDecorator extends BaseListenerDecorator implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('peer'); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listener instance + * @return $decoratorInstance An instance a prepared listener decorator class + */ + public final static function createPeerUdpListenerDecorator (Listenable $listenerInstance) { + // Get new instance + $decoratorInstance = new PeerUdpListenerDecorator(); + + // Set the application instance + $decoratorInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $decoratorInstance; + } + + /** + * Initializes the listener by setting up the required socket server + * + * @return void + */ + public function initListener() { + $this->partialStub('WARNING: This method should not be called.'); + } + + /** + * "Listens" for incoming network packages + * + * @return void + */ + public function doListen() { + // Handle generic UDP packages first + $this->getListenerInstance()->doListen(); + + // Handle this peer UDP package + $this->partialStub('Need to handle peer UDP package.'); + } + + /** + * Checks wether the listener would accept the given package data array + * + * @param $packageData Raw package data + * @return $accepts Wether this listener does accept + */ + function ifListenerAcceptsPackageData (array $packageData) { + // Get a tags instance + $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); + + // So is the package accepted with this listener? + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + + // Return the result + return $accepts; + } +} + +// [EOF] +?> diff --git a/application/hub/main/lists/class_BaseList.php b/application/hub/main/lists/class_BaseList.php index 3755b2605..da036a52d 100644 --- a/application/hub/main/lists/class_BaseList.php +++ b/application/hub/main/lists/class_BaseList.php @@ -131,7 +131,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { // Add the instance itself to the list $this->listEntries[$hash] = $instance; - //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START'); + //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED'); } /** @@ -336,6 +336,45 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { return $entry; } + /** + * Gets a full array from given group name + * + * @param $groupName The group name to get a list for + * @return $entries The array with all entries + * @throws NoListGroupException If the specified group is invalid + */ + public function getArrayFromGroup ($groupName) { + // Is the group valid? + if (!$this->isGroupSet($groupName)) { + // Throw the exception here + throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND); + } // END - if + + // Init the entries' array + $entries = array(); + + // Get an iterator + $iteratorInstance = $this->listGroups[$groupName]->getIterator(); + + // Go through all entries + while ($iteratorInstance->valid()) { + // Get key + $entryIndex = $iteratorInstance->key(); + + // ... and the final entry which is the stored instance + $entry = $this->getEntry($entryIndex); + + // Add it to the list + $entries[$iteratorInstance->current()] = $entry; + + // Skip to next one + $iteratorInstance->next(); + } // END - while + + // Return the list + return $entries; + } + /** * Updates the given entry by hash with given array * @@ -349,7 +388,7 @@ class BaseList extends BaseHubSystem implements IteratorAggregate, Countable { if (!$this->isHashValid($hash)) { // Throw an exception here, hashIndex is unknown at this point throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH); - } + } // END - if // Set the entry $this->listEntries[$hash] = $entryArray; diff --git a/application/hub/main/lists/groups/class_ListGroupList.php b/application/hub/main/lists/groups/class_ListGroupList.php index 8fabaf62e..d79376580 100644 --- a/application/hub/main/lists/groups/class_ListGroupList.php +++ b/application/hub/main/lists/groups/class_ListGroupList.php @@ -44,15 +44,6 @@ class ListGroupList extends BaseList implements Listable { // Return the prepared instance return $listInstance; } - - /** - * Gets an array from this group - * - * @return $array The array from this group - */ - public final function getArrayFromGroup () { - $this->debugInstance(); - } } // [EOF] diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 0fb71fcda..243cb14f5 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -56,11 +56,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { */ private $isActive = false; - /** - * List instance of all hubs - */ - private $hubsInstance = false; - /** * Protected constructor * @@ -71,9 +66,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { // Call parent constructor parent::__construct($className); - // Init list for connected hubs - $this->hubsInstance = ObjectFactory::createObjectByConfiguredName('hub_list_class'); - // Init state which sets the state to 'init' $this->initState(); } @@ -340,7 +332,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { } /** - * Generates a session id which will be sent to the other hubs and clients + * Generates a session id which will be sent to the other hubs and peers * * @return void */ @@ -545,7 +537,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get a decorator class - $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance)); + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_tcp_listener_class', array($listenerInstance)); // Add this listener to the pool $this->getListenerPoolInstance()->addListener($decoratorInstance); @@ -567,7 +559,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { $this->getListenerPoolInstance()->addListener($decoratorInstance); // Get a decorator class - $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance)); + $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_udp_listener_class', array($listenerInstance)); // Add this listener to the pool $this->getListenerPoolInstance()->addListener($decoratorInstance); diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 7806d07ed..f3e9d9c63 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -121,7 +121,7 @@ class BasePool extends BaseHubSystem implements Visitable { } /** - * Gets the arra from specified list + * Gets the array from specified list * * @param $list The list identifier we should return * @return $array The requested array diff --git a/application/hub/main/pools/client/.htaccess b/application/hub/main/pools/client/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/application/hub/main/pools/client/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/hub/main/pools/client/class_DefaultClientPool.php b/application/hub/main/pools/client/class_DefaultClientPool.php deleted file mode 100644 index f8a2338cb..000000000 --- a/application/hub/main/pools/client/class_DefaultClientPool.php +++ /dev/null @@ -1,132 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 DefaultClientPool extends BasePool implements PoolableClient { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $listenerInstance A Listenable instance - * @return $poolInstance An instance a Poolable class - */ - public final static function createDefaultClientPool (Listenable $listenerInstance) { - // Get new instance - $poolInstance = new DefaultClientPool(); - - // Set the application instance - $poolInstance->setListenerInstance($listenerInstance); - - // Return the prepared instance - return $poolInstance; - } - - /** - * Validates given socket - * - * @param $socketResource A valid socket resource - * @return void - */ - private function validateSocket ($socketResource) { - // Is it a valid resource? - if (!is_resource($socketResource)) { - // Throw an exception - throw new InvalidSocketException(array($this, gettype($socketResource), 0, 'invalid'), BaseListener::EXCEPTION_INVALID_SOCKET); - } // END - if - - // Get error code - $errorCode = socket_last_error($socketResource); - - // Is it without any errors? - if ($errorCode > 0) { - // Get error message - $errorMessage = socket_strerror($errorCode); - - // Shutdown this socket - $this->getListenerInstance()->shutdownSocket($socketResource); - - // And throw again - throw new InvalidSocketException(array($this, gettype($socketResource), $errorCode, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); - } // END - if - } - - /** - * Adds a socket resource to the client pool - * - * @param $socketResource A valid (must be!) socket resource - * @return void - * @throws InvalidSocketException If the given resource is invalid or errorous - */ - public function addClient ($socketResource) { - // Validate the socket - $this->validateSocket($socketResource); - - // Default is this peer's IP - $peerName = '0.0.0.0'; - - // The socket resource should not match server socket - if ($socketResource != $this->getListenerInstance()->getSocketResource()) { - // Try to determine the peer's IP number - if (!socket_getpeername($socketResource, $peerName)) { - // Get last error - $lastError = socket_last_error($socketResource); - - // Doesn't work! - throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET); - } // END - if - } else { - // Server sockets won't work with socket_getpeername() - $this->debugOutput('POOL: Socket resource is server socket. This is no bug.'); - } - - // Output error message - $this->debugOutput('POOL: Adding client ' . $peerName); - - // Add it finally to the pool - $this->addPoolEntry($socketResource); - } - - /** - * Getter for array of all socket resources - * - * @return $sockets An array with all sockets - */ - public final function getAllSockets () { - // Get the list - $sockets = $this->getArrayFromList('generic'); - - // Return it - return $sockets; - } -} - -// -?> diff --git a/application/hub/main/pools/peer/.htaccess b/application/hub/main/pools/peer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/pools/peer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php new file mode 100644 index 000000000..c6b1c986a --- /dev/null +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -0,0 +1,132 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 DefaultPeerPool extends BasePool implements PoolablePeer { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $listenerInstance A Listenable instance + * @return $poolInstance An instance a Poolable class + */ + public final static function createDefaultPeerPool (Listenable $listenerInstance) { + // Get new instance + $poolInstance = new DefaultPeerPool(); + + // Set the application instance + $poolInstance->setListenerInstance($listenerInstance); + + // Return the prepared instance + return $poolInstance; + } + + /** + * Validates given socket + * + * @param $socketResource A valid socket resource + * @return void + */ + private function validateSocket ($socketResource) { + // Is it a valid resource? + if (!is_resource($socketResource)) { + // Throw an exception + throw new InvalidSocketException(array($this, gettype($socketResource), 0, 'invalid'), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + + // Get error code + $errorCode = socket_last_error($socketResource); + + // Is it without any errors? + if ($errorCode > 0) { + // Get error message + $errorMessage = socket_strerror($errorCode); + + // Shutdown this socket + $this->getListenerInstance()->shutdownSocket($socketResource); + + // And throw again + throw new InvalidSocketException(array($this, gettype($socketResource), $errorCode, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + } + + /** + * Adds a socket resource to the peer pool + * + * @param $socketResource A valid (must be!) socket resource + * @return void + * @throws InvalidSocketException If the given resource is invalid or errorous + */ + public function addPeer ($socketResource) { + // Validate the socket + $this->validateSocket($socketResource); + + // Default is this peer's IP + $peerName = '0.0.0.0'; + + // The socket resource should not match server socket + if ($socketResource != $this->getListenerInstance()->getSocketResource()) { + // Try to determine the peer's IP number + if (!socket_getpeername($socketResource, $peerName)) { + // Get last error + $lastError = socket_last_error($socketResource); + + // Doesn't work! + throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET); + } // END - if + } else { + // Server sockets won't work with socket_getpeername() + $this->debugOutput('POOL: Socket resource is server socket. This is no bug.'); + } + + // Output error message + $this->debugOutput('POOL: Adding peer ' . $peerName); + + // Add it finally to the pool + $this->addPoolEntry($socketResource); + } + + /** + * Getter for array of all socket resources + * + * @return $sockets An array with all sockets + */ + public final function getAllSockets () { + // Get the list + $sockets = $this->getArrayFromList('generic'); + + // Return it + return $sockets; + } +} + +// +?> diff --git a/application/hub/main/queues/client/.htaccess b/application/hub/main/queues/client/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/application/hub/main/queues/client/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/hub/main/queues/client/class_LocalClientQueue.php b/application/hub/main/queues/client/class_LocalClientQueue.php deleted file mode 100644 index 07ffe19b0..000000000 --- a/application/hub/main/queues/client/class_LocalClientQueue.php +++ /dev/null @@ -1,50 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 LocalClientQueue extends BaseQueue implements Queueable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $poolInstance An instance a Queueable class - */ - public final static function createLocalClientQueue () { - // Get new instance - $poolInstance = new LocalClientQueue(); - - // Return the prepared instance - return $poolInstance; - } -} - -// -?> diff --git a/application/hub/main/queues/peer/.htaccess b/application/hub/main/queues/peer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/queues/peer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/queues/peer/class_LocalPeerQueue.php b/application/hub/main/queues/peer/class_LocalPeerQueue.php new file mode 100644 index 000000000..55e12a8b7 --- /dev/null +++ b/application/hub/main/queues/peer/class_LocalPeerQueue.php @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 LocalPeerQueue extends BaseQueue implements Queueable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @return $poolInstance An instance a Queueable class + */ + public final static function createLocalPeerQueue () { + // Get new instance + $poolInstance = new LocalPeerQueue(); + + // Return the prepared instance + return $poolInstance; + } +} + +// +?> diff --git a/application/hub/main/states/client/.htaccess b/application/hub/main/states/client/.htaccess deleted file mode 100644 index 3a4288278..000000000 --- a/application/hub/main/states/client/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/hub/main/states/client/class_BaseClientState.php b/application/hub/main/states/client/class_BaseClientState.php deleted file mode 100644 index 627b5db70..000000000 --- a/application/hub/main/states/client/class_BaseClientState.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 BaseClientState extends BaseState { - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - } -} - -// [EOF] -?> diff --git a/application/hub/main/states/peer/.htaccess b/application/hub/main/states/peer/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/peer/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/states/peer/class_BasePeerState.php b/application/hub/main/states/peer/class_BasePeerState.php new file mode 100644 index 000000000..1fc150a39 --- /dev/null +++ b/application/hub/main/states/peer/class_BasePeerState.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 BasePeerState extends BaseState { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tags/package/class_PackageTags.php b/application/hub/main/tags/package/class_PackageTags.php index a8fd09a25..f0c0ee59e 100644 --- a/application/hub/main/tags/package/class_PackageTags.php +++ b/application/hub/main/tags/package/class_PackageTags.php @@ -30,6 +30,11 @@ class PackageTags extends BaseTags implements Tagable { */ private $lastProtocol = 'invalid'; + /** + * Last found recipient type + */ + private $lastRecipientType = 'invalid'; + /** * Protected constructor * @@ -134,8 +139,9 @@ class PackageTags extends BaseTags implements Tagable { throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG); } // END - if - // Now save the last discovered protocol - $this->lastProtocol = $entry['object-protocol']; + // Now save the last discovered protocol/recipient type + $this->lastProtocol = $entry['object-protocol']; + $this->lastRecipientType = $entry['object-recipient-type']; } // END - foreach } @@ -158,6 +164,27 @@ class PackageTags extends BaseTags implements Tagable { // Return it return $protocolName; } + + /** + * Checks wether the given package data is accepted by the listener + * + * @param $packageData Raw package data + * @param $listenerInstance A Listenable instance + * @return $accepts Wether it is accepted + */ + public function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance) { + // Extract the tags + $this->extractTagsFromPackageData($packageData); + + // Now we need to verify every single tag + $this->verifyAllTags(); + + // Now simply check it out + $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid')); + + // And return the result + return $accepts; + } } // [EOF] diff --git a/application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php b/application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php index 01217b339..652f3282a 100644 --- a/application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php +++ b/application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php @@ -44,7 +44,8 @@ class ObjectRegistryTemplateEngine extends BaseTemplateEngine implements Compile 'object-name', 'object-recipient-limitation', 'object-max-spread', - 'object-protocol' + 'object-protocol', + 'object-recipient-type' ); /** @@ -381,6 +382,26 @@ class ObjectRegistryTemplateEngine extends BaseTemplateEngine implements Compile $this->getStackerInstance()->pushNamed('object_registry', 'object-protocol'); } + /** + * Starts the object-recipient-type + * + * @return void + */ + private function startObjectRecipientType () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('object_registry', 'object-recipient-type'); + } + + /** + * Finishes the object-recipient-type + * + * @return void + */ + private function finishObjectRecipientType () { + // Pop the last entry + $this->getStackerInstance()->popNamed('object_registry'); + } + /** * Finishes the object-protocol * diff --git a/application/hub/templates/xml/object_registry/object_registry.xml b/application/hub/templates/xml/object_registry/object_registry.xml index 6c0b7d9d9..d1b1c9a9e 100644 --- a/application/hub/templates/xml/object_registry/object_registry.xml +++ b/application/hub/templates/xml/object_registry/object_registry.xml @@ -56,6 +56,15 @@ along with this program. If not, see 'tcp' or 'udp', without the quotes. //--> tcp + + hub