- Added new interface + first (completely unfinished) implementation for UNL discovery
-
- Made UNL upper-case
Signed-off-by: Roland Haeder <roland@mxchange.org>
// CFG: DHT-RECIPIENT-DISCOVERY-CLASS
$cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery');
+// CFG: UNIVERSAL-NODE-LOCATOR-DISCOVERY-CLASS
+$cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery');
+
// CFG: RECIPIENT-LIST-CLASS
$cfg->setConfigEntry('recipient_list_class', 'RecipientList');
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Discoverable extends FrameworkInterface {
- /**
- * "Getter" for recipient iterator
- *
- * @return $iteratorInstance An instance of a Iterateable object
- */
- function getIterator ();
-
- /**
- * Clears all recipients for e.g. another package to deliver
- *
- * @return void
- */
- function clearRecipients ();
-
- /**
- * Checks whether the recipient list is empty
- *
- * @return $isEmpty Whether the recipient list is empty
- */
- function isRecipientListEmpty ();
}
// [EOF]
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An interface for socket discovery
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 DiscoverableDhtRecipient extends Discoverable {
- /**
- * Resolves one or more recipients for a DHT transfer by given package data.
- *
- * @param $packageData Valid package data array
- * @return $recipients An indexed array with DHT recipients
- */
- function resolveRecipientsByPackageData (array $packageData);
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An interface for recipient discovery
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 DiscoverableNodeRecipient extends Discoverable, IteratorAggregate {
- /**
- * Tries to discover all recipients for given package data
- *
- * @param $packageData Raw package data array
- * @return void
- */
- function discoverRecipients (array $packageData);
-
- /**
- * Tries to discover all recipients by given decoded package data.
- *
- * @param $decodedData Raw raw package data array
- * @return void
- */
- function discoverRawRecipients (array $decodedData);
-
- /**
- * "Getter" for recipient iterator
- *
- * @return $iteratorInstance An instance of a Iterateable object
- */
- function getIterator ();
-
- /**
- * Clears all recipients for e.g. another package to deliver
- *
- * @return void
- */
- function clearRecipients ();
-}
-
-// [EOF]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for recipient discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DiscoverableRecipient extends Discoverable {
+ /**
+ * "Getter" for recipient iterator
+ *
+ * @return $iteratorInstance An instance of a Iterateable object
+ */
+ function getIterator ();
+
+ /**
+ * Clears all recipients for e.g. another package to deliver
+ *
+ * @return void
+ */
+ function clearRecipients ();
+
+ /**
+ * Checks whether the recipient list is empty
+ *
+ * @return $isEmpty Whether the recipient list is empty
+ */
+ function isRecipientListEmpty ();
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for DHT recipient discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DiscoverableDhtRecipient extends DiscoverableRecipient {
+ /**
+ * Resolves one or more recipients for a DHT transfer by given package data.
+ *
+ * @param $packageData Valid package data array
+ * @return $recipients An indexed array with DHT recipients
+ */
+ function resolveRecipientsByPackageData (array $packageData);
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for node recipient discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DiscoverableNodeRecipient extends DiscoverableRecipient {
+ /**
+ * Tries to discover all recipients for given package data
+ *
+ * @param $packageData Raw package data array
+ * @return void
+ */
+ function discoverRecipients (array $packageData);
+
+ /**
+ * Tries to discover all recipients by given decoded package data.
+ *
+ * @param $decodedData Raw raw package data array
+ * @return void
+ */
+ function discoverRawRecipients (array $decodedData);
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for socket discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DiscoverableSocket extends DiscoverableRecipient {
+ /**
+ * Tries to discover the right socket for given package data and returns a
+ * matching socket resource.
+ *
+ * @param $packageData Raw package data array
+ * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
+ * @return $socketResource A valid socket resource
+ * @throws NoListGroupException If the procol group is not found in peer list
+ * @throws NullPointerException If listenerInstance is NULL
+ */
+ function discoverSocket (array $packageData, $connectionType);
+}
+
+// [EOF]
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An interface for socket discovery
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 DiscoverableSocket extends Discoverable {
- /**
- * Tries to discover the right socket for given package data and returns a
- * matching socket resource.
- *
- * @param $packageData Raw package data array
- * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
- * @return $socketResource A valid socket resource
- * @throws NoListGroupException If the procol group is not found in peer list
- * @throws NullPointerException If listenerInstance is NULL
- */
- function discoverSocket (array $packageData, $connectionType);
-}
-
-// [EOF]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for UNL discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DiscoverableUniversalNodeLocator extends Discoverable {
+}
+
+// [EOF]
+?>
function doSelfConnection (Taskable $taskInstance);
/**
- * Determines the universal node locator
+ * Determines the Universal Node Locator
*
- * @return $unl A an universal node locator for this node
+ * @return $unl A an Universal Node Locator for this node
*/
function determineUniversalNodeLocator ();
/**
- * "Getter for an universal node locator array
+ * "Getter for an Universal Node Locator array
*
- * @return $unlArray An array an universal node locator for this node
+ * @return $unlArray An array an Universal Node Locator for this node
*/
function getUniversalNodeLocatorArray ();
*/
interface Recipient extends FrameworkInterface {
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
* @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
--- /dev/null
+<?php
+/**
+ * A !!! discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 !!!Discovery extends BaseNodeDiscovery implements Discoverable,,,, 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 create!!!Discovery () {
+ // Get an instance of this class
+ $discoveryInstance = new !!!Discovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
<?php
/**
- * A PackageRecipient discovery class
+ * A general node discovery class
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
-
- /*
- * Get recipients list instance and set it here for all discovery
- * implementations.
- */
- $listInstance = RecipientListFactory::createRecipientListInstance();
- $this->setListInstance($listInstance);
- }
-
- /**
- * Determines the protoctol name
- *
- * @param $packageData Valid package data
- * @return $protocolInstance An instance of a ProtocolHandler class
- */
- protected function determineProtocolByPackageData (array $packageData) {
- // First we need a tags instance
- $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
-
- /*
- * We need to decide here which socket (TCP or UDP) should be used for
- * the actual data transmission. In this process we will find out if
- * the recipient of this package has already a known (registered) socket
- * and if so we can re-use it. If there is no socket registered, we try
- * to make a new connection to the given universal node locator.
- */
- $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
-
- // Return it
- return $protocolInstance;
- }
-
- /**
- * "Getter" for recipient iterator
- *
- * @return$iteratorInstance An instance of a Iterateable object
- */
- public final 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 final function clearRecipients () {
- // Clear the list
- $this->getListInstance()->clearList();
- }
-
- /**
- * Checks whether the recipient list is empty
- *
- * @return $isEmpty Whether the recipient list is empty
- */
- public final function isRecipientListEmpty () {
- // Check it ...
- $isEmpty = ($this->getListInstance()->count() == 0);
-
- // Return it
- return $isEmpty;
}
}
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A DhtRecipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 DhtRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableDhtRecipient, 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 createDhtRecipientDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new DhtRecipientDiscovery();
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Set it here
- $discoveryInstance->setDhtInstance($dhtInstance);
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Resolves one or more recipients for a DHT transfer by given package data.
- *
- * @param $packageData Valid package data array
- * @return $recipients An indexed array with DHT recipients
- */
- public function resolveRecipientsByPackageData (array $packageData) {
- // Use facade to get recipients back
- $recipients = $this->getDhtInstance()->findRecipientsByPackageData($packageData);
-
- // Return it
- return $recipients;
- }
-}
-
-// [EOF]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UniversalNodeLocator discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements DiscoverableUniversalNodeLocator, 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 createUniversalNodeLocatorDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new UniversalNodeLocatorDiscovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A PackageRecipient discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 PackageRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableNodeRecipient, 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();
-
- // 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) {
- // This must be available
- //* DEBUG: */ print $this->__toString() . ': packageData=' . print_r($packageData, TRUE);
- assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // 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(), $packageData);
- } 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($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
- } catch (FrameworkException $e) {
- // Could not find class, what ever failed
- $this->debugInstance($e->getMessage());
- }
- }
- }
-
- /**
- * Tries to discover all recipients by given decoded package data.
- *
- * @param $decodedData Raw raw package data array
- * @return void
- * @todo Add some validation of recipient field, e.g. an universal node locator is found
- * @todo The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
- */
- public function discoverRawRecipients (array $decodedData) {
- // This must be available
- assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
-
- // First clear all recipients
- $this->clearRecipients();
-
- // Explode 'recipient', first element is the IP/hostname
- $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Is the 'recipient' field same as this peer's IP?
- if ((($recipient[0] == HubTools::determineOwnExternalIp()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) {
- /*
- * Is same as own external IP + TCP/UDP listen port or internal IP, don't do anything here so other
- * classes found an empty recipient list for internal (own) handling
- * of the original content.
- */
-
- // Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
- } else {
- // Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external ip (' . HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
-
- // This package is to be delivered to someone else, so add it
- $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
- }
- }
-}
-
-// [EOF]
-?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A !!! recipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 !!!RecipientDiscovery extends BaseRecipientDiscovery implements Discoverable,,,Recipient, 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 create!!!Discovery () {
+ // Get an instance of this class
+ $discoveryInstance = new !!!Discovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A PackageRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 BaseRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableRecipient {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real class name
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ /*
+ * Get recipients list instance and set it here for all discovery
+ * implementations.
+ */
+ $listInstance = RecipientListFactory::createRecipientListInstance();
+ $this->setListInstance($listInstance);
+ }
+
+ /**
+ * Determines the protoctol name
+ *
+ * @param $packageData Valid package data
+ * @return $protocolInstance An instance of a ProtocolHandler class
+ */
+ protected function determineProtocolByPackageData (array $packageData) {
+ // First we need a tags instance
+ $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+ /*
+ * We need to decide here which socket (TCP or UDP) should be used for
+ * the actual data transmission. In this process we will find out if
+ * the recipient of this package has already a known (registered) socket
+ * and if so we can re-use it. If there is no socket registered, we try
+ * to make a new connection to the given Universal Node Locator.
+ */
+ $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
+
+ // Return it
+ return $protocolInstance;
+ }
+
+ /**
+ * "Getter" for recipient iterator
+ *
+ * @return$iteratorInstance An instance of a Iterateable object
+ */
+ public final 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 final function clearRecipients () {
+ // Clear the list
+ $this->getListInstance()->clearList();
+ }
+
+ /**
+ * Checks whether the recipient list is empty
+ *
+ * @return $isEmpty Whether the recipient list is empty
+ */
+ public final function isRecipientListEmpty () {
+ // Check it ...
+ $isEmpty = ($this->getListInstance()->count() == 0);
+
+ // Return it
+ return $isEmpty;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A DhtRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 DhtRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableDhtRecipient, 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 createDhtRecipientDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new DhtRecipientDiscovery();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Set it here
+ $discoveryInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Resolves one or more recipients for a DHT transfer by given package data.
+ *
+ * @param $packageData Valid package data array
+ * @return $recipients An indexed array with DHT recipients
+ */
+ public function resolveRecipientsByPackageData (array $packageData) {
+ // Use facade to get recipients back
+ $recipients = $this->getDhtInstance()->findRecipientsByPackageData($packageData);
+
+ // Return it
+ return $recipients;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A PackageRecipient discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 PackageRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableNodeRecipient, 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();
+
+ // 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) {
+ // This must be available
+ //* DEBUG: */ print $this->__toString() . ': packageData=' . print_r($packageData, TRUE);
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // 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(), $packageData);
+ } 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($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
+ } catch (FrameworkException $e) {
+ // Could not find class, what ever failed
+ $this->debugInstance($e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * Tries to discover all recipients by given decoded package data.
+ *
+ * @param $decodedData Raw raw package data array
+ * @return void
+ * @todo Add some validation of recipient field, e.g. an Universal Node Locator is found
+ * @todo The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
+ */
+ public function discoverRawRecipients (array $decodedData) {
+ // This must be available
+ assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // First clear all recipients
+ $this->clearRecipients();
+
+ // Explode 'recipient', first element is the IP/hostname
+ $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Is the 'recipient' field same as this peer's IP?
+ if ((($recipient[0] == HubTools::determineOwnExternalIp()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) {
+ /*
+ * Is same as own external IP + TCP/UDP listen port or internal IP, don't do anything here so other
+ * classes found an empty recipient list for internal (own) handling
+ * of the original content.
+ */
+
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
+ } else {
+ // Debug output (may flood)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external ip (' . HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
+
+ // This package is to be delivered to someone else, so add it
+ $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ }
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A socket discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 PackageSocketDiscovery extends BaseRecipientDiscovery implements DiscoverableSocket, 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 createPackageSocketDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new PackageSocketDiscovery();
+
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Initialized.');
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * Tries to dicover the right listener instance
+ *
+ * @param $protocolName Protocol name
+ * @param $packageData Raw package data
+ * @return $listenerInstance An instance of a Listenable instance or null
+ */
+ public function discoverListenerInstance ($protocolName, array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ' - ENTERED!');
+
+ /*
+ * Get the listener pool instance, we need to lookup the matching
+ * listener->poolInstance chain there.
+ */
+ $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance();
+
+ // Init listener instance
+ $listenerInstance = NULL;
+
+ /*
+ * Now we need to choose again. It is whether we are speaking with a hub
+ * or with a client. So just handle it over to all listeners in this
+ * pool.
+ */
+ foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromGroup($protocolName) as $listenerInstance) {
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString());
+
+ // Does the listener want that package?
+ if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
+ // This listener likes our package data, so abort here
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is accepting package data.');
+ break;
+ } // END - if
+
+ // Debug output
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is NOT accepting package data.');
+ } // END - foreach
+
+ // Return it
+ return $listenerInstance;
+ }
+
+ /**
+ * Tries to discover the right socket for given package data and returns a
+ * matching socket resource for that protocol.
+ *
+ * @param $packageData Raw package data array
+ * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
+ * @return $socketResource A valid socket resource or FALSE if an error occured
+ * @throws NoListGroupException If the procol group is not found in peer list
+ * @throws NullPointerException If listenerInstance is NULL
+ */
+ public function discoverSocket (array $packageData, $connectionType) {
+ // Assert on type
+ assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
+
+ // Determine protocol name
+ $protocolName = $this->determineProtocolByPackageData($packageData);
+
+ // Is it the same?
+ assert(strtoupper($protocolName) == $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]);
+
+ // Get the listener instance
+ $listenerInstance = $this->discoverListenerInstance($protocolName, $packageData);
+
+ // If there is no listener who wants to have that package, we simply drop it here
+ if (is_null($listenerInstance)) {
+ // Abort with no resource
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ } // END - if
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, TRUE));
+
+ /*
+ * Now we have the listener instance, we can determine the right
+ * resource to continue. The first step is to get the attached pool
+ * instance and pass over the whole package data to get the right
+ * socket.
+ */
+ $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType);
+
+ // Debug message
+ if (is_resource($socketResource)) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, TRUE));
+ } else {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
+ }
+
+ // Is it FALSE, the recipient isn't known to us and we have no connection to it
+ if (($socketResource === FALSE) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
+ // Try to create a new socket resource
+ try {
+ // Possibly noisy debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+
+ // Get a socket resource from our factory (if succeeded)
+ $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
+ } catch (SocketConnectionException $e) {
+ // The connection fails of being established, so log it away
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
+ }
+ } // END - if
+
+ // Try to resolve the socket resource
+ try {
+ // Get the helper instance from registry
+ $helperInstance = Registry::getRegistry()->getInstance('connection');
+
+ // Possibly noisy debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Going to resolve socket from peer state and given package data ...');
+
+ // Resolve the peer's state (but ignore return value)
+ PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
+ } catch (InvalidSocketException $e) {
+ // This cannot be fixed, so log it away
+ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage());
+
+ // Make any failed attempts to 'FALSE'
+ $socketResource = FALSE;
+ }
+
+ // And return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
+ return $socketResource;
+ }
+}
+
+// [EOF]
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A socket discovery class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 PackageSocketDiscovery extends BaseNodeDiscovery implements DiscoverableSocket, 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 createPackageSocketDiscovery () {
- // Get an instance of this class
- $discoveryInstance = new PackageSocketDiscovery();
-
- // Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Initialized.');
-
- // Return the prepared instance
- return $discoveryInstance;
- }
-
- /**
- * Tries to dicover the right listener instance
- *
- * @param $protocolName Protocol name
- * @param $packageData Raw package data
- * @return $listenerInstance An instance of a Listenable instance or null
- */
- public function discoverListenerInstance ($protocolName, array $packageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ' - ENTERED!');
-
- /*
- * Get the listener pool instance, we need to lookup the matching
- * listener->poolInstance chain there.
- */
- $poolInstance = NodeObjectFactory::createNodeInstance()->getListenerPoolInstance();
-
- // Init listener instance
- $listenerInstance = NULL;
-
- /*
- * Now we need to choose again. It is whether we are speaking with a hub
- * or with a client. So just handle it over to all listeners in this
- * pool.
- */
- foreach ($poolInstance->getPoolEntriesInstance()->getArrayFromGroup($protocolName) as $listenerInstance) {
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $protocolName . ',listenerInstance=' . $listenerInstance->__toString());
-
- // Does the listener want that package?
- if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) {
- // This listener likes our package data, so abort here
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is accepting package data.');
- break;
- } // END - if
-
- // Debug output
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Listener is NOT accepting package data.');
- } // END - foreach
-
- // Return it
- return $listenerInstance;
- }
-
- /**
- * Tries to discover the right socket for given package data and returns a
- * matching socket resource for that protocol.
- *
- * @param $packageData Raw package data array
- * @param $connectionType Type of connection, can be 'incoming' or 'outgoing', *NEVER* 'server'!
- * @return $socketResource A valid socket resource or FALSE if an error occured
- * @throws NoListGroupException If the procol group is not found in peer list
- * @throws NullPointerException If listenerInstance is NULL
- */
- public function discoverSocket (array $packageData, $connectionType) {
- // Assert on type
- assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
-
- // Determine protocol name
- $protocolName = $this->determineProtocolByPackageData($packageData);
-
- // Is it the same?
- assert(strtoupper($protocolName) == $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]);
-
- // Get the listener instance
- $listenerInstance = $this->discoverListenerInstance($protocolName, $packageData);
-
- // If there is no listener who wants to have that package, we simply drop it here
- if (is_null($listenerInstance)) {
- // Abort with no resource
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, TRUE));
-
- /*
- * Now we have the listener instance, we can determine the right
- * resource to continue. The first step is to get the attached pool
- * instance and pass over the whole package data to get the right
- * socket.
- */
- $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType);
-
- // Debug message
- if (is_resource($socketResource)) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',error=' . socket_strerror(socket_last_error($socketResource)) . ',packageData=' . print_r($packageData, TRUE));
- } else {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
- }
-
- // Is it FALSE, the recipient isn't known to us and we have no connection to it
- if (($socketResource === FALSE) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
- // Try to create a new socket resource
- try {
- // Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
-
- // Get a socket resource from our factory (if succeeded)
- $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
- } catch (SocketConnectionException $e) {
- // The connection fails of being established, so log it away
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
- }
- } // END - if
-
- // Try to resolve the socket resource
- try {
- // Get the helper instance from registry
- $helperInstance = Registry::getRegistry()->getInstance('connection');
-
- // Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Going to resolve socket from peer state and given package data ...');
-
- // Resolve the peer's state (but ignore return value)
- PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
- } catch (InvalidSocketException $e) {
- // This cannot be fixed, so log it away
- self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Cannot discover socket resource for recipient ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ': ' . $e->getMessage());
-
- // Make any failed attempts to 'FALSE'
- $socketResource = FALSE;
- }
-
- // And return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: socketResource=' . $socketResource . ',packageData=' . print_r($packageData, TRUE));
- return $socketResource;
- }
-}
-
-// [EOF]
-?>
$listInstance = new RecipientList();
// Add groups:
- // 1.) universal node locators
+ // 1.) Universal Node Locators
$listInstance->addGroup('unl');
// 2.) Session ids
}
/**
- * Determines the universal node locator
+ * Determines the Universal Node Locator
*
- * @return $unl A an universal node locator for this node
+ * @return $unl A an Universal Node Locator for this node
*/
- public final function determineUniversalNodeLocator () {
- // Get IP and port
- $unl = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
+ public function determineUniversalNodeLocator () {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 1) "Determine it
+ $unl = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
// Return it
return $unl;
}
/**
- * "Getter" for universal node locator array
+ * "Getter" for Universal Node Locator array
*
- * @return $unlArray An array of the universal node locator for this node
+ * @return $unlArray An array of the Universal Node Locator for this node
*/
public final function getUniversalNodeLocatorArray () {
- // Get IP and port
+ // Get Universal Node Locator (UNL)
+ $unl = $this->determineUniversalNodeLocator();
+
// @TODO Unfinished
- die(__METHOD__ . ':' . print_r($this, TRUE));
- $unlArray = explode(':', $this->determineUniversalNodeLocator());
+ die(__METHOD__ . ':' . print_r($unl, TRUE));
// Return it
return $unlArray;
// Temporary resolve recipient field
$recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
- // Make sure it is a valid universal node locator array (3 elements)
+ // Make sure it is a valid Universal Node Locator array (3 elements)
assert(count($recipientIpArray) == 3);
// Debug message
}
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
* @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
}
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern). This
* implementation will add more than one recipient to the list as a DHT is
* distributed and the package might go to more than one recipient.
}
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
* @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
}
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
* @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
}
/**
- * Tries to resolve given recipient into session ids or universal node locator
+ * Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
* @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
}
/**
- * Resolves a session id into an universal node locator. The opposite method
+ * Resolves a session id into an Universal Node Locator. The opposite method
* is resolveSessionIdByUniversalNodeLocator()
*
* @param $sessionId A valid session id
- * @return $recipientUniversalNodeLocator Recipient as universal node locator
+ * @return $recipientUniversalNodeLocator Recipient as Universal Node Locator
*/
protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
// Init variable
$recipientUniversalNodeLocator = 'invalid:invalid';
- // And ask it for universal node locator by given session id
+ // And ask it for Universal Node Locator by given session id
$recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
// Is the recipient valid?
// Is the session id the same?
if ($nodeInstance->getSessionId() == $sessionId) {
- // Then get the universal node locator from it, assume TCP by default
+ // Then get the Universal Node Locator from it, assume TCP by default
$recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
} // END - if
}
}
/**
- * Resolves a universal node locator into a session id. The "opposite" method
+ * Resolves a Universal Node Locator into a session id. The "opposite" method
* is resolveUniversalNodeLocatorBySessionId().
*
- * @param $unl Universal node locator
+ * @param $unl Universal Node Locator
* @return $sessionId Valid session id
*/
public static function resolveSessionIdByUniversalNodeLocator ($unl) {
// Get an own instance
$selfInstance = self::getSelfInstance();
- // And ask it for session id by given universal node locator
+ // And ask it for session id by given Universal Node Locator
$recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unl);
die(__METHOD__.':recipient=<pre>'.print_r($recipient, TRUE).'</pre>' . PHP_EOL);
}
/**
- * Resolves given session id into an universal node locator, if universal node locator is set, it won't be translated
+ * Resolves given session id into an Universal Node Locator, if Universal Node Locator is set, it won't be translated
*
- * @param $address Session id or universal node locator
- * @return $recipient Recipient as universal node locator
- * @throws InvalidSessionIdException If the provided session id is invalid (and no universal node locator)
+ * @param $address Session id or Universal Node Locator
+ * @return $recipient Recipient as Universal Node Locator
+ * @throws InvalidSessionIdException If the provided session id is invalid (and no Universal Node Locator)
* @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address
*/
public static function resolveSessionId ($address) {
// Get an own instance
$selfInstance = self::getSelfInstance();
- // Default is direct universal node locator
+ // Default is direct Universal Node Locator
$recipient = $address;
- // Does it match a direct universal node locator? (hint: see www.regexlib.com for the regular expression)
+ // Does it match a direct Universal Node Locator? (hint: see www.regexlib.com for the regular expression)
if (preg_match('/([a-z0-9]{3,10})\/\/:([a-z0-9\.]{5,})/', $address)) {
// @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})
- // Direct universal node locator found
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct universal node locator ' . $address . ' detected.');
+ // Direct Universal Node Locator found
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct Universal Node Locator ' . $address . ' detected.');
} elseif (isset($selfInstance->sessionIdCache[$address])) {
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.');
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
- // Resolve session id into an universal node locator
+ // Resolve session id into an Universal Node Locator
$recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
// Debug message
// Set the primary key
$dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
- // Get universal node locator and "explode" it
+ // Get Universal Node Locator and "explode" it
$unl = $nodeInstance->getUniversalNodeLocatorArray();
// Make sure both is valid
// Get node instance
$nodeInstance = NodeObjectFactory::createNodeInstance();
- // Get universal node locator and "explode" it
+ // Get Universal Node Locator and "explode" it
$unl = $nodeInstance->getUniversalNodeLocatorArray();
/*
*/
assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
- // Add universal node locator/node id as criteria
+ // Add Universal Node Locator/node id as criteria
$searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $unl[0]);
$searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $unl[1]);
$searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
-Subproject commit 584f44fab69cbffea39a99f0b169e3bdbb98b385
+Subproject commit 1613679bba663e7d92c2194fd14a047770befe2c