application/hub/interfaces/query/class_Queryable.php svneol=native#text/plain
application/hub/interfaces/queues/.htaccess -text svneol=unset#text/plain
application/hub/interfaces/queues/class_Queueable.php svneol=native#text/plain
+application/hub/interfaces/recipient/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/recipient/class_Recipient.php svneol=native#text/plain
application/hub/interfaces/socket/.htaccess -text svneol=unset#text/plain
application/hub/interfaces/socket/class_SocketTag.php svneol=native#text/plain
application/hub/interfaces/source/.htaccess svneol=native#text/plain
application/hub/main/queues/class_BaseQueue.php svneol=native#text/plain
application/hub/main/queues/peer/.htaccess -text svneol=unset#text/plain
application/hub/main/queues/peer/class_LocalPeerQueue.php svneol=native#text/plain
+application/hub/main/recipient/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/class_ svneol=native#text/plain
+application/hub/main/recipient/dht/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/dht/class_DhtRecipient.php svneol=native#text/plain
+application/hub/main/recipient/direct/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/direct/class_DirectRecipient.php svneol=native#text/plain
+application/hub/main/recipient/self/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/self/class_SelfRecipient.php svneol=native#text/plain
+application/hub/main/recipient/upper/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/upper/class_UpperRecipient.php svneol=native#text/plain
application/hub/main/registry/.htaccess -text svneol=unset#text/plain
application/hub/main/registry/connection/.htaccess -text svneol=unset#text/plain
application/hub/main/registry/connection/class_ConnectionRegistry.php svneol=native#text/plain
// CFG: REQUEST-NODE-LIST-ANSWER-STATUS-OKAY-HANDLER-CLASS
$cfg->setConfigEntry('request_node_list_answer_status_okay_handler_class', 'RequestNodeListAnswerOkayHandler');
+///////////////////////////////////////////////////////////////////////////////
+// Recipient resolver
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: DIRECT-RECIPIENT-CLASS
+$cfg->setConfigEntry('direct_recipient_class', 'DirectRecipient');
+
+// CFG: DHT-RECIPIENT-CLASS
+$cfg->setConfigEntry('dht_recipient_class', 'DhtRecipient');
+
+// CFG: SELF-RECIPIENT-CLASS
+$cfg->setConfigEntry('self_recipient_class', 'SelfRecipient');
+
+// CFG: UPPER-RECIPIENT-CLASS
+$cfg->setConfigEntry('upper_recipient_class', 'UpperRecipient');
+
///////////////////////////////////////////////////////////////////////////////
// Cruncher configuration
///////////////////////////////////////////////////////////////////////////////
<?php
-/**
- * An interface for queues
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 Queueable extends FrameworkInterface {
-}
-
-// [EOF]
+// @DEPRECATED
?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for recipients
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 Recipient extends FrameworkInterface {
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ */
+ function resolveRecipient ($recipient, Listable $listInstance);
+}
+
+// [EOF]
+?>
*
* @param $packageData Raw package data array
* @return void
- * @todo Find a better way than this switch/case/default thing
*/
public function discoverRecipients (array $packageData) {
- // We do some rudimentary checks but this might be a bit ugly
- switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
- case NetworkPackage::NETWORK_TARGET_UPPER_NODES: // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
- // Get all bootstrap nodes
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
- // Is maximum reached?
- if ($this->getListInstance()->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
-
- // Then stop adding more
- break;
- } // END - if
-
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Adding node ' . $ipPort . ' as recipient.');
-
- // Add the entry
- $this->getListInstance()->addEntry('ip_port', $ipPort);
- } // END - foreach
- break;
-
- case NetworkPackage::NETWORK_TARGET_SELF: // The target 'self' is always the external IP address!
- // Determine own port
- $port = $this->getConfigInstance()->getConfigEntry('node_listen_port');
-
- // Determine IP or 'external_ip' if set
- $ip = HubTools::determineOwnExternalIp();
-
- // Is it not empty?
- if (!empty($ip)) {
- // Add it to the list
- $this->getListInstance()->addEntry('ip_port', $ip . ':' . $port);
- } // END - if
- break;
-
- case NetworkPackage::NETWORK_TARGET_DHT: // The target 'dht' is a list from local DHT query
- $this->partialStub('DHT recipient unimplemented: packageData=' . print_r($packageData, true));
- break;
-
- default: // This may be a direct recipient (node's session id)
- /*
- * Try to solve it, if an exception comes back, it is not a
- * session-id, nor IP:port and not a hostname:port combination.
- */
- try {
- // "Explode" all recipients
- $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Is maximum reached?
- assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
-
- // Try it on all
- foreach ($recipients as $recipient) {
- // Try to sole a single recipient
- $ipPort = HubTools::resolveSessionId($recipient);
-
- // Add it as recipient
- $this->getListInstance()->addEntry('ip_port', $ipPort);
- } // END - foreach
- } catch (FrameworkException $e) {
- // Didn't work, pleace add more code
- $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',packageData=' . print_r($packageData, true) . ',exception=' . $e->__toString() . ',message=' . $e->getMessage());
- }
- break;
- } // END - switch
+ // First try out the direct recipient (session id)
+ try {
+ // Get instance (should not break)
+ $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
+
+ // Try to solve it
+ $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance());
+ } catch (FrameworkException $e) {
+ // Didn't work, so try the non-generic, depending recipient field itself (this may fail)
+ try {
+ // Try to find the right class
+ $recipientInstance = ObjectFactory::createObjectByConfiguredName(strtolower($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) . '_recipient_class');
+
+ // And try to solve again
+ $recipientInstance->resolveRecipient('', $this->getListInstance());
+ } catch (FrameworkException $e) {
+ // Could not find class, what ever failed
+ $this->debugInstance($e->getMessage());
+ }
+ }
}
/**
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 ???Recipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function create???Recipient () {
+ // Get new instance
+ $recipientInstance = new ???Recipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ * @todo 0% done
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance) {
+ $this->partialStub('Please implement this method. recipient=' . $recipient);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general Recipient class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 BaseRecipient extends BaseHubSystem {
+ /**
+ * 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 DHT recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 DhtRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createDhtRecipient () {
+ // Get new instance
+ $recipientInstance = new DhtRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ * @todo 0% done
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance) {
+ $this->partialStub('Please implement this method. recipient=' . $recipient);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Direct recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 DirectRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createDirectRecipient () {
+ // Get new instance
+ $recipientInstance = new DirectRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance = NULL) {
+ // "Explode" all recipients
+ $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
+
+ // Is maximum reached?
+ assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
+
+ // Try it on all
+ foreach ($recipients as $recipient) {
+ // Try to sole a single recipient
+ $ipPort = HubTools::resolveSessionId($recipient);
+
+ // Add it as recipient
+ $listInstance->addEntry('ip_port', $ipPort);
+ } // END - foreach
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Self recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 SelfRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createSelfRecipient () {
+ // Get new instance
+ $recipientInstance = new SelfRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance) {
+ // Determine own port
+ $port = $this->getConfigInstance()->getConfigEntry('node_listen_port');
+
+ // Determine IP or 'external_ip' if set
+ $ip = HubTools::determineOwnExternalIp();
+
+ // Is it not empty?
+ if (!empty($ip)) {
+ // Add it to the list
+ $listInstance->addEntry('ip_port', $ip . ':' . $port);
+ } // END - if
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Upper recipient
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 UpperRecipient extends BaseRecipient implements Recipient {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $recipientInstance An instance of a Recipient class
+ */
+ public final static function createUpperRecipient () {
+ // Get new instance
+ $recipientInstance = new UpperRecipient();
+
+ // Return the prepared instance
+ return $recipientInstance;
+ }
+
+ /**
+ * Tries to resolve given recipient into session ids or ip:port combination
+ * depending on implementation (hint: Template Method Pattern)
+ *
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @throws FrameworkException Could throw different exceptions back depending on implementation
+ */
+ public function resolveRecipient ($recipient, Listable $listInstance) {
+ // Get all bootstrap nodes
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
+ // Is maximum reached?
+ if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
+
+ // Then stop adding more
+ break;
+ } // END - if
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $ipPort . ' as recipient.');
+
+ // Add the entry
+ $listInstance->addEntry('ip_port', $ipPort);
+ } // END - foreach
+ }
+}
+
+// [EOF]
+?>
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * Validates whether the DHT state is 'init' or throws an exception if it
+ * is every other state.
+ *
+ * @return void
+ * @throws InvalidStateException If the state is not 'active'
+ */
+ public function validateDhtStateIsInitialized () {
+ // Just compare it...
+ if (!$this instanceof DhtInitState) {
+ // Throw the exception
+ throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
}
// [EOF]