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
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
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
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
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
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
$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);
$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');
// 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');
* @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]
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
*/
+++ /dev/null
-Deny from all
+++ /dev/null
-<?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]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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]
+?>
* 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]
*
* @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
*/
$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;
}
}
$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);
// Get a state from the resolver for this package
$stateInstance = $this->getResolverInstance()->resolveStateByPackage($this, $rawData);
+ die('UNFINISHED:'.$stateInstance->__toString());
}
}
* @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
* @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
* @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
* @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
* @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
private $blockingMode = false;
/**
- * A client pool instance
+ * A peer pool instance
*/
private $poolInstance = null;
}
/**
- * 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;
}
* 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
*
// 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]
// 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);
$writers = array();
$excepts = array();
- // Check if we have some clients left
+ // Check if we have some peers left
$left = socket_select(
$readers,
$writers,
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());
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?
// 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]
+++ /dev/null
-<?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]
-?>
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set listener type
+ $this->setListenerType('hub');
}
/**
*
* @return void
*/
- public function initListener() {
+ public function initListener () {
$this->partialStub('WARNING: This method should not be called.');
}
*
* @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]
--- /dev/null
+<?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]
+?>
* @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
// 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]
+++ /dev/null
-<?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]
-?>
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set listener type
+ $this->setListenerType('hub');
}
/**
// 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]
--- /dev/null
+<?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]
+?>
// 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');
}
/**
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
*
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;
// 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]
*/
private $isActive = false;
- /**
- * List instance of all hubs
- */
- private $hubsInstance = false;
-
/**
* Protected constructor
*
// 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();
}
}
/**
- * 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
*/
$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);
$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);
}
/**
- * 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
+++ /dev/null
-Deny from all
+++ /dev/null
-<?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;
- }
-}
-
-//
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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;
+ }
+}
+
+//
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?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;
- }
-}
-
-//
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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;
+ }
+}
+
+//
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?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]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?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]
+?>
*/
private $lastProtocol = 'invalid';
+ /**
+ * Last found recipient type
+ */
+ private $lastRecipientType = 'invalid';
+
/**
* Protected constructor
*
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
}
// 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]
'object-name',
'object-recipient-limitation',
'object-max-spread',
- 'object-protocol'
+ 'object-protocol',
+ 'object-recipient-type'
);
/**
$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
*
'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>