From c0d1995cfe9a8bce7e30f3415a6bbefad49df838 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 23 Dec 2014 13:55:43 +0100 Subject: [PATCH] Continued with refacturing: - Removed no longer needed port which was only for TCP/UDP connections - Added UniversalNodeLocator class - Some parts are now "basicly finished", still there is a lot work to do - Updated 'core' to latest commit id Signed-off-by: Roland Haeder --- application/hub/config.php | 5 +- ...class_AnnouncementNotAcceptedException.php | 3 +- ...class_NoAnnouncementAttemptedException.php | 3 +- ...class_DhtBootstrapNotAcceptedException.php | 3 +- ...lass_NodeSessionIdVerficationException.php | 3 +- .../class_NodeAlreadyRegisteredException.php | 5 +- .../class_NodeDataMissingException.php | 5 +- .../helper/nodes/class_NodeHelper.php | 2 +- .../class_UniversalNodeLocatorDiscovery.php | 4 +- ...ass_PackageAnnouncementAnswerTagFilter.php | 1 - .../class_PackageAnnouncementTagFilter.php | 3 +- .../class_PackageDhtBootstrapTagFilter.php | 1 - .../class_AnnouncementAnswerOkayHandler.php | 1 - .../class_NodeMessageAnnouncementHandler.php | 5 +- ...s_NodeMessageAnnouncementAnswerHandler.php | 3 - ...s_NodeMessageDhtBootstrapAnswerHandler.php | 3 - .../class_NodeMessageDhtBootstrapHandler.php | 3 - .../hub/main/nodes/class_BaseHubNode.php | 48 +++++---- .../main/pools/peer/class_DefaultPeerPool.php | 8 +- .../main/recipient/dht/class_DhtRecipient.php | 3 +- .../direct/class_DirectRecipient.php | 4 +- .../recipient/upper/class_UpperRecipient.php | 6 +- .../tcp/class_TcpProtocolResolver.php | 36 ++++--- .../class_XmlAnnouncementTemplateEngine.php | 22 ----- ...ss_XmlAnnouncementAnswerTemplateEngine.php | 22 ----- ...ss_XmlDhtBootstrapAnswerTemplateEngine.php | 22 ----- .../class_XmlDhtBootstrapTemplateEngine.php | 22 ----- ...class_XmlDhtPublishEntryTemplateEngine.php | 22 ----- application/hub/main/tools/class_HubTools.php | 4 +- application/hub/main/unl/.htaccess | 1 + .../main/unl/class_UniversalNodeLocator.php | 98 +++++++++++++++++++ ...odeDistributedHashTableDatabaseWrapper.php | 19 ++-- .../xml/announcement/announcement.xml | 2 - .../announcement/announcement_answer.xml | 4 - .../dht_bootstrap/dht_bootstrap_answer.xml | 4 - .../xml/dht_bootstrap/dht_bootstrap.xml | 2 - .../hub/templates/xml/dht_publish/publish.xml | 2 - core | 2 +- 38 files changed, 187 insertions(+), 219 deletions(-) create mode 100644 application/hub/main/unl/.htaccess create mode 100644 application/hub/main/unl/class_UniversalNodeLocator.php diff --git a/application/hub/config.php b/application/hub/config.php index b68b51000..bb5c4e636 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -729,9 +729,12 @@ $cfg->setConfigEntry('socket_discovery_class', 'PackageSocketDiscovery'); // CFG: DHT-RECIPIENT-DISCOVERY-CLASS $cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery'); -// CFG: UNIVERSAL-NODE-LOCATOR-DISCOVERY-CLASS +// CFG: UNL-DISCOVERY-CLASS $cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery'); +// CFG: UNIVERSAL-NODE-LOCATOR-CLASS +$cfg->setConfigEntry('universal_node_locator_class', 'UniversalNodeLocator'); + // CFG: RECIPIENT-LIST-CLASS $cfg->setConfigEntry('recipient_list_class', 'RecipientList'); diff --git a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php index 8ec66001e..3004802cd 100644 --- a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php +++ b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php @@ -32,14 +32,13 @@ class AnnouncementNotAcceptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s', + $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,unl=%s/%s,status=%s,mode=%s', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], - $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE] ); diff --git a/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php b/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php index 9f96fdd81..a95310060 100644 --- a/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php +++ b/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php @@ -32,14 +32,13 @@ class NoAnnouncementAttemptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,ip=%s/%s,listen port=%s,status=%s.', + $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,unl=%s/%s,status=%s.', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], - $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] ); diff --git a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php index b8f196af3..e2637e3ae 100644 --- a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php +++ b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php @@ -32,14 +32,13 @@ class DhtBootstrapNotAcceptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s', + $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,unl=%s/%s,status=%s,mode=%s', $messageArray[0]->__toString(), $this->getLine(), $messageArray[0]->getNodeInstance()->__toString(), $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID], $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS], $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS], - $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT], $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS], $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE] ); diff --git a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php index 93640c0e7..1acf2b29e 100644 --- a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php +++ b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php @@ -33,13 +33,12 @@ class NodeSessionIdVerficationException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] Session id %s cannot be verfied. ip=%s/%s,listen port=%s,status=%s.', + $message = sprintf('[%s:%d] Session id %s cannot be verfied. unl=%s/%s,status=%s.', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS], - $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] ); diff --git a/application/hub/exceptions/wrapper/class_NodeAlreadyRegisteredException.php b/application/hub/exceptions/wrapper/class_NodeAlreadyRegisteredException.php index 887cfd69c..318782cb7 100644 --- a/application/hub/exceptions/wrapper/class_NodeAlreadyRegisteredException.php +++ b/application/hub/exceptions/wrapper/class_NodeAlreadyRegisteredException.php @@ -31,12 +31,11 @@ class NodeAlreadyRegisteredException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] Node already registered: session-id=%s, external-address=%s, listen-port=%s', + $message = sprintf('[%s:%d] Node already registered: session-id=%s, external-address=%s', $messageArray[0]->__toString(), $this->getLine(), $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID], - $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS], - $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT], + $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] ); // Call parent exception constructor diff --git a/application/hub/exceptions/wrapper/class_NodeDataMissingException.php b/application/hub/exceptions/wrapper/class_NodeDataMissingException.php index 4187ba2e6..c2de8a4be 100644 --- a/application/hub/exceptions/wrapper/class_NodeDataMissingException.php +++ b/application/hub/exceptions/wrapper/class_NodeDataMissingException.php @@ -31,12 +31,11 @@ class NodeDataMissingException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] Node not registered/missing: session-id=%s, external-address=%s, listen-port=%s', + $message = sprintf('[%s:%d] Node not registered/missing: session-id=%s, external-address=%s', $messageArray[0]->__toString(), $this->getLine(), $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID], - $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS], - $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT], + $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] ); // Call parent exception constructor diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php index 59e0760cf..31354fa47 100644 --- a/application/hub/interfaces/helper/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -118,7 +118,7 @@ interface NodeHelper extends Helper, AddableCriteria { /** * "Getter for an array of an instance of a LocateableNode class * - * @return $unlArray An array of an instance of a LocateableNode class + * @return $unlData An array of an instance of a LocateableNode class */ function getUniversalNodeLocatorArray (); diff --git a/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php index b3e0ee1b1..551e4a177 100644 --- a/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php +++ b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php @@ -60,7 +60,9 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove // Then resolve the node instance into an UNL instance $unlInstance = $resolverInstance->resolveUniversalNodeLocatorFromNodeHelper($nodeInstance); - die(__METHOD__ . ':unlInstance=' . print_r($unlInstance, TRUE)); + + // ... and return it + return $unlInstance; } /** diff --git a/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php b/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php index 290fba128..b355d51f0 100644 --- a/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php +++ b/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php @@ -37,7 +37,6 @@ class PackageAnnouncementAnswerTagFilter extends BaseNodeFilter implements Filte XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 9060, BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '', ); } diff --git a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php index 5dac03418..e075372e4 100644 --- a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php @@ -37,8 +37,7 @@ class PackageAnnouncementTagFilter extends BaseNodeFilter implements FilterableP XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '', - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '', - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 9060, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '' ); } diff --git a/application/hub/main/filter/tags/class_PackageDhtBootstrapTagFilter.php b/application/hub/main/filter/tags/class_PackageDhtBootstrapTagFilter.php index 151137d30..0a878f730 100644 --- a/application/hub/main/filter/tags/class_PackageDhtBootstrapTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageDhtBootstrapTagFilter.php @@ -38,7 +38,6 @@ class PackageDhtBootstrapTagFilter extends BaseNodeFilter implements FilterableP XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => '', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE => '', XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '', - XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 9060, ); } diff --git a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php index 53775e3ae..e3e06646f 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -35,7 +35,6 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha $this->searchData = array( XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT ); // Set handler name diff --git a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php index dc83f404a..3c20cb41f 100644 --- a/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -41,7 +41,6 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT, ); // Init message-data->configuration translation array @@ -57,13 +56,11 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS ); } diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index 02cafcdf6..3e97cfb93 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -40,7 +40,6 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, ); @@ -59,14 +58,12 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT ); } diff --git a/application/hub/main/handler/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php b/application/hub/main/handler/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php index d981b685f..4de6abb59 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php @@ -40,7 +40,6 @@ class NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS, XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS, XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, ); @@ -59,14 +58,12 @@ class NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address', XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status', XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT ); } diff --git a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index ee5ce6334..c793a6fb0 100644 --- a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -41,7 +41,6 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS, XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE, XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID, - XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT, ); // Init message-data->configuration translation array @@ -57,13 +56,11 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address', XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status', XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id', - XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, - XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT ); } diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index dc3eb68cd..ea4fb11d2 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -153,7 +153,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { */ private function generateExternalUnl () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Is there cache? (This shortens a lot calls) if (!isset($GLOBALS[__METHOD__])) { @@ -166,7 +166,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { } // END - if // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); return $GLOBALS[__METHOD__]; } @@ -213,10 +213,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { // Run through all configured IPs foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) { - // @TODO Unfinished - die(__METHOD__ . ':' . print_r($this, TRUE)); - die(__METHOD__ . ': unl=' . $unl . ',remoteAddr=' . $remoteAddr); - // Does it match? if ($unl == $remoteAddr) { // Found it! @@ -226,7 +222,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl->__toString() . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.'); // Stop further searching break; @@ -241,7 +237,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl->__toString() . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.'); // Stop further searching break; @@ -258,11 +254,23 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { * @return $unl Node's own universal node locator */ public function detectOwnUniversalNodeLocator () { - // Get the UNL array back - $unlArray = $this->getUniversalNodeLocatorArray(); + // Is "cache" set? + if (!isset($GLOBALS[__METHOD__])) { + // Get the UNL array back + $unlData = $this->getUniversalNodeLocatorArray(); + + // There are 2 UNLs, internal and external. + if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') { + // Public "external" UNL address + $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]; + } else { + // Non-public "internal" UNL address + $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL]; + } + } // END - if - // @TODO - die(__METHOD__ . ':unlArray=' . print_r($unlArray, TRUE)); + // Return it + return $GLOBALS[__METHOD__]; } /** @@ -756,7 +764,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { */ public function determineUniversalNodeLocator () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Determine UNL based on this node: // 1) Get discovery class @@ -766,28 +774,28 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this); // 3) Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!'); return $unlInstance; } /** * "Getter" for an array of an instance of a LocateableNode class * - * @return $unlArray An array from an instance of a LocateableNode class for this node + * @return $unlData An array from an instance of a LocateableNode class for this node */ public final function getUniversalNodeLocatorArray () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Get the Universal Node Locator (UNL) instance $unlInstance = $this->determineUniversalNodeLocator(); - // @TODO Unfinished - die(__METHOD__ . ':unlInstance[' . gettype($unlInstance) . ']=' . print_r($unlInstance, TRUE)); + // ... and the array from it + $unlData = $unlInstance->getUnlData(); // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); - return $unlArray; + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + return $unlData; } /** diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 22069fcb6..c0bfd3186 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -222,13 +222,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Temporary resolve recipient field die(__METHOD__ . ': UNFINISHED!' . PHP_EOL); - $unlArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + $unlData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); // Make sure it is a valid Universal Node Locator array (3 elements) - assert(count($unlArray) == 3); + assert(count($unlData) == 3); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlArray[0]=' . $unlArray[0] . ',unlArray[1]=' . $unlArray[1] . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[0]=' . $unlData[0] . ',unlData[1]=' . $unlData[1] . ' ...'); // Default is all sockets $sockets = $this->getAllSockets(); @@ -259,7 +259,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Get // If the "peer" IP and recipient is same, use it - if ($peerIp == $unlArray[0]) { + if ($peerIp == $unlData[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 c6bfea603..3ccba6b66 100644 --- a/application/hub/main/recipient/dht/class_DhtRecipient.php +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -76,10 +76,9 @@ class DhtRecipient extends BaseRecipient implements Recipient { // @TODO Unfinished die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE)); assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])); - assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT])); // Put ip and port both together - $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]; + $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]; // Add it to the list //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...'); diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php index 0ed776e90..c93110cbe 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 - $unlArray = HubTools::resolveSessionId($recipient); + $unlData = HubTools::resolveSessionId($recipient); // Add it as recipient - $listInstance->addEntry('unl', $unlArray); + $listInstance->addEntry('unl', $unlData); } // END - foreach } } diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php index 33d45ffea..d76fc7a25 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 $unlArray) { + foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) { // 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 ' . print_r($unlArray, TRUE) . ' as recipient.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.'); // Add the entry - $listInstance->addEntry('unl', $unlArray); + $listInstance->addEntry('unl', $unlData); } // END - foreach } } diff --git a/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php index 8a3aae4bf..32f86bad3 100644 --- a/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php +++ b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php @@ -57,24 +57,32 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv * @todo 0% done */ public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) { - // Get result instance - $resultInstance = $nodeInstance->getResultInstance(); + // Get search instance (to lookup database result) + $searchInstance = $nodeInstance->getSearchInstance(); - // Make sure the result instance is valid - assert($resultInstance instanceof SearchableResult); + // Make sure the in stance is valid + assert($searchInstance instanceof SearchCriteria); - // Rewind iterator - $resultInstance->rewind(); + // Refetch and rewind iterator + $resultInstance = $nodeInstance->getWrapperInstance()->doSelectByCriteria($searchInstance); - // Lookup node's id - while ($resultInstance->next()) { - // Get current entry - $current = $resultInstance->current(); + // Is the result valid? + if ((!$resultInstance->valid()) || (! $resultInstance->next())) { + // Node not found in database, this could mean that your database file is damaged. + return NULL; + } // END - if - // Do we have found an entry? - // $nodeInstance->getNodeId() - die(print_r($current, TRUE)); - } // END - while + // Get current entry + $current = $resultInstance->current(); + + // This should always be the case, if not your database file might be damaged. + assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]); + + // Get UNL instance and handle over all data + $unlInstance = ObjectFactory::createObjectByConfiguredName('universal_node_locator_class', array($current)); + + // Return resolved instance + return $unlInstance; } /** diff --git a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php index e5701d43a..0da0cc86b 100644 --- a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php +++ b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php @@ -31,7 +31,6 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode'; const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address'; const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address'; - const ANNOUNCEMENT_DATA_LISTEN_PORT = 'listen-port'; /** * Protected constructor @@ -48,7 +47,6 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com 'listener', self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_NODE_MODE, - self::ANNOUNCEMENT_DATA_LISTEN_PORT, self::ANNOUNCEMENT_DATA_SESSION_ID, self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, @@ -161,16 +159,6 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->pushNamed('node_announcement', 'listener'); } - /** - * Starts the TCP/UDP listen port - * - * @return void - */ - protected function startListenPort () { - // Push the node name on the stacker - $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_LISTEN_PORT); - } - /** * Starts the session id * @@ -271,16 +259,6 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->popNamed('node_announcement'); } - /** - * Finishes the TCP/UDP listen port - * - * @return void - */ - protected function finishListenPort () { - // Pop the last entry - $this->getStackInstance()->popNamed('node_announcement'); - } - /** * Finishes the listener * diff --git a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php index 17a3bda18..f70a05f55 100644 --- a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php @@ -30,7 +30,6 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status'; const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address'; const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address'; - const ANNOUNCEMENT_DATA_LISTEN_PORT = 'my-listen-port'; /** * Protected constructor @@ -49,7 +48,6 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im // Data from *this* node self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, - self::ANNOUNCEMENT_DATA_LISTEN_PORT, self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_SESSION_ID, // Data from other node @@ -157,16 +155,6 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS); } - /** - * Starts the my-tcp-port - * - * @return void - */ - protected function startMyListenPort () { - // Push the node name on the stacker - $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_LISTEN_PORT); - } - /** * Starts the my-session-id * @@ -207,16 +195,6 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->popNamed('node_announcement_answer'); } - /** - * Finishes the my-tcp-port - * - * @return void - */ - protected function finishMyListenPort () { - // Pop the last entry - $this->getStackInstance()->popNamed('node_announcement_answer'); - } - /** * Finishes the my-internal-address * diff --git a/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php b/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php index f5e26d7a3..b9a94872b 100644 --- a/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/dht/class_XmlDhtBootstrapAnswerTemplateEngine.php @@ -30,7 +30,6 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status'; const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address'; const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address'; - const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'my-listen-port'; const DHT_BOOTSTRAP_DATA_NODE_LIST = 'dht-nodes-list'; /** @@ -50,7 +49,6 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im // Data from *this* node self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS, - self::DHT_BOOTSTRAP_DATA_LISTEN_PORT, self::DHT_BOOTSTRAP_DATA_NODE_STATUS, self::DHT_BOOTSTRAP_DATA_SESSION_ID, // Data from other node @@ -160,16 +158,6 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS); } - /** - * Starts the my-tcp-port - * - * @return void - */ - protected function startMyListenPort () { - // Push the node name on the stacker - $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT); - } - /** * Starts the my-session-id * @@ -230,16 +218,6 @@ class XmlDhtBootstrapAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackInstance()->popNamed('node_dht_bootstrap_answer'); } - /** - * Finishes the my-tcp-port - * - * @return void - */ - protected function finishMyListenPort () { - // Pop the last entry - $this->getStackInstance()->popNamed('node_dht_bootstrap_answer'); - } - /** * Finishes the my-internal-address * diff --git a/application/hub/main/template/dht/class_XmlDhtBootstrapTemplateEngine.php b/application/hub/main/template/dht/class_XmlDhtBootstrapTemplateEngine.php index 47e08cec0..9b95cc37c 100644 --- a/application/hub/main/template/dht/class_XmlDhtBootstrapTemplateEngine.php +++ b/application/hub/main/template/dht/class_XmlDhtBootstrapTemplateEngine.php @@ -32,7 +32,6 @@ class XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements Com const DHT_BOOTSTRAP_DATA_NODE_MODE = 'node-mode'; const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'external-address'; const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address'; - const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'listen-port'; /** * Protected constructor @@ -49,7 +48,6 @@ class XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements Com 'listener', self::DHT_BOOTSTRAP_DATA_NODE_STATUS, self::DHT_BOOTSTRAP_DATA_NODE_MODE, - self::DHT_BOOTSTRAP_DATA_LISTEN_PORT, self::DHT_BOOTSTRAP_DATA_SESSION_ID, self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS, self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS @@ -161,16 +159,6 @@ class XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->pushNamed('dht_bootstrap', 'listener'); } - /** - * Starts the TCP/UDP listen port - * - * @return void - */ - protected function startListenPort () { - // Push the node name on the stacker - $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT); - } - /** * Starts the public ip * @@ -231,16 +219,6 @@ class XmlDhtBootstrapTemplateEngine extends BaseXmlTemplateEngine implements Com $this->getStackInstance()->popNamed('dht_bootstrap'); } - /** - * Finishes the TCP/UDP listen port - * - * @return void - */ - protected function finishListenPort () { - // Pop the last entry - $this->getStackInstance()->popNamed('dht_bootstrap'); - } - /** * Finishes the listener * diff --git a/application/hub/main/template/publish/class_XmlDhtPublishEntryTemplateEngine.php b/application/hub/main/template/publish/class_XmlDhtPublishEntryTemplateEngine.php index 9cbd20c4e..0360090ad 100644 --- a/application/hub/main/template/publish/class_XmlDhtPublishEntryTemplateEngine.php +++ b/application/hub/main/template/publish/class_XmlDhtPublishEntryTemplateEngine.php @@ -31,7 +31,6 @@ class XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements const PUBLISH_DATA_NODE_STATUS = 'node-status'; const PUBLISH_DATA_NODE_MODE = 'node-mode'; const PUBLISH_DATA_EXTERNAL_ADDRESS = 'external-address'; - const PUBLISH_DATA_LISTEN_PORT = 'listen-port'; const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash'; const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types'; @@ -50,7 +49,6 @@ class XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements 'listener', self::PUBLISH_DATA_NODE_STATUS, self::PUBLISH_DATA_NODE_MODE, - self::PUBLISH_DATA_LISTEN_PORT, self::PUBLISH_DATA_PRIVATE_KEY_HASH, self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES, self::PUBLISH_DATA_NODE_ID, @@ -165,16 +163,6 @@ class XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements $this->getStackInstance()->pushNamed('dht_publish', 'listener'); } - /** - * Starts the TCP/UDP listen port - * - * @return void - */ - protected function startListenPort () { - // Push the node name on the stacker - $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_LISTEN_PORT); - } - /** * Starts accepted object types * @@ -295,16 +283,6 @@ class XmlDhtPublishEntryTemplateEngine extends BaseXmlTemplateEngine implements $this->getStackInstance()->popNamed('dht_publish'); } - /** - * Finishes the TCP/UDP listen port - * - * @return void - */ - protected function finishListenPort () { - // Pop the last entry - $this->getStackInstance()->popNamed('dht_publish'); - } - /** * Finishes hash from private key * diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index d550b64a0..1784578d4 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -101,9 +101,9 @@ class HubTools extends BaseHubSystem { $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId); // Is the recipient valid? - if ((isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) && (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]))) { + if (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) { // Then use this - $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]; + $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]; } else { // Get the instance, this might throw a NPE $nodeInstance = NodeObjectFactory::createNodeInstance(); diff --git a/application/hub/main/unl/.htaccess b/application/hub/main/unl/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/unl/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/unl/class_UniversalNodeLocator.php b/application/hub/main/unl/class_UniversalNodeLocator.php new file mode 100644 index 000000000..7f857a0e8 --- /dev/null +++ b/application/hub/main/unl/class_UniversalNodeLocator.php @@ -0,0 +1,98 @@ + + * @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 UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode { + /** + * UNL data array + */ + private $unlData = array(); + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional. + * @return $unlInstance An instance of a LocateableNode class + */ + public final static function createUniversalNodeLocator (array $current = array()) { + // Get new instance + $unlInstance = new UniversalNodeLocator(); + + // Init instance + $unlInstance->initUniversalNodeLocator($current); + + // Return the prepared instance + return $unlInstance; + } + + /** + * Initializes the UNL instance by givena array. If an entry is found, it + * will be copied, otherwise the entry is set empty. + * + * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional. + * @return void + */ + private function initUniversalNodeLocator (array $current = array()) { + // Init UNL array + $this->unlData = array(); + + // Copy all found entries + foreach (array( + NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, + NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, + NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, + NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, + NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, + NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) { + // Init entry + $this->unlData[$key] = NULL; + + // Is the key found? + if (isset($current[$key])) { + // The copy the entry + $this->unlData[$key] = $current[$key]; + } // END - if + } // END - foreach + } + + /** + * Getter for UNL data array + * + * @return $unlData An array with UNL data + */ + public final function getUnlData () { + return $this->unlData; + } +} + +// [EOF] +?> diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 218e5163b..87d4232ea 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -34,7 +34,6 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem const DB_COLUMN_NODE_ID = 'node_id'; const DB_COLUMN_SESSION_ID = 'session_id'; const DB_COLUMN_EXTERNAL_ADDRESS = 'external_address'; - const DB_COLUMN_LISTEN_PORT = 'listen_port'; const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash'; const DB_COLUMN_NODE_MODE = 'node_mode'; const DB_COLUMN_ACCEPTED_OBJECTS = 'accepted_object_types'; @@ -87,7 +86,6 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem self::DB_COLUMN_NODE_ID, self::DB_COLUMN_SESSION_ID, self::DB_COLUMN_EXTERNAL_ADDRESS, - self::DB_COLUMN_LISTEN_PORT, self::DB_COLUMN_PRIVATE_KEY_HASH, self::DB_COLUMN_NODE_MODE, self::DB_COLUMN_ACCEPTED_OBJECTS, @@ -149,7 +147,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID); // Get Universal Node Locator and "explode" it - $unl = $nodeInstance->getUniversalNodeLocatorArray(); + $unlInstance = $nodeInstance->determineUniversalNodeLocator(); // Make sure both is valid assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid')); @@ -162,8 +160,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Add public node data $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode')); - $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS , $unl[0]); - $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT , $unl[1]); + $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]); $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()); @@ -191,19 +188,18 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $nodeInstance = NodeObjectFactory::createNodeInstance(); // Get Universal Node Locator and "explode" it - $unl = $nodeInstance->getUniversalNodeLocatorArray(); + $unlData = $nodeInstance->getUniversalNodeLocatorArray(); /* * Make sure both is not 'invalid' which means that the resolver * didn't work. */ - assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid')); + die(__METHOD__ . ':unlData[' . gettype($unlData) . ']=' . print_r($unlData, TRUE) . PHP_EOL); // Add Universal Node Locator/node id as criteria $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $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->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); + $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); $searchInstance->setLimit(1); // Query database and get a result instance back @@ -380,8 +376,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Only look for these array elements ("keys") array( self::DB_COLUMN_NODE_ID => TRUE, - self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE, - self::DB_COLUMN_LISTEN_PORT => TRUE, + self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE ) ); diff --git a/application/hub/templates/xml/announcement/announcement.xml b/application/hub/templates/xml/announcement/announcement.xml index 32b33e555..b8c1dcb32 100644 --- a/application/hub/templates/xml/announcement/announcement.xml +++ b/application/hub/templates/xml/announcement/announcement.xml @@ -37,8 +37,6 @@ along with this program. If not, see {?external_address?} {?internal_address?} - - {?node_listen_port?} diff --git a/application/hub/templates/xml/answer/announcement/announcement_answer.xml b/application/hub/templates/xml/answer/announcement/announcement_answer.xml index 456403fd4..ce2e18eee 100644 --- a/application/hub/templates/xml/answer/announcement/announcement_answer.xml +++ b/application/hub/templates/xml/answer/announcement/announcement_answer.xml @@ -36,10 +36,6 @@ along with this program. If not, see //--> {?my_internal_address?} - {?my_listen_port?} - {?my_session_id?} diff --git a/application/hub/templates/xml/answer/dht_bootstrap/dht_bootstrap_answer.xml b/application/hub/templates/xml/answer/dht_bootstrap/dht_bootstrap_answer.xml index 6b5f57024..d30993ad7 100644 --- a/application/hub/templates/xml/answer/dht_bootstrap/dht_bootstrap_answer.xml +++ b/application/hub/templates/xml/answer/dht_bootstrap/dht_bootstrap_answer.xml @@ -37,10 +37,6 @@ along with this program. If not, see //--> {?my_internal_address?} - {?my_listen_port?} - {?my_session_id?} diff --git a/application/hub/templates/xml/dht_bootstrap/dht_bootstrap.xml b/application/hub/templates/xml/dht_bootstrap/dht_bootstrap.xml index 06f9eab67..ba0a81ea1 100644 --- a/application/hub/templates/xml/dht_bootstrap/dht_bootstrap.xml +++ b/application/hub/templates/xml/dht_bootstrap/dht_bootstrap.xml @@ -46,8 +46,6 @@ along with this program. If not, see {?external_address?} {?internal_address?} - - {?node_listen_port?} diff --git a/application/hub/templates/xml/dht_publish/publish.xml b/application/hub/templates/xml/dht_publish/publish.xml index c6b8604ab..156f0d249 100644 --- a/application/hub/templates/xml/dht_publish/publish.xml +++ b/application/hub/templates/xml/dht_publish/publish.xml @@ -63,8 +63,6 @@ Array {?external_address?} - - {?listen_port?} diff --git a/core b/core index eea9aadff..7bb55d2b9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit eea9aadff7619b2a5c25972f37b34a1b83d30891 +Subproject commit 7bb55d2b90d5a32710bc0bb220cff5720194a6eb -- 2.39.5