function doSelfConnection (Taskable $taskInstance);
/**
- * "Getter for address:port combination
+ * Determines the universal node locator
*
- * @return $addressPort A address:port combination for this node
+ * @return $unl A an universal node locator for this node
*/
- function getAddressPort ();
+ function determineUniversalNodeLocator ();
/**
- * "Getter for address:port array
+ * "Getter for an universal node locator array
*
- * @return $addressPortArray An array address:port combination for this node
+ * @return $unlArray An array an universal node locator for this node
*/
- function getAddressPortArray ();
+ function getUniversalNodeLocatorArray ();
/**
* Updates/refreshes node data (e.g. state).
*/
interface Recipient extends FrameworkInterface {
/**
- * Tries to resolve given recipient into session ids or ip:port combination
+ * 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)
* 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 (TCP or UDP) to the given IP:port.
+ * to make a new connection to the given universal node locator.
*/
$protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
*
* @param $decodedData Raw raw package data array
* @return void
- * @todo Add some validation of recipient field, e.g. ip:port is found
+ * @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) {
/* 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('ip_port', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
}
}
}
}
/**
- * Returns a singleton protocol handler instance. If an instance is
- * found in registry, it will be returned, else a new instance is created
- * and stored in the same registry entry.
+ * Returns a singleton protocol handler instance from given HubHelper
+ * instance. If an instance is found in registry, it will be returned, else
+ * a new instance is created and stored in the same registry entry.
*
- * @param $messageType Protocol to create an object from
+ * @param $helperInstance An instance of a HubHelper class
* @return $handlerInstance A protocol handler instance
*/
- public static final function createProtocolHandlerInstance ($messageType) {
+ public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
+ // Get the protocol type from given helper instance
+ die(__METHOD__ . ':' . print_r($helperInstance, TRUE));
+
// Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists($messageType . '_protocol_handler')) {
+ if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
// Then use this instance
- $handlerInstance = Registry::getRegistry()->getInstance($messageType . '_protocol_handler');
+ $handlerInstance = Registry::getRegistry()->getInstance($protocolType . '_protocol_handler');
} else {
// Now prepare the tags instance
- $handlerInstance = self::createObjectByConfiguredName($messageType . '_protocol_handler_class');
+ $handlerInstance = self::createObjectByConfiguredName($protocolType . '_protocol_handler_class');
// Set the instance in registry for further use
- Registry::getRegistry()->addInstance($messageType . '_protocol_handler', $handlerInstance);
+ Registry::getRegistry()->addInstance($protocolType . '_protocol_handler', $handlerInstance);
}
// Return the instance
}
/**
- * Checks whether the 'recipient' field matches our own address:port
- * combination.
+ * Checks whether the 'recipient' field matches our own an universal node
+ * locator.
*
* @param $packageData Raw package data
* @return $matches Whether it matches
* @todo This method will be moved to a better place
*/
- protected function ifRecipientMatchesOwnAddress (array $packageData) {
+ protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
// Construct own address first
- $ownAddress = NodeObjectFactory::createNodeInstance()->getAddressPort();
+ $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
// Does it match?
$matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
}
/**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
+ * Processes raw data from given resource. This is mostly useful for UDP
+ * package handling and is implemented in the UdpListener class
*
* @param $socketArray A valid socket resource array
* @return void
<?php
/**
- * A decorator for the TcpListener to communicate to hubs
+ * A general decorator for listeners to communicate to hubs
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
$listInstance = new RecipientList();
// Add groups:
- // 1.) ip:port combinations
- $listInstance->addGroup('ip_port');
+ // 1.) universal node locators
+ $listInstance->addGroup('unl');
// 2.) Session ids
$listInstance->addGroup('session_id');
*/
public function clearList () {
// Clear both groups
- $this->clearGroups(array('ip_port', 'session_id'));
+ $this->clearGroups(array('unl', 'session_id'));
}
}
* @todo add some more special bootstrap things for this boot node
*/
public function doBootstrapping () {
+ // @TODO Unfinished
+ die(__METHOD__ . ':' . print_r($this, TRUE));
+
// Now check if the IP address matches one of the bootstrap nodes
if ($this->ifAddressMatchesBootstrapNodes($this->getConfigInstance()->detectServerAddress())) {
// Get our port from configuration
$ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
// Extract port
- $bootPort = substr($this->getBootIpPort(), -strlen($ourPort), strlen($ourPort));
+ $bootPort = substr($this->getBootUniversalNodeLocator(), -strlen($ourPort), strlen($ourPort));
// Is the port the same?
if ($bootPort == $ourPort) {
// It is the same!
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrap node ' . $this->getBootIpPort() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
// Now, does the mode match
if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
const OBJECT_LIST_SEPARATOR = ',';
/**
- * IP/port number of bootstrap node
+ * Universal node locator of bootstrap node
*/
- private $bootIpPort = '';
+ private $bootUniversalNodeLocator = '';
/**
* Whether this node is anncounced (keep on FALSE!)
$rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
// Generate a pseudo-random string
- $randomString = $rngInstance->randomString($length) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
+ $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode');
// Add UUID for even more entropy for the hasher
$randomString .= $this->getCryptoInstance()->createUuid();
/**
* Getter for boot IP/port combination
*
- * @return $bootIpPort The IP/port combination of the boot node
+ * @return $bootUniversalNodeLocator The IP/port combination of the boot node
*/
- protected final function getBootIpPort () {
- return $this->bootIpPort;
+ protected final function getBootUniversalNodeLocator () {
+ return $this->bootUniversalNodeLocator;
}
/**
$isFound = FALSE;
// Run through all configured IPs
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
- // Split it up in IP/port
- $ipPortArray = explode(':', $ipPort);
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
+ // Get back an array from the UNL
+ $unlArray = HubTools::getArrayFromUniversalNodeLocator($unl);
+ // @TODO Unfinished
+ die(__METHOD__ . ':' . print_r($unlArray, TRUE));
// Does it match?
- if ($ipPortArray[0] == $remoteAddr) {
+ if ($unlArray[0] == $remoteAddr) {
// Found it!
$isFound = TRUE;
// Remember the port number
- $this->bootIpPort = $ipPort;
+ $this->bootUniversalNodeLocator = $unl;
// Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
// Stop further searching
break;
- } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
+ } elseif ($unlArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
/*
* IP matches listen address. At this point we really don't care
* if we can really listen on that address
$isFound = TRUE;
// Remember the port number
- $this->bootIpPort = $ipPort;
+ $this->bootUniversalNodeLocator = $unl;
// Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.');
// Stop further searching
break;
}
/**
- * "Getter" for address:port combination
+ * Determines the universal node locator
*
- * @return $addressPort A address:port combination for this node
+ * @return $unl A an universal node locator for this node
*/
- public final function getAddressPort () {
+ public final function determineUniversalNodeLocator () {
// Get IP and port
- $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
+ $unl = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
// Return it
- return $addressPort;
+ return $unl;
}
/**
- * "Getter" for address:port array
+ * "Getter" for universal node locator array
*
- * @return $addressPortArray An array of a address:port combination for this node
+ * @return $unlArray An array of the universal node locator for this node
*/
- public final function getAddressPortArray () {
+ public final function getUniversalNodeLocatorArray () {
// Get IP and port
- $addressPortArray = explode(':', $this->getAddressPort());
+ // @TODO Unfinished
+ die(__METHOD__ . ':' . print_r($this, TRUE));
+ $unlArray = explode(':', $this->determineUniversalNodeLocator());
// Return it
- return $addressPortArray;
+ return $unlArray;
}
/**
// Is it the same?
//$isSignatureValid =
- exit(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray, TRUE));
+ exit(__METHOD__ . ': signature=' . $signature . chr(10) . ',decodedArray=' . print_r($decodedArray, TRUE));
}
/**
*/
public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
// Get protocol instance for recipient
- $protocolInstance = ProtocolHandlerFactory::createProtocolFromRecipientHelper($helperInstance);
+ $protocolInstance = ProtocolHandlerFactory::createProtocolHandlerFromRecipientHelper($helperInstance);
// Get the raw content ...
$content = $helperInstance->getTemplateInstance()->getRawTemplateData();
// Temporary resolve recipient field
$recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
- // Make sure it is a valid ip:port array (2 elements)
- assert(count($recipientIpArray) == 2);
+ // Make sure it is a valid universal node locator array (3 elements)
+ assert(count($recipientIpArray) == 3);
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),recipientIpArray[0]=' . $recipientIpArray[0] . ',recipientIpArray[1]=' . $recipientIpArray[1] . ' ...');
}
/**
- * Tries to resolve given recipient into session ids or ip:port combination
+ * 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 ip:port combination
+ * 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.
// Now "walk" through all elements and add them to the list
foreach ($recipients as $recipient) {
// These array elements must exist for this loop:
+ // @TODO Unfinished
+ die(__METHOD__ . ':' . print_r($recipient, TRUE));
assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP]));
assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]));
// Put ip and port both together
- $ipPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+ $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
// Add it to the list
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $ipPort . ') ...');
- $listInstance->addEntry('ip_port', $ipPort);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...');
+ $listInstance->addEntry('unl', $unl);
} // END - foreach
// Debug message
}
/**
- * Tries to resolve given recipient into session ids or ip:port combination
+ * 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)
// Try it on all
foreach ($recipients as $recipient) {
// Try to sole a single recipient
- $ipPort = HubTools::resolveSessionId($recipient);
+ $unl = HubTools::resolveSessionId($recipient);
// Add it as recipient
- $listInstance->addEntry('ip_port', $ipPort);
+ $listInstance->addEntry('unl', $unl);
} // END - foreach
}
}
}
/**
- * Tries to resolve given recipient into session ids or ip:port combination
+ * 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)
public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
// Make sure the recipient is valid
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient);
+ // @TODO Unfinished
+ die(__METHOD__ . ':' . print_r($this, TRUE));
assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
// Determine own port
// Is it not empty?
if (!empty($ip)) {
// Add it to the list
- $listInstance->addEntry('ip_port', $ip . ':' . $port);
+ $listInstance->addEntry('unl', $ip . ':' . $port);
} // END - if
}
}
}
/**
- * Tries to resolve given recipient into session ids or ip:port combination
+ * 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)
assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER);
// Get all bootstrap nodes
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
// Is maximum reached?
if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
// Debug message
} // END - if
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $ipPort . ' as recipient.');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $unl . ' as recipient.');
// Add the entry
- $listInstance->addEntry('ip_port', $ipPort);
+ $listInstance->addEntry('unl', $unl);
} // END - foreach
}
}
class ConnectionStatisticsHelper extends BaseHubSystem {
/**
* Statistics array
+ * @TODO Add more protocols to use
*/
private static $connectionStatistics = array(
// Statistics for TCP connections
}
/**
- * Resolves a session id into an ip:port combination. The opposite method
- * is resolveSessionIdByIpPort()
+ * Resolves a session id into an universal node locator. The opposite method
+ * is resolveSessionIdByUniversalNodeLocator()
*
* @param $sessionId A valid session id
- * @return $recipientIpPort Recipient as ip:port combination
+ * @return $recipientUniversalNodeLocator Recipient as universal node locator
*/
- protected function resolveIpPortBySessionId ($sessionId) {
+ protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
// Init variable
- $recipientIpPort = 'invalid:invalid';
+ $recipientUniversalNodeLocator = 'invalid:invalid';
- // And ask it for ip:port by given session id
+ // And ask it for universal node locator by given session id
$recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
// Is the recipient valid?
if ((isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP])) && (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]))) {
// Then use this
- $recipientIpPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+ $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
} else {
// Get the instance, this might throw a NPE
$nodeInstance = NodeObjectFactory::createNodeInstance();
// Is the session id the same?
if ($nodeInstance->getSessionId() == $sessionId) {
- // Then get the ip:port from it, assume TCP by default
- $recipientIpPort = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
+ // Then get the universal node locator from it, assume TCP by default
+ $recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
} // END - if
}
// Return result
- return $recipientIpPort;
+ return $recipientUniversalNodeLocator;
}
/**
- * Resolves a ip:port combination into a session id. The "opposite" method
- * is resolveIpPortBySessionId().
+ * Resolves a universal node locator into a session id. The "opposite" method
+ * is resolveUniversalNodeLocatorBySessionId().
*
- * @param $ipPort Ip:port combination
+ * @param $unl Universal node locator
* @return $sessionId Valid session id
*/
- public static function resolveSessionIdByIpPort ($ipPort) {
+ public static function resolveSessionIdByUniversalNodeLocator ($unl) {
// Get an own instance
$selfInstance = self::getSelfInstance();
- // And ask it for session id by given ip:port
- $recipient = $selfInstance->getDhtInstance()->findNodeByIpPort($ipPort);
+ // 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);
// Return result
}
/**
- * Resolves given session id into an ip:port combination, if ip:port 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 $sessionId Session id or ip:port combination
- * @return $recipient Recipient as ip:port combination
- * @throws InvalidSessionIdException If the provided session id is invalid (and no ip:port combination)
+ * @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 ($sessionId) {
+ public static function resolveSessionId ($address) {
// Get an own instance
$selfInstance = self::getSelfInstance();
- // Default is direct ip:port
- $recipient = $sessionId;
+ // Default is direct universal node locator
+ $recipient = $address;
- // Does it match a direct ip:port? (hint: see www.regexlib.com for the regular expression)
- if (preg_match('/((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})/', $sessionId)) {
- // Direct ip:port found
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct ip:port ' . $sessionId . ' detected.');
- } elseif (isset($selfInstance->sessionIdCache[$sessionId])) {
+ // 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.');
+ } elseif (isset($selfInstance->sessionIdCache[$address])) {
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.');
// Found in cache!
- $recipient = $selfInstance->sessionIdCache[$sessionId];
+ $recipient = $selfInstance->sessionIdCache[$address];
// Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $sessionId . ']=' . $recipient);
- } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}:([0-9]{3,5})/', $sessionId)) {
- // Hostname:port found
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: hostname:port ' . $sessionId . ' detected.');
-
- // Hostname:port found
- $hostnameArray = explode(':', $sessionId);
-
- /*
- * Try to resolve it and add port again
- * @TODO Please try to encapsulate this PHP call into an own class
- */
- $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1];
-
- // Is it valid?
- if ($recipient == $sessionId) {
- // Resolving hostname->IP failed!
- throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND);
- } // END - if
-
- // Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: hostname:port ' . $sessionId . ' resolved to ' . $recipient);
- } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $address . ']=' . $recipient);
+ } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $address)) {
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
- // Resolve session id into a ip:port combination
- $recipient = $selfInstance->resolveIpPortBySessionId($sessionId);
+ // Resolve session id into an universal node locator
+ $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
// Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $sessionId . ' resolved to ' . $recipient);
+ self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $address . ' resolved to ' . $recipient);
} else {
- // Invalid session id
- throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID);
+ // Invalid session id/UNL
+ throw new InvalidSessionIdException($address, self::EXCEPTION_SESSION_ID_IS_INVALID);
}
// Return it
// Set the primary key
$dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
- // Get ip:port combination and "explode" it
- $ipPort = $nodeInstance->getAddressPortArray();
+ // Get universal node locator and "explode" it
+ $unl = $nodeInstance->getUniversalNodeLocatorArray();
// Make sure both is valid
- assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
+ assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
// Get an array of all accepted object types
$objectList = $nodeInstance->getListFromAcceptedObjectTypes();
// Add public node data
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode'));
- $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP , $ipPort[0]);
- $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT , $ipPort[1]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP , $unl[0]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT , $unl[1]);
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
$dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
// Get node instance
$nodeInstance = NodeObjectFactory::createNodeInstance();
- // Get ip:port combination and "explode" it
- $ipPort = $nodeInstance->getAddressPortArray();
+ // Get universal node locator and "explode" it
+ $unl = $nodeInstance->getUniversalNodeLocatorArray();
/*
* Make sure both is not 'invalid' which means that the resolver
* didn't work.
*/
- assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
+ assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
- // Add ip:port/node id as criteria
- $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]);
- $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]);
+ // 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());
$searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$searchInstance->setLimit(1);
//-->
<object-max-spread>1</object-max-spread>
<!--
- The protocol we should use for transmission. Valid values can be
- 'tcp' or 'udp', without the quotes.
+ The protocol we should use for transmission. Valid is 'unl' without
+ the quotes.
//-->
<object-protocol>tcp</object-protocol>
<!--
<object-name>self_connect</object-name>
<object-recipient-limitation>self</object-recipient-limitation>
<object-max-spread>self</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>announcement_answer</object-name>
<object-recipient-limitation>direct</object-recipient-limitation>
<object-max-spread>1</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>request_node_list</object-name>
<object-recipient-limitation>upper</object-recipient-limitation>
<object-max-spread>1</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>request_node_list_answer</object-name>
<object-recipient-limitation>direct</object-recipient-limitation>
<object-max-spread>1</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>dht_bootstrap</object-name>
<object-recipient-limitation>all</object-recipient-limitation>
<object-max-spread>3</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>all</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>dht_bootstrap_answer</object-name>
<object-recipient-limitation>direct</object-recipient-limitation>
<object-max-spread>1</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>dht_publish_entry</object-name>
<object-recipient-limitation>all</object-recipient-limitation>
<object-max-spread>4</object-max-spread>
- <object-protocol>tcp</object-protocol>
+ <object-protocol>unl</object-protocol>
<object-recipient-type>hub</object-recipient-type>
</object-list-entry>
</object-list>
-Subproject commit fc986df5800daabbd777eae81ec44f63c7cd84f5
+Subproject commit 584f44fab69cbffea39a99f0b169e3bdbb98b385