From: Roland Häder Date: Thu, 17 May 2012 18:56:15 +0000 (+0000) Subject: Added 'registering of other nodes' ability, added protocol name to relevant method... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=afddd3c0816f2815c25db52f036210e98483a821;p=hub.git Added 'registering of other nodes' ability, added protocol name to relevant method signatures --- diff --git a/.gitattributes b/.gitattributes index eaca3b08a..bddcba8fc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -295,6 +295,9 @@ application/hub/main/handler/chunks/class_ChunkHandler.php svneol=native#text/pl application/hub/main/handler/class_ svneol=native#text/plain application/hub/main/handler/class_BaseHandler.php svneol=native#text/plain application/hub/main/handler/message-types/.htaccess -text svneol=unset#text/plain +application/hub/main/handler/message-types/anouncement/.htaccess -text svneol=unset#text/plain +application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php svneol=native#text/plain +application/hub/main/handler/message-types/class_BaseMessageHandler.php svneol=native#text/plain application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php svneol=native#text/plain application/hub/main/handler/network/.htaccess -text svneol=unset#text/plain application/hub/main/handler/network/class_ svneol=native#text/plain diff --git a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php index 9f55c5963..dc090eafb 100644 --- a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php +++ b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php @@ -30,6 +30,15 @@ interface HandleableMessage extends Handleable { * @return void */ function handleMessageData (array $messageData, Receivable $packageInstance); + + /** + * Adds all required elements from given array into data set instance + * + * @param $dataSetInstance An instance of a StoreableCriteria class + * @param $messageData An array with all message data + * @return void + */ + function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData); } // [EOF] diff --git a/application/hub/interfaces/helper/hub/class_HelpableHub.php b/application/hub/interfaces/helper/hub/class_HelpableHub.php index bd25a6f72..7b5747555 100644 --- a/application/hub/interfaces/helper/hub/class_HelpableHub.php +++ b/application/hub/interfaces/helper/hub/class_HelpableHub.php @@ -30,7 +30,7 @@ interface HelpableHub extends Helper { function loadDescriptorXml (); /** - * Do the helped attempt by delivering a package to ourselfs + * Send a package out * * @param $nodeInstance An instance of a NodeHelper class * @return void diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index 3e0fbf9b5..72d4ed139 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -28,9 +28,10 @@ interface Deliverable extends FrameworkInterface { * stack. * * @param $helperInstance An instance of a HelpableHub class + * @param $protocol Name of used protocol (TCP/UDP) * @return void */ - function enqueueRawDataFromTemplate (HelpableHub $helperInstance); + function enqueueRawDataFromTemplate (HelpableHub $helperInstance, $protocol); /** * Checks whether a package has been enqueued for delivery. diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 2f2ac8aa5..5f0217506 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -25,10 +25,6 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl // Table names const DB_TABLE_NODE_LIST = 'node_list'; - // Constants for column name - const DB_COLUMN_NODE_SESSION_ID = 'node_session_id'; - const DB_COLUMN_NODE_IP_PORT = 'node_ipport'; - // Other constants const INVALID_IP_PORT = 'invalid:invalid'; @@ -62,9 +58,10 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl * Resolves a session id into an ip:port combination * * @param $sessionId A valid session id + * @param $protocol Name of the protocol (TCP/UDP) * @return $recipient Recipient as ip:port combination */ - public function resolveIpPortBySessionId ($sessionId) { + public function resolveIpPortBySessionId ($sessionId, $protocol) { // Set invalid ip:port combination $recipient = self::INVALID_IP_PORT; @@ -72,7 +69,7 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for the node session id - $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, $sessionId); + $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, $sessionId); $searchInstance->setLimit(1); // Get a result back @@ -84,7 +81,22 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl $this->setResultInstance($resultInstance); // Get the node id from result and set it - $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT); + $recipientIp = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP); + + // Which protocol? + switch ($protocol) { + case 'TCP': // Transmission Control Procol has been used + $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT); + break; + + case 'UDP': // User Datagram Protocol has been used + $recipientPort = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT); + break; + + default: // Unsupported protocol detected! + $this->debugBackTrace('Unsupported protocol ' . $protocol . ' specified!'); + break; + } // END - switch } // END - if // Return result @@ -95,17 +107,38 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl * Resolves a ip:port combination into a session id * * @param $ipPort Ip:port combination + * @param $protocol Name of the used protocol (TCP/UDP) * @return $sessionId A valid session id */ - public function resolveSessionIdByIpPort ($ipPort) { + public function resolveSessionIdByIpPort ($ipPort, $protocol) { // Set invalid session id as default $sessionId = 'invalid'; + // Split ip:port + $ipPortArray = explode(':', $ipPort); + // Now get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for the node session id - $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT, $ipPort); + $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, $ipPortArray[0]); + + // Which protocol? + switch ($protocol) { + case 'TCP': // Transmission Control Procol has been used + $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, $ipPortArray[1]); + break; + + case 'UDP': // User Datagram Protocol has been used + $searchInstance->addCriteria('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT, $ipPortArray[1]); + break; + + default: // Unsupported protocol detected! + $this->debugBackTrace('Unsupported protocol ' . $protocol . ' specified!'); + break; + } // END - switch + + // Only one record $searchInstance->setLimit(1); // Get a result back @@ -117,12 +150,33 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl $this->setResultInstance($resultInstance); // Get the session from result - $sessionId = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID); + $sessionId = $this->getField('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID); } // END - if // Return result return $sessionId; } + + /** + * Registeres a node by given message data. + * + * @param $messageData An array of all message data + * @param $handlerInstance An instance of a HandleableMessage class + * @return void + */ + public function registerNodeByMessageData (array $messageData, HandleableMessage $handlerInstance) { + // Get a data set instance + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_LIST)); + + // Set primary key (session id) + $dataSetInstance->setUniqueKey('node_' . XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID); + + // Add all array elements + $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData); + + // Run the "INSERT" query + $this->queryInsertDataSet($dataSetInstance); + } } // [EOF] diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index 384c3758c..4c9f2f499 100644 --- a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -188,7 +188,7 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_STATE , $stateInstance->getStateName()); // Try to resolve sender's session id - $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER])); + $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER], $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL])); // Just make sure that 'invalid:invalid' is not being processed assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid')); diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index ec4469e49..a133e4a4d 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -105,6 +105,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc // Determine protocol name $protocolName = $this->determineProtocolByPackageData($packageData); + // Is it the same? + assert(strtoupper($protocolName) == $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]); + // Get the listener instance $listenerInstance = $this->discoverListenerInstance($protocolName, $packageData); @@ -123,7 +126,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('socketResource=' . $socketResource . ',packageData='.print_r($packageData,true)); + //* NOISY-DEBUG: */ $this->debugOutput('socketResource=' . $socketResource . ',packageData=' . print_r($packageData, true)); // Is it false, the recipient isn't known to us and we have no connection to it if (($socketResource === false) || (!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) { diff --git a/application/hub/main/handler/message-types/anouncement/.htaccess b/application/hub/main/handler/message-types/anouncement/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/handler/message-types/anouncement/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php new file mode 100644 index 000000000..0f18ea1f3 --- /dev/null +++ b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php @@ -0,0 +1,100 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable { + /** + * Array with all data XML nodes (which hold the actual data) and their values + */ + private $messageDataElements = array(); + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set handler name + $this->setHandlerName('message_type_announcement'); + + // Init message data array + $this->messageDataElements = array( + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT + ); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a HandleableMessage class + */ + public final static function createNodeMessageAnnouncementHandler () { + // Get new instance + $handlerInstance = new NodeMessageAnnouncementHandler(); + + // Return the prepared instance + return $handlerInstance; + } + + /** + * Handles data array of the message + * + * @param $messageData An array with message data to handle + * @param $packageInstance An instance of a Receivable class + * @return void + */ + public function handleMessageData (array $messageData, Receivable $packageInstance) { + // Register the announcing node with this node + $this->registerNodeByMessageData($messageData); + + // Prepare answer message to be delivered back to the other node + $this->prepareAnswerMessage($messageData, $packageInstance); + } + + /** + * Adds all required elements from given array into data set instance + * + * @param $dataSetInstance An instance of a StoreableCriteria class + * @param $messageData An array with all message data + * @return void + */ + public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) { + // Add all ements + foreach ($this->messageDataElements as $key) { + // Is it there? + assert(isset($messageData[$key])); + + // Add it + $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]); + } // END - foreach + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php new file mode 100644 index 000000000..b918dc1dd --- /dev/null +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -0,0 +1,90 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 BaseMessageHandler extends BaseHandler { + /** + * Array with search criteria elements + */ + private $searchData = array(); + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Init array + $this->searchData = array( + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT + ); + } + + /** + * Registers an other node with this node by given message data. The + * following data must always be present: + * + * - 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) + * + * @param $messageArray An array with all minimum message data + * @return void + */ + protected function registerNodeByMessageData (array $messageData) { + // Get a wrapper instance + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class'); + + // Get a search criteria class + $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); + + // Search for the node's session id and external IP/hostname + TCP port + foreach ($this->searchData as $key) { + // Add criteria + $searchInstance->addCriteria('node_' . $key, $messageData[$key]); + } // END - foreach + + // Only one entry is fine + $searchInstance->setLimit(1); + + // Run the query + $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance); + + // Is there already an entry? + if ($resultInstance->next()) { + // Entry found + $resultInstance->debugBackTrace('Entry found!'); + } else { + // Nothing found, so register it + $wrapperInstance->registerNodeByMessageData($messageData, $this); + } + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php index ef974da04..f551ef47b 100644 --- a/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php @@ -1,63 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 NodeMessageAnnouncementHandler extends BaseHandler implements HandleableMessage, Registerable { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set handler name - $this->setHandlerName('message_type_announcement'); - } - - /** - * Creates an instance of this class - * - * @return $handlerInstance An instance of a HandleableMessage class - */ - public final static function createNodeMessageAnnouncementHandler () { - // Get new instance - $handlerInstance = new NodeMessageAnnouncementHandler(); - - // Return the prepared instance - return $handlerInstance; - } - - /** - * Handles data array of the message - * - * @param $messageData An array with message data to handle - * @param $packageInstance An instance of a Receivable class - * @return void - */ - public function handleMessageData (array $messageData, Receivable $packageInstance) { - } -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 63b9c41d3..f7efa68d6 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -90,7 +90,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Try to solve the recipient try { // Resolve any session ids; 0 = IP, 1 = Port - $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 'TCP')); } catch (NoValidHostnameException $e) { // Debug message $helperInstance->debugOutput('CONNECTION: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage()); diff --git a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php index 0d598ba71..75318d80e 100644 --- a/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php @@ -97,7 +97,7 @@ class HubAnnouncementHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this); + $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); } /** diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index 1f210fba2..784528db6 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -93,7 +93,7 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this); + $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); } /** diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index a6e0e8a67..b8ad315f5 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -97,6 +97,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ const PACKAGE_DATA_SENDER = 'sender'; const PACKAGE_DATA_RECIPIENT = 'recipient'; + const PACKAGE_DATA_PROTOCOL = 'protocol'; const PACKAGE_DATA_CONTENT = 'content'; const PACKAGE_DATA_STATUS = 'status'; const PACKAGE_DATA_SIGNATURE = 'signature'; @@ -570,9 +571,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * stack. * * @param $helperInstance An instance of a HelpableHub class + * @param $protocol Name of used protocol (TCP/UDP) * @return void */ - public function enqueueRawDataFromTemplate (HelpableHub $helperInstance) { + public function enqueueRawDataFromTemplate (HelpableHub $helperInstance, $protocolName) { // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -601,6 +603,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array( self::PACKAGE_DATA_SENDER => $this->getSessionId(), self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(), + self::PACKAGE_DATA_PROTOCOL => $protocolName, self::PACKAGE_DATA_CONTENT => $content, self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW, self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($content, $this->getSessionId()) diff --git a/application/hub/main/package/fragmenter/class_PackageFragmenter.php b/application/hub/main/package/fragmenter/class_PackageFragmenter.php index 2f0add250..0a967973b 100644 --- a/application/hub/main/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/main/package/fragmenter/class_PackageFragmenter.php @@ -429,8 +429,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) { // Is this package already fragmented? if (!$this->isPackageProcessed($packageData)) { - // Remove package status, the recipient doesn't need this + // Remove package status and protocol, the recipient doesn't need this unset($packageData[NetworkPackage::PACKAGE_DATA_STATUS]); + unset($packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]); // First we need to "implode" the array $rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData); diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index b052c2a5d..8261a2886 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -147,7 +147,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $socketResource = false; // Temporary resolve recipient field - $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL])); // Make sure it is a valid ip:port array (2 elements) assert(count($recipientIpArray) == 2); diff --git a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php index 9c0b2d6fe..935ddb64f 100644 --- a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php +++ b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php @@ -26,9 +26,9 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil /** * Some XML nodes must be available for later data extraction */ - const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip'; - const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status'; const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id'; + const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status'; + const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip'; const ANNOUNCEMENT_DATA_TCP_PORT = 'tcp-port'; const ANNOUNCEMENT_DATA_UDP_PORT = 'udp-port'; diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 6bd06a9f3..95198e7a6 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -83,14 +83,15 @@ class HubTools extends BaseHubSystem { * Resolves a session id into an ip:port combination * * @param $sessionId A valid session id + * @param $protocol Name of the used protocol: TCP/UDP * @return $recipient Recipient as ip:port combination */ - protected function resolveIpPortBySessionId ($sessionId) { + protected function resolveIpPortBySessionId ($sessionId, $protocol) { // Get a wrapper instance $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class'); // And ask it for the session id - $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId); + $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId, $protocol); // Is the recipient invalid? if ($recipient == 'invalid:invalid') { @@ -100,7 +101,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_tcp_listen_port'); + $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_' . strtolower($protocol) . '_listen_port'); } // END - if } // END - if @@ -112,14 +113,15 @@ class HubTools extends BaseHubSystem { * Resolves a ip:port combination into a session id * * @param $ipPort Ip:port combination + * @param $protocol Name of used protocol (TCP/UDP) * @return $sessionId Valid session id */ - public static function resolveSessionIdByIpPort ($ipPort) { + public static function resolveSessionIdByIpPort ($ipPort, $protocol) { // Get a wrapper instance $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class'); // And ask it for the session id - $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort); + $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort, $protocol); // Return result return $sessionId; @@ -129,11 +131,12 @@ class HubTools extends BaseHubSystem { * Resolves given session id into an ip:port combination, if ip:port is set, it won't be translated * * @param $sessionId Session id or ip:port combination + * @param $protocol Name of the used protocol (TCP/UDP) * @return $recipient Recipient as ip:port combination * @throws InvalidSessionIdException If the provided session id is invalid (and no ip:port combination) * @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address */ - public static function resolveSessionId ($sessionId) { + public static function resolveSessionId ($sessionId, $protocol) { // Get an own instance $selfInstance = self::getSelfInstance(); @@ -177,7 +180,7 @@ class HubTools extends BaseHubSystem { $selfInstance->debugOutput('HUB-TOOLS: Using internal session id resolver.'); // Resolve session id into a ip:port combination - $recipient = $selfInstance->resolveIpPortBySessionId($sessionId); + $recipient = $selfInstance->resolveIpPortBySessionId($sessionId, $protocol); // Debug message $selfInstance->debugOutput('HUB-TOOLS: session id ' . $sessionId . ' resolved to ' . $recipient);