From: Roland Häder Date: Thu, 7 Feb 2013 21:36:13 +0000 (+0000) Subject: Rewrites, some more methods: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4a4fbfb80267fd344b37cef2b173f666ecb44646;p=hub.git Rewrites, some more methods: - Added missing database "table" 'node_dht' - Added methods for local node data handling - There is now no more need for separate TCP/UDP ports --- diff --git a/.gitattributes b/.gitattributes index 39f3e3323..6f8d3d4a3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -712,6 +712,7 @@ db/cruncher_projects/.htaccess svneol=native#text/plain db/cruncher_units/.htaccess svneol=native#text/plain db/news/.htaccess -text svneol=unset#text/plain db/node_data/.htaccess -text svneol=unset#text/plain +db/node_dht/.htaccess -text svneol=unset#text/plain db/node_states/.htaccess -text svneol=unset#text/plain db/peer_states/.htaccess -text svneol=unset#text/plain docs/AUTHORS.txt svneol=native#text/plain diff --git a/application/hub/config-local.php-dist b/application/hub/config-local.php-dist index 7d63bc911..2df73dfc0 100644 --- a/application/hub/config-local.php-dist +++ b/application/hub/config-local.php-dist @@ -39,11 +39,8 @@ $cfg = FrameworkConfiguration::getSelfInstance(); // CFG: NODE-LISTEN-ADDR $cfg->setConfigEntry('node_listen_addr', '0.0.0.0'); -// CFG: NODE-TCP-LISTEN-PORT -$cfg->setConfigEntry('node_tcp_listen_port', 9060); - -// CFG: NODE-UDP-LISTEN-PORT -$cfg->setConfigEntry('node_udp_listen_port', 9060); +// CFG: NODE-LISTEN-PORT +$cfg->setConfigEntry('node_listen_port', 9060); // CFG: NODE-DEFAULT-MODE (can be 'regular', 'list', 'master' or 'boot', default is 'regular') $cfg->setConfigEntry('node_default_mode', 'regular'); diff --git a/application/hub/config.php b/application/hub/config.php index 970c197d9..4063d372b 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -27,11 +27,8 @@ $cfg = FrameworkConfiguration::getSelfInstance(); // CFG: NODE-LISTEN-ADDR $cfg->setConfigEntry('node_listen_addr', '0.0.0.0'); -// CFG: NODE-TCP-LISTEN-PORT -$cfg->setConfigEntry('node_tcp_listen_port', 9060); - -// CFG: NODE-UDP-LISTEN-PORT -$cfg->setConfigEntry('node_udp_listen_port', 9060); +// CFG: NODE-LISTEN-PORT +$cfg->setConfigEntry('node_listen_port', 9060); // CFG: NODE-DEFAULT-MODE (can be 'regular', 'list', 'master' or 'boot', default is 'regular') $cfg->setConfigEntry('node_default_mode', 'regular'); diff --git a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php index 072f86ade..1d32a57f0 100644 --- a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php +++ b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php @@ -39,8 +39,7 @@ class AnnouncementNotAcceptedException extends FrameworkException { $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP], - $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT], - $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT], + $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 6363de18f..46d249cc8 100644 --- a/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php +++ b/application/hub/exceptions/announcement/class_NoAnnouncementAttemptedException.php @@ -39,8 +39,7 @@ class NoAnnouncementAttemptedException extends FrameworkException { $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP], - $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT], - $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT], + $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT], $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] ); diff --git a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php index 657fb8d56..1593f605f 100644 --- a/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php +++ b/application/hub/exceptions/node/class_NodeSessionIdVerficationException.php @@ -39,8 +39,7 @@ class NodeSessionIdVerficationException extends FrameworkException { $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP], - $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT], - $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT], + $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT], $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] ); diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php index eaaf5879c..eaf24ce94 100644 --- a/application/hub/interfaces/helper/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -111,10 +111,9 @@ interface NodeHelper extends Helper { /** * "Getter for address:port combination * - * @param $handlerInstance An instance of a Networkable class - * @return $addressPort A address:port combination for this node + * @return $addressPort A address:port combination for this node */ - function getAddressPort (Networkable $handlerInstance); + function getAddressPort (); /** * Adds hub data elements to a given dataset instance diff --git a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php index 9ef9950f5..37a5b1297 100644 --- a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php @@ -22,6 +22,28 @@ * along with this program. If not, see . */ interface NodeDhtWrapper extends DatabaseWrapper { + /** + * Checks whether the local (*this*) node is registered in the DHT by + * checking if the external ip/port is found. + * + * @return $isRegistered Whether *this* node is registered in the DHT + */ + function isLocalNodeRegistered (); + + /** + * Updates local (*this*) node data in DHT, this is but not limited to the + * session id, ip number (and/or hostname) and port number. + * + * @return void + */ + function updateLocalNode(); + + /** + * Registeres the local (*this*) node with its data in the DHT. + * + * @return void + */ + function registerLocalNode(); } // [EOF] diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index b9ea83a50..1d7bc252b 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -25,6 +25,10 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Constants for database table names const DB_TABLE_NODE_DHT = 'node_dht'; + // Constants for database column names + const DB_COLUMN_SESSION_ID = 'session_id'; + const DB_COLUMN_IP_PORT = 'ip_port'; + /** * Protected constructor * @@ -50,6 +54,52 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Return the instance return $wrapperInstance; } + + /** + * Checks whether the local (*this*) node is registered in the DHT by + * checking if the external ip/port is found. + * + * @return $isRegistered Whether *this* node is registered in the DHT + */ + public function isLocalNodeRegistered () { + // Get node instance + $nodeInstance = Registry::getRegistry()->getInstance('node'); + + // Get a dataset instance + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Add ip:port as criteria + $searchInstance->addCriteria(self::DB_COLUMN_IP_PORT, $nodeInstance->getAddressPort()); + $searchInstance->setLimit(1); + + // Query database and get a result instance back + $resultInstance = $this->doSelectByCriteria($searchInstance); + + // Is there an entry? + $isRegistered = $resultInstance->next(); + + // Return result + return $isRegistered; + } + + /** + * Updates local (*this*) node data in DHT, this is but not limited to the + * session id, ip number (and/or hostname) and port number. + * + * @return void + */ + public function updateLocalNode () { + $this->partialStub('Not implemented yet.'); + } + + /** + * Registeres the local (*this*) node with its data in the DHT. + * + * @return void + */ + public function registerLocalNode () { + $this->partialStub('Not implemented yet.'); + } } // [EOF] diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index 42366edf9..b8b70fb19 100644 --- a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -92,9 +92,6 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DATABASE-WRAPPER: ' . __FUNCTION__ . ' called with packageData()=' . count($packageData) . ' - ENTERED!'); - // Is always new peer by default - $isNewPeer = true; - // Is the package valid? if (!isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])) { // Invalid package found, please report this diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 44efb9a1b..dd6d13a1c 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -52,13 +52,20 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { } /** - * Initializes the distributable hash table (DHT) + * Initializes the distributed hash table (DHT) * * @return void * @todo Please implement this method */ public function initDht () { - $this->partialStub('Please implement this method.'); + // Is the local node registered? + if ($this->getWrapperInstance()->isLocalNodeRegistered()) { + // Then only update session id + $this->getWrapperInstance()->updateLocalNode(); + } else { + // No, so register it + $this->getWrapperInstance()->registerLocalNode(); + } } } diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 896f5b4c6..6843d14b5 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -85,7 +85,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable // The target 'self' is always the external IP address! case NetworkPackage::NETWORK_TARGET_SELF: // Determine own port - $port = $this->getConfigInstance()->getConfigEntry('node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port'); + $port = $this->getConfigInstance()->getConfigEntry('node_listen_port'); // Determine IP or 'external_ip' if set $ip = HubTools::determineOwnExternalIp(); @@ -142,9 +142,9 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable $recipient = explode(':', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); // Is the 'recipient' field same as this peer's IP? - if ((($recipient[0] == HubTools::determineOwnExternalIp()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_tcp_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) { + if ((($recipient[0] == HubTools::determineOwnExternalIp()) && ($recipient[1] == $this->getConfigInstance()->getConfigEntry('node_listen_port'))) || ($recipient[0] == $this->getConfigInstance()->getServerAddress())) { /* - * Is same as own external IP+TCP port or internal IP, don't do anything here so other + * Is same as own external IP + TCP/UDP listen port or internal IP, don't do anything here so other * classes found an empty recipient list for internal (own) handling * of the original content. */ diff --git a/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php b/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php index d8777510b..6dbe3868f 100644 --- a/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php +++ b/application/hub/main/filter/tags/answer/class_PackageAnnouncementAnswerTagFilter.php @@ -37,8 +37,7 @@ class PackageAnnouncementAnswerTagFilter extends BaseNodeFilter implements Filte XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => '', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT => 9060, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT => 9060, + 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 3593f5236..2a7b688fd 100644 --- a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php @@ -38,8 +38,7 @@ class PackageAnnouncementTagFilter extends BaseNodeFilter implements FilterableP XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '', - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT => 9060, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT => 9060 + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_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 39e792ed2..1b1b12b83 100644 --- a/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php +++ b/application/hub/main/handler/answer-status/announcement/class_AnnouncementAnswerOkayHandler.php @@ -68,7 +68,7 @@ class AnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements Ha // Lookup external session id/external IP/port $searchInstance->addCriteria('node_session_id' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]); $searchInstance->addCriteria('node_external_ip', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP]); - $searchInstance->addCriteria('node_tcp_port' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT]); + $searchInstance->addCriteria('node_listen_port', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT]); // Only one entry is fine $searchInstance->setLimit(1); diff --git a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php index 357f9e372..cc48b0481 100644 --- a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php @@ -41,8 +41,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT, ); // Init message-data->configuration translation array @@ -58,15 +57,14 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => 'internal_ip', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT => 'node_tcp_listen_port', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT => 'node_udp_listen_port' + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT ); } 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 e34b51c1c..cd2db6bd2 100644 --- a/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/main/handler/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -40,8 +40,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT, + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT, BaseXmlAnswerTemplateEngine::ANSWER_STATUS, ); @@ -60,15 +59,14 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => 'internal_ip', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status', XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT => 'node_tcp_listen_port', - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT => 'node_udp_listen_port' + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port', ); // Init array $this->searchData = array( XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, - XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT + XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT ); } diff --git a/application/hub/main/handler/message-types/class_ b/application/hub/main/handler/message-types/class_ index a3a98b6ff..98b417ed7 100644 --- a/application/hub/main/handler/message-types/class_ +++ b/application/hub/main/handler/message-types/class_ @@ -39,8 +39,7 @@ class NodeMessage???Handler extends BaseMessageHandler implements HandleableMess Xml???TemplateEngine::!!!_DATA_EXTERNAL_IP, Xml???TemplateEngine::!!!_DATA_NODE_STATUS, Xml???TemplateEngine::!!!_DATA_SESSION_ID, - Xml???TemplateEngine::!!!_DATA_TCP_PORT, - Xml???TemplateEngine::!!!_DATA_UDP_PORT + Xml???TemplateEngine::!!!_DATA_LISTEN_PORT, ); } diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 864c3d37f..8c347b407 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -59,7 +59,7 @@ abstract class BaseMessageHandler extends BaseDataHandler { * * - session-id (for finding the node's record together with below data) * - external-ip (hostname or IP number) - * - tcp-port (TCP port for inbound connections) + * - listen-port (TCP/UDP listen port for inbound connections) * * @param $messageArray An array with all minimum message data * @return void @@ -78,7 +78,7 @@ abstract class BaseMessageHandler extends BaseDataHandler { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData=' . print_r($messageData, true)); - // Search for the node's session id and external IP/hostname + TCP port + // Search for the node's session id and external IP/hostname + TCP/UDP listen port foreach ($this->searchData as $key) { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MESSAGE-HANDLER: messageData[' . $key . ']=' . $messageData[$key]); diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 96147ecb3..57857bfcd 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -147,7 +147,7 @@ class BaseRawDataHandler extends BaseHandler { */ protected function ifRecipientMatchesOwnAddress (array $packageData) { // Construct own address first - $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this); + $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort(); // Does it match? $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index ef05db54a..166cdb263 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -61,7 +61,7 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { // Now check if the IP address matches one of the bootstrap nodes if ($this->ifAddressMatchesBootstrappingNodes($this->getConfigInstance()->detectServerAddress())) { // Get our port from configuration - $ourPort = $this->getConfigInstance()->getConfigEntry('node_tcp_listen_port'); + $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port'); // Extract port $bootPort = substr($this->getBootIpPort(), -strlen($ourPort), strlen($ourPort)); diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 8f3d1864d..f5b854b27 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -573,7 +573,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * All nodes can now use the same configuration entry because it can be * customized in config-local.php. */ - $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port'); + $listenerInstance->setListenPortByConfiguration('node_listen_port'); // Initialize the listener $listenerInstance->initListener(); @@ -600,7 +600,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable { * All nodes can now use the same configuration entry because it can be * customized in config-local.php. */ - $listenerInstance->setListenPortByConfiguration('node_udp_listen_port'); + $listenerInstance->setListenPortByConfiguration('node_listen_port'); // Initialize the listener $listenerInstance->initListener(); @@ -723,15 +723,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable { /** * "Getter" for address:port combination * - * @param $handlerInstance An instance of a Networkable class - * @return $addressPort A address:port combination for this node + * @return $addressPort A address:port combination for this node */ - public final function getAddressPort (Networkable $handlerInstance) { - // Construct config entry - $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port'; - + public final function getAddressPort () { // Get IP and port - $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry); + $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port'); // Return it return $addressPort; diff --git a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php index e0fdbd70a..684e6dafc 100644 --- a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php +++ b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php @@ -31,8 +31,7 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode'; const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip'; const ANNOUNCEMENT_DATA_INTERNAL_IP = 'internal-ip'; - const ANNOUNCEMENT_DATA_TCP_PORT = 'tcp-port'; - const ANNOUNCEMENT_DATA_UDP_PORT = 'udp-port'; + const ANNOUNCEMENT_DATA_LISTEN_PORT = 'listen-port'; /** * Protected constructor @@ -49,8 +48,7 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com 'listener', self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_NODE_MODE, - self::ANNOUNCEMENT_DATA_TCP_PORT, - self::ANNOUNCEMENT_DATA_UDP_PORT, + self::ANNOUNCEMENT_DATA_LISTEN_PORT, self::ANNOUNCEMENT_DATA_SESSION_ID, self::ANNOUNCEMENT_DATA_EXTERNAL_IP, self::ANNOUNCEMENT_DATA_INTERNAL_IP, @@ -164,23 +162,13 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com } /** - * Starts the TCP port + * Starts the TCP/UDP listen port * * @return void */ - protected function startTcpPort () { + protected function startListenPort () { // Push the node name on the stacker - $this->getStackerInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_TCP_PORT); - } - - /** - * Starts the UDP port - * - * @return void - */ - protected function startUdpPort () { - // Push the node name on the stacker - $this->getStackerInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_UDP_PORT); + $this->getStackerInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_LISTEN_PORT); } /** @@ -284,21 +272,11 @@ class XmlAnnouncementTemplateEngine extends BaseXmlTemplateEngine implements Com } /** - * Finishes the UDP port - * - * @return void - */ - protected function finishUdpPort () { - // Pop the last entry - $this->getStackerInstance()->popNamed('node_announcement'); - } - - /** - * Finishes the TCP port + * Finishes the TCP/UDP listen port * * @return void */ - protected function finishTcpPort () { + protected function finishListenPort () { // Pop the last entry $this->getStackerInstance()->popNamed('node_announcement'); } diff --git a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php index 5245f5a32..17feefd45 100644 --- a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php @@ -30,8 +30,7 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status'; const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'my-external-ip'; const ANNOUNCEMENT_DATA_INTERNAL_IP = 'my-internal-ip'; - const ANNOUNCEMENT_DATA_TCP_PORT = 'my-tcp-port'; - const ANNOUNCEMENT_DATA_UDP_PORT = 'my-udp-port'; + const ANNOUNCEMENT_DATA_LISTEN_PORT = 'my-listen-port'; /** * Protected constructor @@ -50,8 +49,7 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im // Data from *this* node self::ANNOUNCEMENT_DATA_EXTERNAL_IP, self::ANNOUNCEMENT_DATA_INTERNAL_IP, - self::ANNOUNCEMENT_DATA_TCP_PORT, - self::ANNOUNCEMENT_DATA_UDP_PORT, + self::ANNOUNCEMENT_DATA_LISTEN_PORT, self::ANNOUNCEMENT_DATA_NODE_STATUS, self::ANNOUNCEMENT_DATA_SESSION_ID, // Data from other node @@ -164,19 +162,9 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im * * @return void */ - protected function startMyTcpPort () { + protected function startMyListenPort () { // Push the node name on the stacker - $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_TCP_PORT); - } - - /** - * Starts the my-udp-port - * - * @return void - */ - protected function startMyUdpPort () { - // Push the node name on the stacker - $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_UDP_PORT); + $this->getStackerInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_LISTEN_PORT); } /** @@ -219,22 +207,12 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseXmlAnswerTemplateEngine im $this->getStackerInstance()->popNamed('node_announcement_answer'); } - /** - * Finishes the my-udp-port - * - * @return void - */ - protected function finishMyUdpPort () { - // Pop the last entry - $this->getStackerInstance()->popNamed('node_announcement_answer'); - } - /** * Finishes the my-tcp-port * * @return void */ - protected function finishMyTcpPort () { + protected function finishMyListenPort () { // Pop the last entry $this->getStackerInstance()->popNamed('node_announcement_answer'); } diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index ad25728bb..e69c4f7dc 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -103,7 +103,7 @@ class HubTools extends BaseHubSystem { // Is the session id the same? if ($nodeInstance->getSessionId() == $sessionId) { // Then get the ip:port from it, assume TCP by default - $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_' . strtolower($protocol) . '_listen_port'); + $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port'); } // END - if } // END - if diff --git a/application/hub/templates/xml/announcement/announcement.xml b/application/hub/templates/xml/announcement/announcement.xml index 542e60a48..024361974 100644 --- a/application/hub/templates/xml/announcement/announcement.xml +++ b/application/hub/templates/xml/announcement/announcement.xml @@ -38,8 +38,7 @@ along with this program. If not, see {?internal_ip?} - {?node_tcp_listen_port?} - {?node_udp_listen_port?} + {?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 706869311..cf57528d6 100644 --- a/application/hub/templates/xml/answer/announcement/announcement_answer.xml +++ b/application/hub/templates/xml/answer/announcement/announcement_answer.xml @@ -36,13 +36,9 @@ along with this program. If not, see //--> {?my_internal_ip?} - {?my_tcp_port?} - - {?my_udp_port?} + {?my_listen_port?} diff --git a/db/node_dht/.htaccess b/db/node_dht/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/db/node_dht/.htaccess @@ -0,0 +1 @@ +Deny from all