* @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.'); // Get recipients list instance and set it $listInstance = RecipientListFactory::createRecipientListInstance(); $discoveryInstance->setListInstance($listInstance); // 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) { // 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) { // Debug message /* DEBUG: */ $this->debugOutput('DISCOVERY: Adding node ' . $node . ' as recipient.'); // Add the entry $this->getListInstance()->addEntry('ip_port', $node); } // END - foreach break; // The target 'self' is always the external IP address! case NetworkPackage::NETWORK_TARGET_SELF: // Determine IP or 'external_ip' if set $ip = HubTools::determineOwnExternalIp(); // Get port and add it $ipPort = $ip . ':' . $this->getConfigInstance()->getConfigEntry('node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port'); // Add it to the list $this->getListInstance()->addEntry('ip_port', $ipPort); break; // This may be a direct recipient (node'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 iterator from it $iteratorInstance = $this->getListInstance()->getIterator(); // Return it return $iteratorInstance; } /** * Clears all recipients for e.g. another package to deliver. This method * simply clears the inner list instance. * * @return void */ public function clearRecipients () { // Clear the list $this->getListInstance()->clearList(); } } // [EOF] ?>