]> git.mxchange.org Git - hub.git/commitdiff
Development on 'hub' continued:
authorRoland Häder <roland@mxchange.org>
Thu, 16 Feb 2012 21:55:50 +0000 (21:55 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 16 Feb 2012 21:55:50 +0000 (21:55 +0000)
- Implemented IP check in DefaultPeerPool for selecting the right socket for
  given raw package data array
- Variable naming fixed (opps)
- TODOs.txt updated

application/hub/main/handler/chunks/class_ChunkHandler.php
application/hub/main/pools/peer/class_DefaultPeerPool.php
docs/TODOs.txt

index 456f1ea08e34ab906a5c1f47c11ad0fe5e696614..ea5865ab8f7ab972f0635a3aa87b4cfdb83c6e54 100644 (file)
@@ -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
index 3e469aecc2b8bef117895fedc8bee27521566dbd..c9a901a86e66bcf6704bc8ec5479249fdc628050 100644 (file)
@@ -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;
        }
 }
index ae4c6baead1387bd65b97e05a2362cf2b504a82f..ad5c9aab9ee26839908b045b311174f4b9d471a5 100644 (file)
@@ -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?
 ./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