From: Roland Häder Date: Thu, 16 Feb 2012 21:55:50 +0000 (+0000) Subject: Development on 'hub' continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e586e6b83e93be2d686afdf2224f2aff174ca5a6;p=hub.git Development on 'hub' continued: - Implemented IP check in DefaultPeerPool for selecting the right socket for given raw package data array - Variable naming fixed (opps) - TODOs.txt updated --- diff --git a/application/hub/main/handler/chunks/class_ChunkHandler.php b/application/hub/main/handler/chunks/class_ChunkHandler.php index 456f1ea08..ea5865ab8 100644 --- a/application/hub/main/handler/chunks/class_ChunkHandler.php +++ b/application/hub/main/handler/chunks/class_ChunkHandler.php @@ -77,7 +77,7 @@ class ChunkHandler extends BaseHandler implements Registerable { } // END - if // Add all chunks to the FIFO stacker - foreach ($chunk as $chunk) { + foreach ($chunks as $chunk) { // Add the chunk $this->getStackerInstance()->pushNamed(self::STACKER_NAME_CHUNKS_WITH_FINAL_EOP, $chunk); } // END - foreach diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 3e469aecc..c9a901a86 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -146,22 +146,43 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Default is no socket $socketResource = false; + // Temporary resolve recipient field + $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + + // Make sure it is a valid ip:port array (2 elements) + assert(count($recipientIpArray) == 2); + // Debug message - /* DEBUG: */ $this->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s) ...'); + /* NOISY-DEBUG: */ $this->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s), recipientIpArray[0]=' . $recipientIpArray[0] . ' ...'); // Get all sockets and check them, skip the server socket foreach ($this->getAllSockets() as $socket) { // Is this a server socket? if ($socket === $this->getListenerInstance()->getSocketResource()) { // Skip 'server' sockets (local socket) + /* NOISY-DEBUG: */ $this->debugOutput('POOL: Skipping local socket ' . $socket . ' ...'); continue; } // END - if - // @TODO Check for IP - $this->debugBackTrace('[' . __METHOD__ . ':' . __LINE__ . ']: '.print_r($packageData, true)); + // Try to get the "peer"'s name + if (!@socket_getpeername($socket, $peerIp)) { + // Handle the socket error with given package data + $this->handleSocketError($socket, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + } // END - if + + // If the "peer" IP and recipient is same, use it + if ($peerIp == $recipientIpArray[0]) { + // IPs match, so take the socket and quit this loop + $socketResource = $socket; + + // Debug message + /* NOISY-DEBUG: */ $this->debugOutput('POOL: peerIp=' . $peerIp . ' matches with recipient IP address. Taking socket=' . $socket); + break; + } // END - if } // END - foreach // Return the determined socket resource + /* NOISY-DEBUG: */ $this->debugOutput('POOL: socketResource[' . gettype($socketResource) . ']=' . $socketResource); return $socketResource; } } diff --git a/docs/TODOs.txt b/docs/TODOs.txt index ae4c6baea..ad5c9aab9 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -6,7 +6,7 @@ ./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:38: * @todo We may want to implement a filter for ease notification of other objects like our pool ./application/hub/interfaces/helper/messages/class_MessageHelper.php:10: * @todo Please find another name for this interface ./application/hub/interfaces/nodes/class_NodeHelper.php:10: * @todo We need to find a better name for this interface -./application/hub/main/class_BaseHubSystem.php:300: // @TODO On some systems it is 134, on some 107? +./application/hub/main/class_BaseHubSystem.php:323: // @TODO On some systems it is 134, on some 107? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:107: * @todo Should we add some more filters? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:58: * @todo Try to create a ChatActivationTask or so ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:107: * @todo Should we add some more filters? @@ -102,7 +102,6 @@ ./application/hub/main/package/class_NetworkPackage.php:716: // @TODO Add some content here ./application/hub/main/package/class_NetworkPackage.php:766: * @todo This may be enchanced for outgoing packages? ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:427: * @todo $helperInstance is unused -./application/hub/main/pools/peer/class_DefaultPeerPool.php:160: // @TODO Check for IP ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106: // @TODO Do something with it ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:62: * @todo Find something for init phase of this key producer ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:72: * @todo ~30% done