From def13a3334fbae9bfad71c740ee4a03d818ea0fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 18 Feb 2013 05:49:14 +0000 Subject: [PATCH] Introduced Recipient implentation classes: - DirectRecipient: A direct session id that needs solving into an ip:port combination - DhtRecipient: A virtual recipient that will cause querying the local DHT data for possible recipients (unfinished) - SelfRecipient: A virtual recipient, yet direct one, as this will be resolved into *this* own node's session id - UpperRecipient A virtual recipient for all boot, master and list node's session ids - Internal TODO for above closed (and nicely solved) --- .gitattributes | 12 +++ application/hub/config.php | 16 ++++ .../hub/interfaces/queues/class_Queueable.php | 27 +----- .../hub/interfaces/recipient/.htaccess | 1 + .../interfaces/recipient/class_Recipient.php | 38 ++++++++ .../class_PackageRecipientDiscovery.php | 87 +++++-------------- application/hub/main/recipient/.htaccess | 1 + application/hub/main/recipient/class_ | 64 ++++++++++++++ .../main/recipient/class_BaseRecipient.php | 38 ++++++++ application/hub/main/recipient/dht/.htaccess | 1 + .../main/recipient/dht/class_DhtRecipient.php | 64 ++++++++++++++ .../hub/main/recipient/direct/.htaccess | 1 + .../direct/class_DirectRecipient.php | 76 ++++++++++++++++ application/hub/main/recipient/self/.htaccess | 1 + .../recipient/self/class_SelfRecipient.php | 73 ++++++++++++++++ .../hub/main/recipient/upper/.htaccess | 1 + .../recipient/upper/class_UpperRecipient.php | 79 +++++++++++++++++ .../main/states/dht/class_BaseDhtState.php | 15 ++++ 18 files changed, 502 insertions(+), 93 deletions(-) create mode 100644 application/hub/interfaces/recipient/.htaccess create mode 100644 application/hub/interfaces/recipient/class_Recipient.php create mode 100644 application/hub/main/recipient/.htaccess create mode 100644 application/hub/main/recipient/class_ create mode 100644 application/hub/main/recipient/class_BaseRecipient.php create mode 100644 application/hub/main/recipient/dht/.htaccess create mode 100644 application/hub/main/recipient/dht/class_DhtRecipient.php create mode 100644 application/hub/main/recipient/direct/.htaccess create mode 100644 application/hub/main/recipient/direct/class_DirectRecipient.php create mode 100644 application/hub/main/recipient/self/.htaccess create mode 100644 application/hub/main/recipient/self/class_SelfRecipient.php create mode 100644 application/hub/main/recipient/upper/.htaccess create mode 100644 application/hub/main/recipient/upper/class_UpperRecipient.php diff --git a/.gitattributes b/.gitattributes index c3652a7fd..e366d7bf8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -127,6 +127,8 @@ application/hub/interfaces/query/.htaccess -text svneol=unset#text/plain 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 @@ -543,6 +545,16 @@ application/hub/main/queues/class_ 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 diff --git a/application/hub/config.php b/application/hub/config.php index 6f88c4439..ce328572f 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -802,6 +802,22 @@ $cfg->setConfigEntry('announcement_answer_status_okay_handler_class', 'Announcem // 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 /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/interfaces/queues/class_Queueable.php b/application/hub/interfaces/queues/class_Queueable.php index 3064de590..f551ef47b 100644 --- a/application/hub/interfaces/queues/class_Queueable.php +++ b/application/hub/interfaces/queues/class_Queueable.php @@ -1,28 +1,3 @@ - * @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 . - */ -interface Queueable extends FrameworkInterface { -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/interfaces/recipient/.htaccess b/application/hub/interfaces/recipient/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/recipient/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/recipient/class_Recipient.php b/application/hub/interfaces/recipient/class_Recipient.php new file mode 100644 index 000000000..96e779665 --- /dev/null +++ b/application/hub/interfaces/recipient/class_Recipient.php @@ -0,0 +1,38 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 6bd982d83..5567d36ed 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -57,75 +57,28 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable * * @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()); + } + } } /** diff --git a/application/hub/main/recipient/.htaccess b/application/hub/main/recipient/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/recipient/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/recipient/class_ b/application/hub/main/recipient/class_ new file mode 100644 index 000000000..7669560cf --- /dev/null +++ b/application/hub/main/recipient/class_ @@ -0,0 +1,64 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/recipient/class_BaseRecipient.php b/application/hub/main/recipient/class_BaseRecipient.php new file mode 100644 index 000000000..f6a7a053a --- /dev/null +++ b/application/hub/main/recipient/class_BaseRecipient.php @@ -0,0 +1,38 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/recipient/dht/.htaccess b/application/hub/main/recipient/dht/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/recipient/dht/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php new file mode 100644 index 000000000..328de547b --- /dev/null +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -0,0 +1,64 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/recipient/direct/.htaccess b/application/hub/main/recipient/direct/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/recipient/direct/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php new file mode 100644 index 000000000..e3be9d856 --- /dev/null +++ b/application/hub/main/recipient/direct/class_DirectRecipient.php @@ -0,0 +1,76 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/recipient/self/.htaccess b/application/hub/main/recipient/self/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/recipient/self/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php new file mode 100644 index 000000000..5839a2f25 --- /dev/null +++ b/application/hub/main/recipient/self/class_SelfRecipient.php @@ -0,0 +1,73 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/recipient/upper/.htaccess b/application/hub/main/recipient/upper/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/recipient/upper/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php new file mode 100644 index 000000000..e0cc719c6 --- /dev/null +++ b/application/hub/main/recipient/upper/class_UpperRecipient.php @@ -0,0 +1,79 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/states/dht/class_BaseDhtState.php b/application/hub/main/states/dht/class_BaseDhtState.php index e70151cbe..8a1223acf 100644 --- a/application/hub/main/states/dht/class_BaseDhtState.php +++ b/application/hub/main/states/dht/class_BaseDhtState.php @@ -32,6 +32,21 @@ class BaseDhtState extends BaseState { // 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] -- 2.39.2