From: Roland Haeder Date: Tue, 11 Nov 2014 21:40:18 +0000 (+0100) Subject: Added more UNL (Universal Node Locator) stuff: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=44314097c8abbfef2ee703eeda601dffd22520af;p=hub.git Added more UNL (Universal Node Locator) stuff: - Added interface for protocol resolvers - Added factory for same class - Added (lifeless) TCP resolver (NodeHelper -> LocateableNode resolver) - The UNL is now a class implementation (see interface LocateableNode) Signed-off-by: Roland Haeder --- diff --git a/application/hub/config.php b/application/hub/config.php index d66d1badf..a1ec1a2ec 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -744,6 +744,12 @@ $cfg->setConfigEntry('tcp_connection_helper_class', 'TcpConnectionHelper'); // CFG: UDP-CONNECTION-HELPER-CLASS $cfg->setConfigEntry('udp_connection_helper_class', 'UdpConnectionHelper'); +// CFG: HUB-COMMUNICATION-PROTOCOL-TYPE +$cfg->setConfigEntry('hub_communication_protocol_type', 'tcp'); + +// CFG: TCP-PROTOCOL-RESOLVER-CLASS +$cfg->setConfigEntry('tcp_protocol_resolver_class', 'TcpProtocolResolver'); + // CFG: TCP-BUFFER-LENGTH $cfg->setConfigEntry('tcp_buffer_length', 1024); diff --git a/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php index 203ce429b..9885b370e 100644 --- a/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php +++ b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php @@ -22,6 +22,13 @@ * along with this program. If not, see . */ interface DiscoverableUniversalNodeLocator extends Discoverable { + /** + * "Discovers" an instance of a LocateableNode class for given NodeHelper class + * + * @param $nodeInstance An instance of a NodeHelper class + * @return $unlInstance An instance of a LocateableNode class + */ + function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance); } // [EOF] diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php index 81d4a4000..59e0760cf 100644 --- a/application/hub/interfaces/helper/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -109,16 +109,16 @@ interface NodeHelper extends Helper, AddableCriteria { function doSelfConnection (Taskable $taskInstance); /** - * Determines the Universal Node Locator + * Determines an instance of a LocateableNode class * - * @return $unl A an Universal Node Locator for this node + * @return $unlInstance An instance of a LocateableNode class for this node */ function determineUniversalNodeLocator (); /** - * "Getter for an Universal Node Locator array + * "Getter for an array of an instance of a LocateableNode class * - * @return $unlArray An array an Universal Node Locator for this node + * @return $unlArray An array of an instance of a LocateableNode class */ function getUniversalNodeLocatorArray (); diff --git a/application/hub/interfaces/locator/.htaccess b/application/hub/interfaces/locator/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/locator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/locator/class_LocateableNode.php b/application/hub/interfaces/locator/class_LocateableNode.php new file mode 100644 index 000000000..8be0226e1 --- /dev/null +++ b/application/hub/interfaces/locator/class_LocateableNode.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 . + */ +interface LocateableNode extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/resolver/.htaccess b/application/hub/interfaces/resolver/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/resolver/class_ProtocolResolver.php b/application/hub/interfaces/resolver/class_ProtocolResolver.php new file mode 100644 index 000000000..21dbecac9 --- /dev/null +++ b/application/hub/interfaces/resolver/class_ProtocolResolver.php @@ -0,0 +1,28 @@ +OS + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 . + */ +interface ProtocolResolver extends FrameworkInterface { +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php index b5c3126b4..8011b3aa6 100644 --- a/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php +++ b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php @@ -44,6 +44,24 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove // Return the prepared instance return $discoveryInstance; } + + /** + * "Discovers" an instance of a LocateableNode class for given NodeHelper class + * + * @param $nodeInstance An instance of a NodeHelper class + * @return $unlInstance An instance of a LocateableNode class + */ + public function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance) { + /* + * First get an instance from the configured hub communication protocol + * type (which is mostly TCP, so you get a TcpProtocolResolver here). + */ + $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol(); + + // Then resolve the node instance into an UNL instance + $unlInstance = $resolverInstance->resolveUniversalResourceLocatorFromNodeHelper($nodeInstance); + die(__METHOD__ . ':unlInstance=' . print_r($unlInstance, TRUE)); + } } // [EOF] diff --git a/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php index 46325e9b4..9fa8fe942 100644 --- a/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -88,6 +88,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov */ public function discoverRawRecipients (array $decodedData) { // This must be available + die(__METHOD__ . ': Unfinished' . PHP_EOL); assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); // First clear all recipients diff --git a/application/hub/main/factories/resolver/.htaccess b/application/hub/main/factories/resolver/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/factories/resolver/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/factories/resolver/class_ProtocolResolverFactory.php b/application/hub/main/factories/resolver/class_ProtocolResolverFactory.php new file mode 100644 index 000000000..92d9ea1e9 --- /dev/null +++ b/application/hub/main/factories/resolver/class_ProtocolResolverFactory.php @@ -0,0 +1,62 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class ProtocolResolverFactory extends ObjectFactory { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton (registry-based) ProtocolResolver instance + * + * @return $resolverInstance An instance of a ProtocolResolver class + */ + public static final function createResolverFromConfiguredProtocol () { + // Get the configured protocol + $protocolName = FrameworkConfiguration::getSelfInstance()->getConfigEntry('hub_communication_protocol_type'); + + // If there is no handler? + if (Registry::getRegistry()->instanceExists($protocolName . '_protocol_resolver')) { + // Get handler from registry + $resolverInstance = Registry::getRegistry()->getInstance($protocolName . '_protocol_resolver'); + } else { + // Get the handler instance + $resolverInstance = self::createObjectByConfiguredName($protocolName . '_protocol_resolver_class'); + + // Add it to the registry + Registry::getRegistry()->addInstance($protocolName . '_protocol_resolver', $resolverInstance); + } + + // Return the instance + return $resolverInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php index 6d41c9f52..87f19300f 100644 --- a/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php +++ b/application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php @@ -31,8 +31,9 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen // Call parent constructor parent::__construct(__CLASS__); - // Set listener type + // Set listener type and protocol name $this->setListenerType('peer'); + $this->setProtocolName('tcp'); } /** diff --git a/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php index 5d23f7b85..710228122 100644 --- a/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php +++ b/application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php @@ -31,8 +31,9 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl // Call parent constructor parent::__construct(__CLASS__); - // Set listener type + // Set listener type and protocol name $this->setListenerType('hub'); + $this->setProtocolName('tcp'); } /** diff --git a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php index 81548a6ba..a3c6fb12f 100644 --- a/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php +++ b/application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php @@ -31,8 +31,9 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen // Call parent constructor parent::__construct(__CLASS__); - // Set listener type + // Set listener type and protocol name $this->setListenerType('peer'); + $this->setProtocolName('udp'); } /** diff --git a/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php index 2e1760405..45ee6e2b7 100644 --- a/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php +++ b/application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php @@ -31,8 +31,9 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl // Call parent constructor parent::__construct(__CLASS__); - // Set listener type + // Set listener type and protocol name $this->setListenerType('hub'); + $this->setProtocolName('udp'); } /** diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 3e0538d17..e71a63026 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -39,7 +39,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { /** * Universal node locator of bootstrap node */ - private $bootUniversalNodeLocator = ''; + private $bootUnlInstance = ''; /** * Whether this node is anncounced (keep on FALSE!) @@ -147,10 +147,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { /** * Getter for boot IP/port combination * - * @return $bootUniversalNodeLocator The IP/port combination of the boot node + * @return $bootUnlInstance The IP/port combination of the boot node */ protected final function getBootUniversalNodeLocator () { - return $this->bootUniversalNodeLocator; + return $this->bootUnlInstance; } /** @@ -164,9 +164,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $isFound = FALSE; // Run through all configured IPs - 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); + foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) { // @TODO Unfinished die(__METHOD__ . ':' . print_r($unlArray, TRUE)); @@ -175,11 +173,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { // Found it! $isFound = TRUE; - // Remember the port number - $this->bootUniversalNodeLocator = $unl; + // Remember the UNL array + $this->bootUnlInstance = $unlArray; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unlArray->__toString() . '.'); // Stop further searching break; @@ -191,10 +189,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $isFound = TRUE; // Remember the port number - $this->bootUniversalNodeLocator = $unl; + $this->bootUnlInstance = $unlArray; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unlArray->__toString() . '.'); // Stop further searching break; @@ -686,33 +684,33 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { } /** - * Determines the Universal Node Locator + * Determines an instance of a LocateableNode class * - * @return $unl A an Universal Node Locator for this node + * @return $unlInstance An instance of a LocateableNode class for this node */ 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); + // 2) "Determine it + $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this); - // Return it - return $unl; + // 3) Return it + return $unlInstance; } /** - * "Getter" for Universal Node Locator array + * "Getter" for an array of an instance of a LocateableNode class * - * @return $unlArray An array of the Universal Node Locator for this node + * @return $unlArray An array from an instance of a LocateableNode class for this node */ public final function getUniversalNodeLocatorArray () { - // Get Universal Node Locator (UNL) - $unl = $this->determineUniversalNodeLocator(); + // Get the Universal Node Locator (UNL) instance + $unlInstance = $this->determineUniversalNodeLocator(); // @TODO Unfinished - die(__METHOD__ . ':' . print_r($unl, TRUE)); + die(__METHOD__ . ':unlInstance[' . gettype($unlInstance) . ']=' . print_r($unlInstance, TRUE)); // Return it return $unlArray; diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 280f63920..9090a8be6 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -77,6 +77,11 @@ class BasePool extends BaseHubSystem implements Visitable { * @return void */ protected final function addInstance ($group, $poolName, Visitable $visitableInstance) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: group=' . $group . ',poolName=' . $poolName . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!'); + + // Make sure the group is not 'invalid' + assert($group != 'invalid'); + // Is the pool group there? if (!$this->getPoolEntriesInstance()->isGroupSet($group)) { // Create the missing pool group diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 39ffea7c4..5c5fdbcbc 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -221,13 +221,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $socketResource = FALSE; // Temporary resolve recipient field - $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + $unlArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); // Make sure it is a valid Universal Node Locator array (3 elements) - assert(count($recipientIpArray) == 3); + assert(count($unlArray) == 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] . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlArray[0]=' . $unlArray[0] . ',unlArray[1]=' . $unlArray[1] . ' ...'); // Default is all sockets $sockets = $this->getAllSockets(); @@ -258,7 +258,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Get // If the "peer" IP and recipient is same, use it - if ($peerIp == $recipientIpArray[0]) { + if ($peerIp == $unlArray[0]) { // IPs match, so take the socket and quit this loop $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE]; diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php index e4a7d7f42..40a4efd28 100644 --- a/application/hub/main/recipient/dht/class_DhtRecipient.php +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -74,7 +74,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { foreach ($recipients as $recipient) { // These array elements must exist for this loop: // @TODO Unfinished - die(__METHOD__ . ':' . print_r($recipient, TRUE)); + die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE)); assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP])); assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT])); diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php index 014809cfe..0ed776e90 100644 --- a/application/hub/main/recipient/direct/class_DirectRecipient.php +++ b/application/hub/main/recipient/direct/class_DirectRecipient.php @@ -68,10 +68,10 @@ class DirectRecipient extends BaseRecipient implements Recipient { // Try it on all foreach ($recipients as $recipient) { // Try to sole a single recipient - $unl = HubTools::resolveSessionId($recipient); + $unlArray = HubTools::resolveSessionId($recipient); // Add it as recipient - $listInstance->addEntry('unl', $unl); + $listInstance->addEntry('unl', $unlArray); } // END - foreach } } diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php index 6693e6b65..85d29eab8 100644 --- a/application/hub/main/recipient/self/class_SelfRecipient.php +++ b/application/hub/main/recipient/self/class_SelfRecipient.php @@ -59,7 +59,7 @@ class SelfRecipient extends BaseRecipient implements Recipient { // Make sure the recipient is valid //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient); // @TODO Unfinished - die(__METHOD__ . ':' . print_r($this, TRUE)); + die(__METHOD__ . 'recipient=:' . print_r($recipient, TRUE)); assert($recipient == NetworkPackage::NETWORK_TARGET_SELF); // Determine own port diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php index d6532029a..33d45ffea 100644 --- a/application/hub/main/recipient/upper/class_UpperRecipient.php +++ b/application/hub/main/recipient/upper/class_UpperRecipient.php @@ -61,7 +61,7 @@ class UpperRecipient extends BaseRecipient implements Recipient { assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER); // Get all bootstrap nodes - foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) { + foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) { // Is maximum reached? if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) { // Debug message @@ -72,10 +72,10 @@ class UpperRecipient extends BaseRecipient implements Recipient { } // END - if // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $unl . ' as recipient.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlArray, TRUE) . ' as recipient.'); // Add the entry - $listInstance->addEntry('unl', $unl); + $listInstance->addEntry('unl', $unlArray); } // END - foreach } } diff --git a/application/hub/main/resolver/protocol/.htaccess b/application/hub/main/resolver/protocol/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/protocol/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/resolver/protocol/class_ b/application/hub/main/resolver/protocol/class_ new file mode 100644 index 000000000..8246fbca6 --- /dev/null +++ b/application/hub/main/resolver/protocol/class_ @@ -0,0 +1,62 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 . + */ +class !!!ProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of a !!! command resolver with a given default command + * + * @return $resolverInstance The prepared command resolver instance + */ + public static final function create!!!ProtocolResolver () { + // Create the new instance + $resolverInstance = new !!!ProtocolResolver(); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an command instance for a given request class or null if + * it was not found + * + * @param $nodeInstance An instance of a NodeHelper class + * @return $unlInstance An instance of a LocateableNode class + * @todo 0% done + */ + public function resolveUniversalResourceLocatorFromNodeHelper (NodeHelper $nodeInstance) { + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/resolver/protocol/class_BaseProtocolResolver.php b/application/hub/main/resolver/protocol/class_BaseProtocolResolver.php new file mode 100644 index 000000000..1a8e82524 --- /dev/null +++ b/application/hub/main/resolver/protocol/class_BaseProtocolResolver.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 . + */ +class BaseProtocolResolver extends BaseResolver { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/resolver/protocol/tcp/.htaccess b/application/hub/main/resolver/protocol/tcp/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/protocol/tcp/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php new file mode 100644 index 000000000..bc23f32a1 --- /dev/null +++ b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php @@ -0,0 +1,65 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 . + */ +class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set protocol type + $this->setProtocolName('tcp'); + } + + /** + * Creates an instance of a Tcp command resolver with a given default command + * + * @return $resolverInstance The prepared command resolver instance + */ + public static final function createTcpProtocolResolver () { + // Create the new instance + $resolverInstance = new TcpProtocolResolver(); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an command instance for a given request class or null if + * it was not found + * + * @param $nodeInstance An instance of a NodeHelper class + * @return $unlInstance An instance of a LocateableNode class + * @todo 0% done + */ + public function resolveUniversalResourceLocatorFromNodeHelper (NodeHelper $nodeInstance) { + $this->partialStub('Please implement this method.'); + } +} + +// [EOF] +?> diff --git a/application/hub/main/tags/package/class_PackageTags.php b/application/hub/main/tags/package/class_PackageTags.php index 7cfbed0ab..71934123d 100644 --- a/application/hub/main/tags/package/class_PackageTags.php +++ b/application/hub/main/tags/package/class_PackageTags.php @@ -153,7 +153,7 @@ class PackageTags extends BaseTags implements Tagable { // Now we need to verify every single tag $this->verifyAllTags(); - // Return it + // Return the last (and only) found protocol (e.g. 'tcp' is very usual) return $this->lastProtocol; } diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index c154b5532..c2c6197e5 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -86,7 +86,7 @@ class HubTools extends BaseHubSystem { } /** - * Resolves a session id into an Universal Node Locator. The opposite method + * Resolves a session id into an instance of a LocateableNode class. The opposite method * is resolveSessionIdByUniversalNodeLocator() * * @param $sessionId A valid session id @@ -94,7 +94,8 @@ class HubTools extends BaseHubSystem { */ protected function resolveUniversalNodeLocatorBySessionId ($sessionId) { // Init variable - $recipientUniversalNodeLocator = 'invalid:invalid'; + die(__METHOD__ . ': Unfinished' . PHP_EOL); + $recipientUniversalNodeLocator = 'invalid://invalid:invalid'; // And ask it for Universal Node Locator by given session id $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId); @@ -109,7 +110,7 @@ class HubTools extends BaseHubSystem { // Is the session id the same? if ($nodeInstance->getSessionId() == $sessionId) { - // Then get the Universal Node Locator from it, assume TCP by default + // Then get an instance of a LocateableNode class from it, assume TCP by default $recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port'); } // END - if } @@ -122,23 +123,23 @@ class HubTools extends BaseHubSystem { * Resolves a Universal Node Locator into a session id. The "opposite" method * is resolveUniversalNodeLocatorBySessionId(). * - * @param $unl Universal Node Locator - * @return $sessionId Valid session id + * @param $unlInstance Universal Node Locator + * @return $sessionId Valid session id */ - public static function resolveSessionIdByUniversalNodeLocator ($unl) { + public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $unlInstance) { // Get an own instance $selfInstance = self::getSelfInstance(); // And ask it for session id by given Universal Node Locator - $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unl); - die(__METHOD__.':recipient=
'.print_r($recipient, TRUE).'
' . PHP_EOL); + $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unlInstance); + die(__METHOD__.':recipient='.print_r($recipient, TRUE)); // Return result return $sessionId; } /** - * 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 instance of a LocateableNode class, 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 @@ -170,7 +171,7 @@ class HubTools extends BaseHubSystem { // 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 instance of a LocateableNode class $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address); // Debug message diff --git a/application/hub/main/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index 42c841b1d..63ef594b4 100644 --- a/application/hub/main/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -188,7 +188,7 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER])); // Just make sure that 'invalid:invalid' is not being processed - assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid')); + assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid') && ($senderData[2] != 'invalid')); // Add ip address and port $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP , $senderData[0]); diff --git a/core b/core index 1613679bb..6339d66e4 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 1613679bba663e7d92c2194fd14a047770befe2c +Subproject commit 6339d66e421f4514ec9de8f61d96e38cb34005e6