]> git.mxchange.org Git - hub.git/commitdiff
Added 'registering of other nodes' ability, added protocol name to relevant method...
authorRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 18:56:15 +0000 (18:56 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 17 May 2012 18:56:15 +0000 (18:56 +0000)
19 files changed:
.gitattributes
application/hub/interfaces/handler/message-types/class_HandleableMessage.php
application/hub/interfaces/helper/hub/class_HelpableHub.php
application/hub/interfaces/package/class_Deliverable.php
application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php
application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
application/hub/main/handler/message-types/anouncement/.htaccess [new file with mode: 0644]
application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php [new file with mode: 0644]
application/hub/main/handler/message-types/class_BaseMessageHandler.php [new file with mode: 0644]
application/hub/main/handler/message-types/class_NodeMessageAnnouncementHandler.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/helper/hub/announcement/class_HubAnnouncementHelper.php
application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/package/fragmenter/class_PackageFragmenter.php
application/hub/main/pools/peer/class_DefaultPeerPool.php
application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php
application/hub/main/tools/class_HubTools.php

index eaca3b08a25a70b392d1ab472c7548f411033abe..bddcba8fcfe207ed885374ff1a01f38bcda9bf2d 100644 (file)
@@ -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
index 9f55c5963f2312172eac4190c81e18ec88699284..dc090eafbb22c72c2b6e80e32bf393f7d274608c 100644 (file)
@@ -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]
index bd25a6f720fd39e390a79a4e2f7206d1daf1979c..7b5747555197d46a7b7608caa2f1ae09266d68f8 100644 (file)
@@ -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
index 3e0fbf9b5ed1b073febc3ac69c61544959664e73..72d4ed139eaaf6a7fe0d8314f446822b973326a6 100644 (file)
@@ -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.
index 2f2ac8aa545edd1a066d342808f0a916c2cd9f80..5f02175068dd72ed10656c3b2ef7820e36cfb215 100644 (file)
@@ -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]
index 384c3758c22e97a484711d86f9c747c134629ed1..4c9f2f4990ab6a22d45c03cce8c0852888d83aff 100644 (file)
@@ -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'));
index ec4469e49043cc2e0d92b544439d5b2dfee02755..a133e4a4d3343b30e42b5804b4163cf892973473 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..0f18ea1
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * A NodeMessageAnnouncement handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..b918dc1
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * A general message handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index ef974da04f59d09885d86b3188f9af93ef571013..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,63 +1,3 @@
 <?php
-/**
- * A NodeMessageAnnouncement handler
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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
 ?>
index 63b9c41d3e758a1e4f3af11cbe1edefe0dfcf41f..f7efa68d6e81d1680ad3925fb556ed11e329f2f9 100644 (file)
@@ -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());
index 0d598ba71a08646da5658bde02b3929a42379997..75318d80e33344a7048e0edcc7b9e15311b2ba32 100644 (file)
@@ -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');
        }
 
        /**
index 1f210fba22f5d2ff26e7189ba5e34929d6f3bcb8..784528db68c823c0097742e946ded0ed059e8d69 100644 (file)
@@ -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');
        }
 
        /**
index a6e0e8a67267b4a8e352638118843621b5b159d9..b8ad315f506ee4a79dbad8f525a71b72300587ec 100644 (file)
@@ -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())
index 2f0add250e1bd070ff6e4cf64d9a765b4783d79b..0a967973b569537aaf37e18aec814b96ef78476f 100644 (file)
@@ -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);
index b052c2a5d34070265cc460a76d2cf7ff1aea2856..8261a28863ed0883d7bdb408ca6a525b52bc020c 100644 (file)
@@ -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);
index 9c0b2d6fe90ffb05159d266dce4db6d0a7d4e1a7..935ddb64ff4a029c508f437211c000c3823bfc5a 100644 (file)
@@ -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';
 
index 6bd06a9f38f5370db2174565376a2482064a46f3..95198e7a6aac5c1ef0effe67628cc183fb9247e6 100644 (file)
@@ -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);