* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core 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 PackageRecipientDiscovery extends BaseHubDiscovery implements DiscoverableRecipient, Registerable { /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } /** * Create an instance of this class * * @return $discoveryInstance An instance of this discovery class */ public static final function createPackageRecipientDiscovery () { // Get an instance of this class $discoveryInstance = new PackageRecipientDiscovery(); // Output debug message $discoveryInstance->debugOutput('RECIPIENT-DISCOVERY: Initialized.'); // Return the prepared instance return $discoveryInstance; } /** * Tries to discover all recipients for given package data * * @param $packageData Raw package data array * @return void */ public function discoverRecipients (array $packageData) { // Get recipients list instance $listInstance = RecipientListFactory::createRecipientListInstance(); // We do some rudimentary checks but this might be a bit ugly switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) { // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes case NetworkPackage::NETWORK_TARGET_UPPER_HUBS: // Get all bootstrap nodes foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPERATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $node) { // Add the entry $listInstance->addEntry('ip_port', $node); } // END - foreach break; // The target 'self' is always the external IP address! case NetworkPackage::NETWORK_TARGET_SELF: // Is the external_ip config entry set? if ($this->getConfigInstance()->getConfigEntry('external_ip') != '') { // Use it as external ip $ip = $this->getConfigInstance()->getConfigEntry('external_ip'); } else { // Determine own external ip by connecting to my (coder) server at 188.138.90.169 $ip = ConsoleTools::determineExternalIp(); } // Get mode $mode = Registry::getRegistry()->getInstance('app')->getRequestInstance()->getRequestElement('mode'); // Set prefix $prefix = ''; if ($mode != 'regular') { // Is a special node $prefix = $mode . '_'; } // END - if // Get port and add it $ipPort = $ip . ':' . $this->getConfigInstance()->getConfigEntry($prefix . 'node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port'); // Add it to the list $listInstance->addEntry('ip_port', $ipPort); break; // This may be a direct recipient (hub's session id) default: $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); break; } // END - switch } /** * "Getter" for recipient iterator * * @return $iteratorInstance An instance of a Iterateable object */ public function getIterator () { // Get list instance $listInstance = RecipientListFactory::createRecipientListInstance(); // Get iterator from it $iteratorInstance = $listInstance->getIterator(); // Return it return $iteratorInstance; } } // [EOF] ?>