From 3cdf3e24c3e85f8f98c5e0522d65d9a29ace1e0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 19 May 2010 10:44:58 +0000 Subject: [PATCH] A lot 'FooClientBar' classes renamed to 'FooPeerBar' for naming convention, added more missing methods for socket discovery (still incomplete/dying code) --- .gitattributes | 20 ++++----- application/hub/class_ApplicationHelper.php | 2 +- application/hub/config.php | 9 ++-- .../interfaces/listener/class_Listenable.php | 8 ++++ .../hub/interfaces/nodes/class_NodeHelper.php | 2 +- .../pool/{client => peer}/.htaccess | 0 .../class_PoolablePeer.php} | 8 ++-- .../hub/interfaces/tags/class_Tagable.php | 16 +++++++ .../socket/class_PackageSocketDiscovery.php | 29 ++++++++++++- .../tcp/class_TcpNetworkPackageHandler.php | 3 +- .../network/class_NetworkListenIterator.php | 2 +- .../iterator/pool/class_DefaultIterator.php | 2 +- .../handler/class_HandlerPoolIterator.php | 2 +- .../shutdown/class_ShutdownPoolIterator.php | 2 +- .../pool/tasks/class_TaskPoolIterator.php | 2 +- .../hub/main/listener/class_BaseListener.php | 14 +++--- .../listener/class_BaseListenerDecorator.php | 24 +++++++++++ .../main/listener/tcp/class_TcpListener.php | 26 +++++++---- .../class_HubTcpListenerDecorator.php | 24 ++++++++++- ...php => class_PeerTcpListenerDecorator.php} | 32 +++++++++++--- .../main/listener/udp/class_UdpListener.php | 12 +++++- .../class_HubUdpListenerDecorator.php | 20 +++++++++ ...php => class_PeerUdpListenerDecorator.php} | 32 +++++++++++--- application/hub/main/lists/class_BaseList.php | 43 ++++++++++++++++++- .../main/lists/groups/class_ListGroupList.php | 9 ---- .../hub/main/nodes/class_BaseHubNode.php | 14 ++---- application/hub/main/pools/class_BasePool.php | 2 +- .../hub/main/pools/{client => peer}/.htaccess | 0 .../class_DefaultPeerPool.php} | 14 +++--- .../main/queues/{client => peer}/.htaccess | 0 .../class_LocalPeerQueue.php} | 8 ++-- .../main/states/{client => peer}/.htaccess | 0 .../class_BasePeerState.php} | 4 +- .../main/tags/package/class_PackageTags.php | 31 ++++++++++++- .../class_ObjectRegistryTemplateEngine.php | 23 +++++++++- .../xml/object_registry/object_registry.xml | 9 ++++ 36 files changed, 349 insertions(+), 99 deletions(-) rename application/hub/interfaces/pool/{client => peer}/.htaccess (100%) rename application/hub/interfaces/pool/{client/class_PoolableClient.php => peer/class_PoolablePeer.php} (86%) rename application/hub/main/listener/tcp/decorators/{class_ClientTcpListenerDecorator.php => class_PeerTcpListenerDecorator.php} (65%) rename application/hub/main/listener/udp/decorators/{class_ClientUdpListenerDecorator.php => class_PeerUdpListenerDecorator.php} (65%) rename application/hub/main/pools/{client => peer}/.htaccess (100%) rename application/hub/main/pools/{client/class_DefaultClientPool.php => peer/class_DefaultPeerPool.php} (90%) rename application/hub/main/queues/{client => peer}/.htaccess (100%) rename application/hub/main/queues/{client/class_LocalClientQueue.php => peer/class_LocalPeerQueue.php} (83%) rename application/hub/main/states/{client => peer}/.htaccess (100%) rename application/hub/main/states/{client/class_BaseClientState.php => peer/class_BasePeerState.php} (93%) 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/peer/.htaccess similarity index 100% rename from application/hub/interfaces/pool/client/.htaccess rename to application/hub/interfaces/pool/peer/.htaccess diff --git a/application/hub/interfaces/pool/client/class_PoolableClient.php b/application/hub/interfaces/pool/peer/class_PoolablePeer.php similarity index 86% rename from application/hub/interfaces/pool/client/class_PoolableClient.php rename to application/hub/interfaces/pool/peer/class_PoolablePeer.php index 607c5af52..6d91da516 100644 --- a/application/hub/interfaces/pool/client/class_PoolableClient.php +++ b/application/hub/interfaces/pool/peer/class_PoolablePeer.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,14 +21,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface PoolableClient extends Poolable { +interface PoolablePeer extends Poolable { /** - * Adds a socket resource to the client pool + * Adds a socket resource to the peer pool * * @param $socketResource A valid (must be!) socket resource * @return void */ - function addClient ($socketResource); + 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_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_ClientTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php similarity index 65% rename from application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php rename to application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php index a55e2d413..cdabf6e6d 100644 --- a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php +++ b/application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * 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 { +class PeerTcpListenerDecorator extends BaseListenerDecorator implements Listenable { /** * Protected constructor * @@ -30,6 +30,9 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('peer'); } /** @@ -38,9 +41,9 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public final static function createClientTcpListenerDecorator (Listenable $listenerInstance) { + public final static function createPeerTcpListenerDecorator (Listenable $listenerInstance) { // Get new instance - $decoratorInstance = new ClientTcpListenerDecorator(); + $decoratorInstance = new PeerTcpListenerDecorator(); // Set the application instance $decoratorInstance->setListenerInstance($listenerInstance); @@ -67,8 +70,25 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen // Handle generic TCP package $this->getListenerInstance()->doListen(); - // Handle client TCP package - $this->partialStub('Need to handle client TCP package.'); + // 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; } } 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_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_ClientUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php similarity index 65% rename from application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php rename to application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php index b6d2fdaf1..6bf5f9c69 100644 --- a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php +++ b/application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * 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 { +class PeerUdpListenerDecorator extends BaseListenerDecorator implements Listenable { /** * Protected constructor * @@ -30,6 +30,9 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set listener type + $this->setListenerType('peer'); } /** @@ -38,9 +41,9 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public final static function createClientUdpListenerDecorator (Listenable $listenerInstance) { + public final static function createPeerUdpListenerDecorator (Listenable $listenerInstance) { // Get new instance - $decoratorInstance = new ClientUdpListenerDecorator(); + $decoratorInstance = new PeerUdpListenerDecorator(); // Set the application instance $decoratorInstance->setListenerInstance($listenerInstance); @@ -67,8 +70,25 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen // Handle generic UDP packages first $this->getListenerInstance()->doListen(); - // Handle this client UDP package - $this->partialStub('Need to handle client UDP package.'); + // 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; } } 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/peer/.htaccess similarity index 100% rename from application/hub/main/pools/client/.htaccess rename to application/hub/main/pools/peer/.htaccess diff --git a/application/hub/main/pools/client/class_DefaultClientPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php similarity index 90% rename from application/hub/main/pools/client/class_DefaultClientPool.php rename to application/hub/main/pools/peer/class_DefaultPeerPool.php index f8a2338cb..c6b1c986a 100644 --- a/application/hub/main/pools/client/class_DefaultClientPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * 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 { +class DefaultPeerPool extends BasePool implements PoolablePeer { /** * Protected constructor * @@ -38,9 +38,9 @@ class DefaultClientPool extends BasePool implements PoolableClient { * @param $listenerInstance A Listenable instance * @return $poolInstance An instance a Poolable class */ - public final static function createDefaultClientPool (Listenable $listenerInstance) { + public final static function createDefaultPeerPool (Listenable $listenerInstance) { // Get new instance - $poolInstance = new DefaultClientPool(); + $poolInstance = new DefaultPeerPool(); // Set the application instance $poolInstance->setListenerInstance($listenerInstance); @@ -79,13 +79,13 @@ class DefaultClientPool extends BasePool implements PoolableClient { } /** - * Adds a socket resource to the client pool + * 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 addClient ($socketResource) { + public function addPeer ($socketResource) { // Validate the socket $this->validateSocket($socketResource); @@ -108,7 +108,7 @@ class DefaultClientPool extends BasePool implements PoolableClient { } // Output error message - $this->debugOutput('POOL: Adding client ' . $peerName); + $this->debugOutput('POOL: Adding peer ' . $peerName); // Add it finally to the pool $this->addPoolEntry($socketResource); diff --git a/application/hub/main/queues/client/.htaccess b/application/hub/main/queues/peer/.htaccess similarity index 100% rename from application/hub/main/queues/client/.htaccess rename to application/hub/main/queues/peer/.htaccess diff --git a/application/hub/main/queues/client/class_LocalClientQueue.php b/application/hub/main/queues/peer/class_LocalPeerQueue.php similarity index 83% rename from application/hub/main/queues/client/class_LocalClientQueue.php rename to application/hub/main/queues/peer/class_LocalPeerQueue.php index 07ffe19b0..55e12a8b7 100644 --- a/application/hub/main/queues/client/class_LocalClientQueue.php +++ b/application/hub/main/queues/peer/class_LocalPeerQueue.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * 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 { +class LocalPeerQueue extends BaseQueue implements Queueable { /** * Protected constructor * @@ -37,9 +37,9 @@ class LocalClientQueue extends BaseQueue implements Queueable { * * @return $poolInstance An instance a Queueable class */ - public final static function createLocalClientQueue () { + public final static function createLocalPeerQueue () { // Get new instance - $poolInstance = new LocalClientQueue(); + $poolInstance = new LocalPeerQueue(); // Return the prepared instance return $poolInstance; diff --git a/application/hub/main/states/client/.htaccess b/application/hub/main/states/peer/.htaccess similarity index 100% rename from application/hub/main/states/client/.htaccess rename to application/hub/main/states/peer/.htaccess diff --git a/application/hub/main/states/client/class_BaseClientState.php b/application/hub/main/states/peer/class_BasePeerState.php similarity index 93% rename from application/hub/main/states/client/class_BaseClientState.php rename to application/hub/main/states/peer/class_BasePeerState.php index 627b5db70..1fc150a39 100644 --- a/application/hub/main/states/client/class_BaseClientState.php +++ b/application/hub/main/states/peer/class_BasePeerState.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseClientState extends BaseState { +class BasePeerState extends BaseState { /** * Protected constructor * 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 -- 2.39.5