]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/protocol/class_ProtocolDiscovery.php
Updated 'core'.
[hub.git] / application / hub / main / discovery / protocol / class_ProtocolDiscovery.php
index e95a8914ec88d4f2bf5edefae0f324b66d06f524..82ac8c693256feefb5f09ec665bc420dfe8155f1 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -45,6 +45,29 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
                return $discoveryInstance;
        }
 
+       /**
+        * Determines the protoctol name
+        *
+        * @param       $packageData            Valid package data
+        * @return      $protocolInstance       An instance of a HandleableProtocol class
+        */
+       public static final function determineProtocolByPackageData (array $packageData) {
+               // First we need a tags instance
+               $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
+
+               /*
+                * We need to decide here which socket (TCP or UDP) should be used for
+                * the actual data transmission. In this process we will find out if
+                * the recipient of this package has already a known (registered) socket
+                * and if so we can re-use it. If there is no socket registered, we try
+                * to make a new connection to the given Universal Node Locator.
+                */
+               $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
+
+               // Return it
+               return $protocolInstance;
+       }
+
        /**
         * "Discovers" the protocol type from given raw package data. This is done
         * by looking at the 'recipient' field and extract the first part from it.
@@ -52,7 +75,7 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco
         * @param       $packageData    Raw package data
         * @return      $protocolType   Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
         */
-       public function discoverProtocolByPackageData (array $packageData) {
+       public static final function discoverProtocolByPackageData (array $packageData) {
                //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
 
                /*