]> git.mxchange.org Git - hub.git/commitdiff
A lot 'FooClientBar' classes renamed to 'FooPeerBar' for naming convention, added...
authorRoland Häder <roland@mxchange.org>
Wed, 19 May 2010 10:44:58 +0000 (10:44 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 19 May 2010 10:44:58 +0000 (10:44 +0000)
46 files changed:
.gitattributes
application/hub/class_ApplicationHelper.php
application/hub/config.php
application/hub/interfaces/listener/class_Listenable.php
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/interfaces/pool/client/.htaccess [deleted file]
application/hub/interfaces/pool/client/class_PoolableClient.php [deleted file]
application/hub/interfaces/pool/peer/.htaccess [new file with mode: 0644]
application/hub/interfaces/pool/peer/class_PoolablePeer.php [new file with mode: 0644]
application/hub/interfaces/tags/class_Tagable.php
application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php
application/hub/main/iterator/network/class_NetworkListenIterator.php
application/hub/main/iterator/pool/class_DefaultIterator.php
application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php
application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php
application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php
application/hub/main/listener/class_BaseListener.php
application/hub/main/listener/class_BaseListenerDecorator.php
application/hub/main/listener/tcp/class_TcpListener.php
application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php [deleted file]
application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php
application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php [new file with mode: 0644]
application/hub/main/listener/udp/class_UdpListener.php
application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php [deleted file]
application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php
application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php [new file with mode: 0644]
application/hub/main/lists/class_BaseList.php
application/hub/main/lists/groups/class_ListGroupList.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/pools/class_BasePool.php
application/hub/main/pools/client/.htaccess [deleted file]
application/hub/main/pools/client/class_DefaultClientPool.php [deleted file]
application/hub/main/pools/peer/.htaccess [new file with mode: 0644]
application/hub/main/pools/peer/class_DefaultPeerPool.php [new file with mode: 0644]
application/hub/main/queues/client/.htaccess [deleted file]
application/hub/main/queues/client/class_LocalClientQueue.php [deleted file]
application/hub/main/queues/peer/.htaccess [new file with mode: 0644]
application/hub/main/queues/peer/class_LocalPeerQueue.php [new file with mode: 0644]
application/hub/main/states/client/.htaccess [deleted file]
application/hub/main/states/client/class_BaseClientState.php [deleted file]
application/hub/main/states/peer/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/class_BasePeerState.php [new file with mode: 0644]
application/hub/main/tags/package/class_PackageTags.php
application/hub/main/template/objects/class_ObjectRegistryTemplateEngine.php
application/hub/templates/xml/object_registry/object_registry.xml

index 07b5148197ba872b010707829cba60dfa66e8da4..3bd89630d83fe366c7b0311d6bb49e36039d9baf 100644 (file)
@@ -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
index 46343ff3755abe22086d0d91f1accbe9610e36a5..523c39cfd6da58eb9d0de518197e2510015a2541 100644 (file)
@@ -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);
index 45a0dd544c080991cfe5308d281e4e2e26c70eb2..1f4741eeab3820c12eb8d4141f7b4fb9e684e479 100644 (file)
@@ -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');
 
index ae2aca028962246343b5a41be8111dbcad1723ac..f299712d12f87357e8123a1a785a1edb07f1825f 100644 (file)
@@ -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]
index d85aa626dd1665aeb89fb3492d2477b7d976a01a..5ca4ba82b4022b35f30f3baae026e5c7c7ae2003 100644 (file)
@@ -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 (file)
index 3a42882..0000000
+++ /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 (file)
index 607c5af..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * A default client pool class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..6d91da5
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * A default peer pool class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index c00b71010d63b41b76c560aa717de1f255595ef1..c87c42967c1e61b593a1f956485fca7aceb47999 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index 8903a43e28da76a6ebd4722a9b519c2fbfb9df85..2435a4d67aa5dfb9d5b9392d8078b51ac03d511f 100644 (file)
@@ -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;
        }
 }
 
index 76832a6e1b681a62bd386ab0501559a8d6af7507..0d91d10242a4c286d2a728c5ac5060c4087fa124 100644 (file)
@@ -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());
        }
 }
 
