]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/pools/peer/class_DefaultPeerPool.php
Updated 'core'.
[hub.git] / application / hub / main / pools / peer / class_DefaultPeerPool.php
index c0bfd31861b8d0ee79324dd0627acd83edf22e38..90e76fde8207dbfc8aa8677ea609af4b916feca7 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 Hub 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
  *
@@ -94,7 +94,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
         */
        public function addPeer ($socketResource, $connectionType) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DEFAULT-PEER-POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - ENTERED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DEFAULT-PEER-POOL[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',connectionType=' . $connectionType . ' - CALLED!');
 
                // Validate the socket
                $this->validateSocket($socketResource);
@@ -220,15 +220,19 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // Default is no socket
                $socketResource = FALSE;
 
-               // Temporary resolve recipient field
-               die(__METHOD__ . ': UNFINISHED!' . PHP_EOL);
-               $unlData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+               // Resolve recipient (UNL) into a handler instance
+               $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
+
+               // Get UNL data
+               $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
 
                // Make sure it is a valid Universal Node Locator array (3 elements)
-               assert(count($unlData) == 3);
+               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+               assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+               assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[0]=' . $unlData[0] . ',unlData[1]=' . $unlData[1] . ' ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . UniversalNodeLocator::UNL_PART_ADDRESS . ']=' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ',unlData[' . UniversalNodeLocator::UNL_PART_PORT . ']=' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' ...');
 
                // Default is all sockets
                $sockets = $this->getAllSockets();
@@ -259,7 +263,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
 
                        // Get
                        // If the "peer" IP and recipient is same, use it
-                       if ($peerIp == $unlData[0]) {
+                       if ($peerIp == $unlData[UniversalNodeLocator::UNL_PART_ADDRESS]) {
                                // IPs match, so take the socket and quit this loop
                                $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];