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/protocol/.htaccess -text
application/hub/interfaces/query/.htaccess -text
application/hub/interfaces/query/class_Queryable.php -text
application/hub/interfaces/queues/.htaccess -text
// CFG: HUB-LIST-CLASS
$cfg->setConfigEntry('hub_list_class', 'HubList');
+// CFG: SOCKET-REGISTRY-CLASS
+$cfg->setConfigEntry('socket_registry_class', 'SocketRegistry');
+
// [EOF]
?>
* 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 Listenable extends FrameworkInterface {
+interface Listenable extends ProtocolHandler {
/**
* Initializes the listener by setting up the required socket server
*
function isPackageEnqueued ();
/**
- * Delivers an enqueued package to the stated destination. If none is
- * provided, the registered helper class is being iterated until no target
- * is left. This allows that a single package is being delivered to multiple
- * targets without enqueueing it for every target. If no target is provided
- * or it can't be determined a NoTargetException is being thrown.
+ * Delivers an enqueued package to the stated destination. If a non-session
+ * id is provided, recipient resolver is being asked (and instanced once).
+ * This allows that a single package is being delivered to multiple targets
+ * without enqueueing it for every target. If no target is provided or it
+ * can't be determined a NoTargetException is being thrown.
*
* @return void
* @throws NoTargetException If no target can't be determined
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for protcol handlers
+ *
+ * @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 ProtocolHandler extends FrameworkInterface {
+}
+
+// [EOF]
+?>
*
* @return void
*/
- protected function __construct() {
+ protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
*
* @return void
*/
- protected function __construct() {
+ protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
}
*/
class BaseListener extends BaseHubSystem implements Visitable {
// Exception code constants
- const EXCEPTION_INVALID_SOCKET = 0xa00;
+ const EXCEPTION_INVALID_SOCKET = 0xa00;
+ const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01;
/**
* Used protocol (Default: invalid, which is indeed invalid...)
*/
private $blockingMode = false;
- /**
- * Socket resource
- */
- private $socketResource = false;
-
/**
* A client pool instance
*/
parent::__construct($className);
}
+ /**
+ * Checks wether the given socket resource is a server socket
+ *
+ * @param $socketResource A valid socket resource
+ * @return $isServerSocket Wether the socket resource is a server socket
+ */
+ protected function isServerSocketResource ($socketResource) {
+ // Check it
+ $isServerSocket = ((is_resource($socketResource)) && (!@socket_getpeername($socketResource, $peerName)));
+
+ // We need to clear the error here
+ socket_clear_error($socketResource);
+
+ // Check peer name, it must be empty
+ $isServerSocket = (($isServerSocket) && (empty($peerName)));
+
+ // Return result
+ return $isServerSocket;
+ }
+
/**
* Setter for listen address
*
return $this->blockingMode;
}
- /**
- * Setter for socket resource
- *
- * @param $socketResource The socket resource we shall set
- * @return void
- */
- protected final function setSocketResource ($socketResource) {
- $this->socketResource = $socketResource;
- }
-
- /**
- * Getter for socket resource
- *
- * @return $socketResource The socket resource we shall set
- */
- public final function getSocketResource () {
- return $this->socketResource;
- }
-
/**
* Setter for client pool instance
*
return $this->packageInstance;
}
+ /**
+ * Registeres the given socket resource for "this" listener instance. This
+ * will be done in a seperate class to allow package writers to use it
+ * again.
+ *
+ * @param $socketResource A valid server socket resource
+ * @return void
+ * @throws InvalidServerSocketException If the given resource is no server socket
+ * @throws SocketAlreadyRegisteredException If the given resource is already registered
+ */
+ protected function registerServerSocketResource ($socketResource) {
+ // First check if it is valid
+ if (!$this->isServerSocketResource($socketResource)) {
+ // No server socket
+ throw new InvalidServerSocketException(array($this, $socketResource), self::EXCEPTION_INVALID_SOCKET);
+ } elseif ($this->isServerSocketRegistered($socketResource)) {
+ // Already registered
+ throw new SocketAlreadyRegisteredException($this, self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ }
+
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Register the socket
+ $registryInstance->registerSocket($this, $socketResource);
+ }
+
+ /**
+ * Checks wether given socket resource is registered in socket registry
+ *
+ * @param $socketResource A valid server socket resource
+ * @return $isRegistered Wether given server socket is registered
+ */
+ protected function isServerSocketRegistered ($socketResource) {
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Check it
+ $isRegistered = $registryInstance->isSocketRegistered($this, $socketResource);
+
+ // Return result
+ return $isRegistered;
+ }
+
+ /**
+ * Getter for "this" socket resource
+ *
+ * @return $socketResource A valid socket resource
+ */
+ public final function getSocketResource () {
+ // Get a socket registry instance (singleton)
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+
+ // Get the socket resource
+ $socketResource = $registryInstance->getSocketResource($this);
+
+ // Return it
+ return $socketResource;
+ }
+
/**
* Accepts the visitor to process the visit "request"
*
} // END - if
// Set the main socket
- $this->setSocketResource($mainSocket);
+ $this->registerServerSocketResource($mainSocket);
// Initialize the client pool instance
$poolInstance = ObjectFactory::createObjectByConfiguredName('client_pool_class', array($this));
} // END - if
// Remember the socket in our class
- $this->setSocketResource($socket);
+ $this->registerServerSocketResource($socket);
// Output message
$this->debugOutput('LISTENER: UDP listener now ready on IP ' . $this->getListenAddress() . ', port ' . $this->getListenPort() . ' for service.');
*/
const STACKER_NAME_UNDECLARED = 'undeclared';
+ /**
+ * Network target (alias): 'upper hubs'
+ */
+ const NETWORK_TARGET_UPPER_HUBS = 'upper';
+
/**
* Protected constructor
*
crc32($content) // @TODO Not so good, but needs to be fast!
);
- // Now prepare the temporary array and push it on the 'undeclared' stack including a call-back helper instance
+ // Now prepare the temporary array and push it on the 'undeclared' stack
$this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
'sender' => $helperInstance->getNodeInstance()->getSessionId(),
- 'recipient' => null,
+ 'recipient' => self::NETWORK_TARGET_UPPER_HUBS,
'content' => $content,
- 'callback' => $helperInstance
));
}
}
/**
- * Delivers an enqueued package to the stated destination. If none is
- * provided, the registered helper class is being iterated until no target
- * is left. This allows that a single package is being delivered to multiple
- * targets without enqueueing it for every target. If no target is provided
- * or it can't be determined a NoTargetException is being thrown.
+ * Delivers an enqueued package to the stated destination. If a non-session
+ * id is provided, recipient resolver is being asked (and instanced once).
+ * This allows that a single package is being delivered to multiple targets
+ * without enqueueing it for every target. If no target is provided or it
+ * can't be determined a NoTargetException is being thrown.
*
* @return void
* @throws NoTargetException If no target can't be determined
*/
public function deliverEnqueuedPackage () {
- $this->partialStub('Please implement this method.');
+ // Make sure this method isn't working if there is no package enqueued
+ if (!$this->isPackageEnqueued()) {
+ // This is not fatal but should be avoided
+ // @TODO Add some logging here
+ return;
+ } // END - if
+
+ // Now we know for sure there are packages to deliver, we can start
+ // with the first one.
+ $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_UNDECLARED);
+ die(print_r($packageData, true));
+
+ // And remove it finally
+ $this->getStackerInstance()->popNamed(self::STACKER_NAME_UNDECLARED);
}
}
$visitorInstance->visitPool($this);
// Get a new iterator instance
- $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->poolEntriesInstance));
+ $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance()));
// Reset the counter
$iteratorInstance->rewind();
* Executes the task
*
* @return void
- * @todo 0%
*/
public function executeTask () {
// Get a singleton network package instance
./application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php:11: * @todo latency-based iteration or similar approaches
./application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php:10: * @todo This current implementation is not recommended, use a
./application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php:11: * @todo latency-based iteration or similar approaches
+./application/hub/main/listener/udp/class_UdpListener.php:101: * @todo ~50% done
./application/hub/main/listener/udp/class_UdpListener.php:61: * @todo stream_socket_server() was declared slow by some user comments.
./application/hub/main/listener/udp/class_UdpListener.php:62: * @todo Please rewrite it to socket_create() and its brothers.
-./application/hub/main/listener/udp/class_UdpListener.php:85: * @todo 0% done
./application/hub/main/lists/class_BaseList.php:264: // @TODO Extend this somehow?
./application/hub/main/nodes/boot/class_HubBootNode.php:119: // @TODO Add some filters here
./application/hub/main/nodes/boot/class_HubBootNode.php:58: * @todo add some more special bootstrap things for this boot node
./application/hub/main/nodes/boot/class_HubBootNode.php:99: * @todo Unfinished method
-./application/hub/main/nodes/class_BaseHubNode.php:412: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
-./application/hub/main/nodes/class_BaseHubNode.php:449: * @todo Change the first if() block to check for a specific state
-./application/hub/main/nodes/class_BaseHubNode.php:587: // @TODO Add some criteria, e.g. if the node is active or so
+./application/hub/main/nodes/class_BaseHubNode.php:420: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
+./application/hub/main/nodes/class_BaseHubNode.php:457: * @todo Change the first if() block to check for a specific state
+./application/hub/main/nodes/class_BaseHubNode.php:595: // @TODO Add some criteria, e.g. if the node is active or so
./application/hub/main/nodes/list/class_HubListNode.php:58: * @todo Implement more bootstrap steps
./application/hub/main/nodes/list/class_HubListNode.php:68: * @todo Unfinished method
./application/hub/main/nodes/list/class_HubListNode.php:91: // @TODO Add some filters here
./application/hub/main/nodes/regular/class_HubRegularNode.php:58: * @todo Implement this method
./application/hub/main/nodes/regular/class_HubRegularNode.php:68: * @todo Unfinished method
./application/hub/main/nodes/regular/class_HubRegularNode.php:91: // @TODO Add some filters here
-./application/hub/main/package/class_NetworkPackage.php:103: crc32($content) // @TODO Not so good, but needs to be fast!
+./application/hub/main/package/class_NetworkPackage.php:108: crc32($content) // @TODO Not so good, but needs to be fast!
+./application/hub/main/package/class_NetworkPackage.php:146: // @TODO Add some logging here
./application/hub/main/package/class_NetworkPackage.php:22: * @todo Needs to add functionality for handling the object's type
./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:67: * @todo ~30% done
./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:76: // @TODO On some systems it is 134, on some 107?
./application/hub/main/tasks/hub/class_HubSelfConnectTask.php:53: * @todo 0%
./application/hub/main/tasks/hub/ping/class_HubPingTask.php:63: * @todo 0%
./application/hub/main/tasks/hub/update/class_HubUpdateCheckTask.php:53: * @todo 0%
-./application/hub/main/tasks/network/class_NetworkPackageWriterTask.php:53: * @todo 0%
./application/hub/main/template/announcement/class_AnnouncementTemplateEngine.php:10: * @todo This template engine does not make use of setTemplateType()
./application/hub/main/template/announcement/class_AnnouncementTemplateEngine.php:256: * @todo Find something useful with this!
-./application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php:92: * @todo Does a query needs to perform some actions as an active task?
+./application/hub/main/visitor/tasks/class_ActiveTaskVisitor.php:94: * @todo Does a query needs to perform some actions as an active task?
./application/hub/main/visitor/tasks/class_ShutdownTaskVisitor.php:89: * @todo Does a query needs to perform some actions as an active task?
./inc/classes/exceptions/main/class_MissingMethodException.php:13: * @todo Try to rewrite user/guest login classes and mark this exception as deprecated
./inc/classes/exceptions/main/class_NoConfigEntryException.php:10: * @todo Rename this class to NoFoundEntryException