index 82aae67231be0f014267c9be13e06c5fd754e70a..11c48f5a481bf6eac8943e75142b3da0919ddc99 100644 (file)
@@ -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
index 949c6c1882c99adc9fc814d4a8307c5645f282b2..c40dbd9d6c66bb50b722097d5a173609804b022d 100644 (file)
@@ -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
index 2a7b124b5ef8634d2c06ba677b69e34ae56a7f95..50f12c9915273d0d3196c9cc86a2ab5e24344be2 100644 (file)
@@ -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
index 39d4041eabd906aaa200411ad9b54105eceafdd5..d3e2691836f9de15a33d35797fa31e1469b10d60 100644 (file)
@@ -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
index f037f26ea95bacd58a7328e9280aaa9531f701b2..205738b0af3c9698deb6e53d2ce04e9c5363f6fb 100644 (file)
@@ -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
index 284bb99870e6dc1741926cee69c3c9fba9ec7303..1a767f9cb16a6eddfe596e1d32d54232b6c7aece 100644 (file)
@@ -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;
        }
 
index 953c131cdcfb2d22bd0b595d8314fed2c5df7c8b..5b4d71845f7417bfd9096e3251a312231b454b63 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index 1149a734b8a854108313cad51820a3f93b9b93a5..6cbe71b3b6e3f63cc54926ff93caeba08d7c4d16 100644 (file)
@@ -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 (file)
index a55e2d4..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
- * A decorator for the TcpListener to communicate to clients
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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]
-?>
index b3a6013c77986c5bee14c86f4373596977ecd778..d6e65827bbf2810b827d74b9e978e4f5e47666e9 100644 (file)
@@ -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 (file)
index 0000000..cdabf6e
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * A decorator for the TcpListener to communicate to peers
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 1f34a8b1aaa606a6cfaff713dc5d399e8d862f3f..c17064c504aea53fb8212cd67a4102c6de21fbfc 100644 (file)
@@ -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 (file)
index b6d2fda..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
- * A decorator for the UdpListener to communicate to clients
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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]
-?>
index 4595ab6b3bc35a3366b34783800405ab619bbabb..2f30e00d67da9cebed234143fa83774b87db73ab 100644 (file)
@@ -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 (file)
index 0000000..6bf5f9c
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * A decorator for the UdpListener to communicate to peers
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 3755b2605d28b83deaa87499b014097aad1f4afc..da036a52d1c4c89f7807cc810053060ca3bf2646 100644 (file)
@@ -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;
index 8fabaf62e93e56b7cd1dbcf02a063839d8e7cd48..d793765806521f1311faf69ce78f19bf53af8e4a 100644 (file)
@@ -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]
index 0fb71fcdaf6a8ba96e06436091f14e15b9f89a62..243cb14f58a2413e8fffb7ecc0c24f3b1b807c5d 100644 (file)
@@ -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);
index 7806d07ede09d44c03a5a2147c37966e4bc8ac07..f3e9d9c6324bb9477ed80f6843ed4322b9f43357 100644 (file)
@@ -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 (file)
index 3a42882..0000000
+++ /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 (file)
index f8a2338..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * A default client pool class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..c6b1c98
--- /dev/null
@@ -0,0 +1,132 @@
+<?php
+/**
+ * A default peer pool class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 3a42882..0000000
+++ /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 (file)
index 07ffe19..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * A local client queue class which is used by a LocalQueueConnector instance
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..55e12a8
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A local peer queue class which is used by a LocalQueueConnector instance
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 3a42882..0000000
+++ /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 (file)
index 627b5db..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * A general client state class
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..1fc150a
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general peer state class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index a8fd09a2598c5ad5ece8226a2816f3bf7f32246e..f0c0ee59e9410df72c9f6666b09f16cc8a4698c2 100644 (file)
@@ -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]
index 01217b339755dce69e1777b27f6fbddd3a4233b0..652f3282acb7c78053d2baf2724586607ecf8455 100644 (file)
@@ -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
         *
index 6c0b7d9d9d185dd3fe8c19b32d0355198cfcb39a..d1b1c9a9ee1c975858e9cd7457470fdf4d283b87 100644 (file)
@@ -56,6 +56,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        'tcp' or 'udp', without the quotes.
                        //-->
                        <object-protocol>tcp</object-protocol>
+                       <!--
+                       The recipient type for this type of object. This can be only one of
+                       the following:
+                       --------------------------
+                       hub  - Only other hubs may receive this object
+                       peer - Only connected peers (not hubs) may receive this object
+                       all  - Hubs and peers may receive this object
+                       //-->
+                       <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
        </object-list>
 </object-registry>