]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 20:18:40 +0000 (21:18 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 27 Oct 2020 20:18:40 +0000 (21:18 +0100)
- renamed $unlInstance to $locatorInstance
- implemented findNodeByUniversalNodeLocator()
- WIP: started implementing looking up session id by UNL (internal or external)

Signed-off-by: Roland Häder <roland@mxchange.org>
31 files changed:
application/hub/classes/class_BaseHubSystem.php
application/hub/classes/container/class_BaseHubContainer.php
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php
application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php
application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php
application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php
application/hub/classes/factories/locator/class_UniversalNodeLocatorFactory.php
application/hub/classes/handler/class_BaseHubHandler.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/handler/protocol/class_BaseProtocolHandler.php
application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/class_BaseListenerDecorator.php
application/hub/classes/locator/class_UniversalNodeLocator.php
application/hub/classes/nodes/class_BaseHubNode.php
application/hub/classes/package/deliverable/class_PackageData.php
application/hub/classes/package/fragmenter/class_PackageFragmenter.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/classes/recipient/direct/class_DirectRecipient.php
application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/interfaces/class_HubInterface.php
application/hub/interfaces/dht/.htaccess [deleted file]
application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php
application/hub/interfaces/distributable/node/class_DistributableNode.php
application/hub/interfaces/nodes/class_Node.php
application/hub/interfaces/resolver/class_ProtocolResolver.php

index 8857121af3abbf899bb973f15f514a80619542f4..098b0bb8a42bd454d7f9f31c565a1339026db1ba 100644 (file)
@@ -426,12 +426,12 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface
        /**
         * Setter for UNL instance
         *
-        * @para        $unlInstance    An instance of a LocateableNode class
+        * @para        $locatorInstance        An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) {
                // Set new UNL data array
-               $this->universalNodeLocatorInstance = $unlInstance;
+               $this->universalNodeLocatorInstance = $locatorInstance;
        }
 
        /**
index 2a33da9dc20c30e4f92fc8f0e46a3c37ff5523f2..52b04714b129a5120f18563d1acfd36eba7eb1eb 100644 (file)
@@ -156,12 +156,12 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface {
        /**
         * Setter for UNL instance
         *
-        * @para        $unlInstance    An instance of a LocateableNode class
+        * @para        $locatorInstance        An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) {
                // Set new UNL data array
-               $this->universalNodeLocatorInstance = $unlInstance;
+               $this->universalNodeLocatorInstance = $locatorInstance;
        }
 
        /**
index aa8ab84fb7abf7739905028765482e12110591c5..bb84047b6e8a0974101b86904e84c93aad18f5eb 100644 (file)
@@ -383,10 +383,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $recipient = $this->getSocketRecipient();
 
                // Generate UNL instance for it
-               $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
+               $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
 
                // Get address part
-               $recipientAddress = $unlInstance->getUnlAddress();
+               $recipientAddress = $locatorInstance->getUnlAddress();
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientAddress=%s - EXIT!', strtoupper($this->getSocketProtocol()), $recipientAddress));
@@ -415,10 +415,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                $recipient = $this->getSocketRecipient();
 
                // Generate UNL instance for it
-               $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
+               $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
 
                // Get port part
-               $recipientPort = $unlInstance->getUnlPort();
+               $recipientPort = $locatorInstance->getUnlPort();
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: recipientPort=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($recipientPort)));
@@ -691,13 +691,13 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: unlRecipient=%s', strtoupper($this->getSocketProtocol()), $unlRecipient));
 
                // Create UNL instance from it. This will validate the connection
-               $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($unlRecipient);
+               $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($unlRecipient);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: unlAddress=%s,unlPort=%d', strtoupper($this->getSocketProtocol()), $unlInstance->getUnlAddress(), $unlInstance->getUnlPort()));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: unlAddress=%s,unlPort=%d', strtoupper($this->getSocketProtocol()), $locatorInstance->getUnlAddress(), $locatorInstance->getUnlPort()));
 
                // Try to connect to it
-               $result = socket_connect($this->getSocketResource(), $unlInstance->getUnlAddress(), $unlInstance->getUnlPort());
+               $result = socket_connect($this->getSocketResource(), $locatorInstance->getUnlAddress(), $locatorInstance->getUnlPort());
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
index bad6fb5964f0ec7053ebcb5dee2b9e8b40b1caa3..f4902aeb2aaa7a129f18da8a4d3e238e5c43aa55 100644 (file)
@@ -156,12 +156,12 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub
        /**
         * Setter for UNL instance
         *
-        * @para        $unlInstance    An instance of a LocateableNode class
+        * @para        $locatorInstance        An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) {
                // Set new UNL data array
-               $this->universalNodeLocatorInstance = $unlInstance;
+               $this->universalNodeLocatorInstance = $locatorInstance;
        }
 
        /**
index cc07f0bc5c5c4136eab3c0d264bfbbdde4d279b8..6bfa6fb15ba0b573c667f28565e00115b78f99be 100644 (file)
@@ -174,10 +174,10 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
 
                // Get Universal Node Locator and "explode" it
-               $unlInstance = $this->getNodeInstance()->determineUniversalNodeLocator();
+               $locatorInstance = $this->getNodeInstance()->determineUniversalNodeLocator();
 
                // Get external UNL
-               $externalUnl = $unlInstance->getExternalUnl();
+               $externalUnl = $locatorInstance->getExternalUnl();
 
                // Make sure both is valid
                // @TODO Bad check on UNL, better use a proper validator
@@ -219,11 +219,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Get Universal Node Locator and "explode" it
-               $unlInstance = $this->getNodeInstance()->determineUniversalNodeLocator();
+               $locatorInstance = $this->getNodeInstance()->determineUniversalNodeLocator();
 
                // Make sure the external address is set and not invalid
                // @TODO Bad check on UNL, better use a proper validator
-               $externalUnl = $unlInstance->getExternalUnl();
+               $externalUnl = $locatorInstance->getExternalUnl();
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl);
                assert($externalUnl != 'invalid');
 
index 1a9c356ff3ac084c814425965c71baaa10ec5905..3ff61b5390fcbffacc6b3e048fb5cc1770722822 100644 (file)
@@ -198,7 +198,7 @@ class PeerStateLookupDatabaseWrapper extends BaseHubDatabaseWrapper implements L
                $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_STATE     , $stateInstance->getStateName());
 
                // Try to resolve sender's session id
-               $senderData = explode(':', HubTools::resolveSessionId($packageInstance->getSenderAddress()));
+               $senderData = explode(':', HubTools::resolveSessionIdToUnl($packageInstance->getSenderAddress()));
 
                // Just make sure that 'invalid:invalid' is not being processed
                assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid') && ($senderData[2] != 'invalid'));
index 9d042119bdee5d2eb22a0c961d8d8244223c33bb..66f7ba1d676955e0af9e764666c3eaec530cab79 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Dht\Node;
 use Org\Shipsimu\Hub\Dht\BaseDht;
 use Org\Shipsimu\Hub\Dht\Distributable;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 // Import framework stuff
@@ -188,6 +189,30 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                return $nodeData;
        }
 
+       /**
+        * Finds a node locally by given UNL instance
+        *
+        * @param       $locatorInstance        An instance of a LocateableNode class
+        * @return      $nodeData       Node-data array
+        */
+       public function findNodeByUniversalNodeLocator (LocateableNode $locatorInstance) {
+               // Default is empty data array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: locatorInstance=%s - CALLED!', $locatorInstance->__toString()));
+               //* DEBUG-DIE: */ die(sprintf('[%s:%d]: locatorInstance=%s', __METHOD__, __LINE__, print_r($locatorInstance, TRUE)));
+               $nodeData = array();
+
+               // Query database
+               $resultInstance = $this->getWrapperInstance()->findNodeLocalByUnlInstance($locatorInstance);
+
+               // Make sure the result instance is valid
+               assert($resultInstance instanceof SearchableResult);
+
+               // Return node data
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData)));
+               return $nodeData;
+       }
+
        /**
         * Registers an other node with this node by given message data. The
         * following data must always be present:
index 792543efdc571b53bda85f9d1bf73602ee91fc7c..97c7f07ba1b0e778f289c5d89be657e82d829887 100644 (file)
@@ -61,8 +61,8 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove
         * "Discovers" an instance of a LocateableNode class for given Node class
         *
         * @param       $nodeInstance   An instance of a Node class
-        * @return      $unlInstance    An instance of a LocateableNode class
-        * @throws      NullPointerException    If $unlInstance is NULL
+        * @return      $locatorInstance        An instance of a LocateableNode class
+        * @throws      NullPointerException    If $locatorInstance is NULL
         */
        public function discoverUniversalNodeLocatorByNode (Node $nodeInstance) {
                /*
@@ -72,16 +72,16 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove
                $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
 
                // Then resolve the node instance into an UNL instance
-               $unlInstance = $resolverInstance->resolveUniversalNodeLocatorFromNode($nodeInstance);
+               $locatorInstance = $resolverInstance->resolveUniversalNodeLocatorFromNode($nodeInstance);
 
                // Is the instance given?
-               if (is_null($unlInstance)) {
+               if (is_null($locatorInstance)) {
                        // Throw NPE here
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } // END - if
 
                // ... and return it
-               return $unlInstance;
+               return $locatorInstance;
        }
 
        /**
index 6c2eebd3692b4604b6daa6ff8272d066a32816c7..7c19d7801ed03bfa7997529dade841ab4f5f8af3 100644 (file)
@@ -116,7 +116,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
                } elseif ($packageInstance->getRecipientUnl() == '' && $packageInstance->getRecipientId() != '') {
                        // Id is set, this might be resolved to an UNL
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Resolving recipientId=%s to UNL ...', $packageInstance->getRecipientId()));
-                       $recipientUnl = HubTools::resolveSessionId($packageInstance->getRecipientId());
+                       $recipientUnl = HubTools::resolveSessionIdToUnl($packageInstance->getRecipientId());
 
                        // And set it in package instance
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: recipientUnl=%s', $recipientUnl));
index e339ab9eb9b81d5a61ceb618a1a6534ea7e42865..ae2b769f6f1e4b4929f8008971c1e182edfd222e 100644 (file)
@@ -43,7 +43,7 @@ class UniversalNodeLocatorFactory extends ObjectFactory {
         * Returns a singleton (registry-based) LocateableNode instance
         *
         * @param       $unl                    UNL address
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        public static final function createUnlInstanceFromString ($unl) {
                // Trace message
@@ -52,37 +52,37 @@ class UniversalNodeLocatorFactory extends ObjectFactory {
                // If there is no handler?
                if (GenericRegistry::getRegistry()->instanceExists('unl_' . $unl)) {
                        // Get handler from registry
-                       $unlInstance = GenericRegistry::getRegistry()->getInstance('unl_' . $unl);
+                       $locatorInstance = GenericRegistry::getRegistry()->getInstance('unl_' . $unl);
                } else {
                        // Get the handler instance
-                       $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class');
+                       $locatorInstance = self::createObjectByConfiguredName('universal_node_locator_class');
 
                        // Parse UNL string
-                       $unlInstance->parseStringAsUnl($unl);
+                       $locatorInstance->parseStringAsUnl($unl);
 
                        // Add it to the registry
-                       GenericRegistry::getRegistry()->addInstance('unl_' . $unl, $unlInstance);
+                       GenericRegistry::getRegistry()->addInstance('unl_' . $unl, $locatorInstance);
                }
 
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: unlInstance[]=%s - EXIT!', gettype($unlInstance)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNL-FACTORY: locatorInstance[]=%s - EXIT!', gettype($locatorInstance)));
 
                // Return the instance
-               return $unlInstance;
+               return $locatorInstance;
        }
 
        /**
         * Creates a UNL instance from given array
         *
         * @param       $unlData        Array with valid UNL data
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        public static final function createUnlInstanceFromArray (array $unlData) {
                // No "caching" for now
-               $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class', array($unlData));
+               $locatorInstance = self::createObjectByConfiguredName('universal_node_locator_class', array($unlData));
 
                // Return it
-               return $unlInstance;
+               return $locatorInstance;
        }
 
 }
index e861c610d5261867187c921bfd899b40b0e53839..63a65e59c7436eac52243c0995c78339fb813d24 100644 (file)
@@ -164,12 +164,12 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte
        /**
         * Setter for UNL instance
         *
-        * @para        $unlInstance    An instance of a LocateableNode class
+        * @para        $locatorInstance        An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) {
                // Set new UNL data array
-               $this->universalNodeLocatorInstance = $unlInstance;
+               $this->universalNodeLocatorInstance = $locatorInstance;
        }
 
        /**
index 82e777adb119af3e423e223f736926ecdc6eae68..af8b8a3b39aa38cbc4f5d0a4349f33c5985d1c30 100644 (file)
@@ -12,6 +12,7 @@ use Org\Shipsimu\Hub\Factory\Discovery\Socket\SocketDiscoveryFactory;
 use Org\Shipsimu\Hub\Factory\FilterChain\Package\PackageFilterChainFactory;
 use Org\Shipsimu\Hub\Factory\Handler\Message\MessageTypeHandlerFactory;
 use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory;
+use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
 use Org\Shipsimu\Hub\Handler\BaseHubHandler;
@@ -128,7 +129,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
        /**
         * Size of the decoded data array
         */
-       const DECODED_DATA_ARRAY_SIZE = 6;
+       const DECODED_DATA_ARRAY_SIZE = 7;
 
        /**
         * Named array elements for decoded package content
@@ -1019,6 +1020,19 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                // Get the package
                $packageInstance = $this->getStackInstance()->getNamed(self::STACKER_NAME_OUTGOING);
 
+               // The UNL should be set but not recipientId
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl(%d)=%s,recipientId(%d)=%s', strlen($packageInstance->getRecipientUnl()), $packageInstance->getRecipientUnl(), strlen($packageInstance->getRecipientId()), $packageInstance->getRecipientId()));
+               if ($packageInstance->getRecipientUnl() != '' && $packageInstance->getRecipientId() == '') {
+                       // Need to resolve UNL -> session id ("recipient id"), so prepare UNL instance
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl=%s is being solved into session id ...', $packageInstance->getRecipientUnl()));
+                       $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
+
+                       // Get session id and set it back
+                       $sessionId = HubTools::resolveSessionIdByUniversalNodeLocator($locatorInstance);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: sessionId=%s found, setting ...', $sessionId));
+                       $packageInstance->setRecipientId($sessionId);
+               }
+
                try {
                        // Now try to send it
                        $this->sendOutgoingRawPackageData($packageInstance);
@@ -1374,7 +1388,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
 
                // Assert on count (should be always 6)
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: decodedArray()=%d', count($decodedArray)));
-               /* DEBUG-DIE: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
+               /* DEBUG-DIE: */ die(sprintf('[%s:%d]: decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
                if (count($decodedArray) != self::DECODED_DATA_ARRAY_SIZE) {
                        // Count of array elements not expected
                        throw new InvalidArgumentException(sprintf('decodedArray()=%d does not match expected size %d. rawPackageContent=%s',
index 9df1c07144d9c6debc81c3da6118a389bb45ef03..5349b6fcd26068c349b2deae49684328188000ea 100644 (file)
@@ -73,8 +73,8 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP
         */
        public function getAddressPart () {
                // Get UNL instance
-               $unlInstance = $this->getUniversalNodeLocatorInstance();
-               die(__METHOD__.':'.print_r($unlInstance, TRUE));
+               $locatorInstance = $this->getUniversalNodeLocatorInstance();
+               die(__METHOD__.':'.print_r($locatorInstance, TRUE));
        }
 
        /**
index 7eaf4863fdadfab9332d41a3d3a75e88998424ad..d465132167e43eeed9923e6cc8d69c13a79b04a1 100644 (file)
@@ -92,14 +92,14 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
                // If this doesn't fail, continue validating the IP:port combination
                if ($isValid === TRUE) {
                        // ... and validate IP:port, first "parse" the UNL
-                       $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
+                       $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
 
                        // Set whole UNL instance
                        // @TODO don't do this in a isValidFoo() method
-                       $this->setUniversalNodeLocatorInstance($unlInstance);
+                       $this->setUniversalNodeLocatorInstance($locatorInstance);
 
                        // Set port
-                       $this->setPort($unlInstance->getUnlPort());
+                       $this->setPort($locatorInstance->getUnlPort());
                } // END - if
 
                // Return result
index 0f8931f3fe782f32fb1c96e6854b341bf712c5cb..ed58f054e9aba8eac3a2181ec7bd7956055d2c0d 100644 (file)
@@ -70,7 +70,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
 
                // @TODO The whole resolving part should be moved out and made more configurable
                // Init recipient data
-               $unlInstance = NULL;
+               $locatorInstance = NULL;
 
                // Try to solve the recipient
                try {
@@ -78,7 +78,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                        $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
 
                        // Get UNL instance
-                       $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
+                       $locatorInstance = $handlerInstance->getUniversalNodeLocatorInstance();
 
                        // Set handler instance
                        $helperInstance->setHandlerInstance($handlerInstance);
@@ -107,7 +107,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
 
                                // Create UNL instance
                                $this->partialStub('Please rewrite this part.');
-                               //$unlInstance =;
+                               //$locatorInstance =;
                        } else {
                                // It doesn't match, we need to take care of this later
                                $helperInstance->debugInstance(sprintf(
@@ -123,7 +123,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                // Now connect to it
                if (!$helperInstance->connectToPeerBySocketRecipient()) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: helperInstance=%s,unlInstance.unlData=%s', $helperInstance->__toString(), print_r($unlInstance->getUnlData(), TRUE)));
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: helperInstance=%s,locatorInstance.unlData=%s', $helperInstance->__toString(), print_r($locatorInstance->getUnlData(), TRUE)));
 
                        // Handle socket error
                        $socketInstance->handleSocketError(__METHOD__, __LINE__);
index 03f153f7fbbfeaac5a0376f24133b5fd8d2829cb..33118d2b97bfa5bfc1fa7a60101adb1db97a1972 100644 (file)
@@ -427,13 +427,13 @@ abstract class BaseListener extends BaseHubSystem implements Visitable {
                $socketProtocol = $this->getSocketInstance()->getSocketProtocol();
 
                // Get UNL instance
-               $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
+               $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
 
                // Get protocol from it
-               $unlProtocol = $unlInstance->getUnlProtocol();
+               $unlProtocol = $locatorInstance->getUnlProtocol();
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: unlInstance.unlProtocol=%s,socketProtocol=%s', strtoupper($this->getProtocolName()), $unlProtocol, $socketProtocol));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: locatorInstance.unlProtocol=%s,socketProtocol=%s', strtoupper($this->getProtocolName()), $unlProtocol, $socketProtocol));
 
                // Is same protocol?
                $accepts = ($unlProtocol == $socketProtocol);
index 966d36e72f38566f779939d1ddcbd852ad07cad8..b0f3fc93873ad9dc0cfb66190f3985373716398b 100644 (file)
@@ -82,10 +82,10 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable
        /**
         * Setter for UNL instance
         *
-        * @param       $unlInstance    An instance of a LocateableNode class
+        * @param       $locatorInstance        An instance of a LocateableNode class
         * @return      void
         */
-       protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+       protected final function setUniversalNodeLocatorInstance (LocateableNode $locatorInstance) {
                throw new UnsupportedOperationException('This method should not be called.');
        }
 
index 98d6a43631c137352f2aac4cbba7781396197b0d..8d89393b57963d71e81674a2026813cfe3c8b8c3 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Locator\Node;
 use Org\Shipsimu\Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
 use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils;
+use Org\Shipsimu\Hub\Tools\HubTools;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Registry\Registerable;
@@ -56,17 +57,106 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
         * Creates an instance of this class
         *
         * @param       $current                An array with "raw" data from the database layer for the UNL. This parameter is optional.
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        public final static function createUniversalNodeLocator (array $current = array()) {
                // Get new instance
-               $unlInstance = new UniversalNodeLocator();
+               $locatorInstance = new UniversalNodeLocator();
 
                // Init instance
-               $unlInstance->initUniversalNodeLocator($current);
+               $locatorInstance->initUniversalNodeLocator($current);
 
                // Return the prepared instance
-               return $unlInstance;
+               return $locatorInstance;
+       }
+
+       /**
+        * Parses the given UNL by splitting it up in its components. The UNL ...
+        *
+        * protocol://address[:port]
+        *
+        * ... becomes:
+        *
+        * array(
+        *     'protocol' => 'value',
+        *     'address'  => 'value',
+        *     'extra'    => 'port'
+        * )
+        *
+        * The value for 'extra' then must be handled by the overwriting
+        * parseUniversalNodeLocator() method of the individual protocol handler as
+        * this is protocol-specific.
+        *
+        * @param       $unl    Universal Node Locator (UNL) to "parse"
+        * @throws      InvalidArgumentException        If given UNL is not valid
+        */
+       private function parseUniversalNodeLocator ($unl) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
+
+               // Make sure the UNL is valid
+               if (!NodeLocatorUtils::isValidUniversalNodeLocator($unl)) {
+                       // UNL is not valid
+                       throw new InvalidArgumentException(sprintf('unl[%s]=%s is not valid.', gettype($unl), $unl));
+               } // END - if
+
+               /*
+                * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
+                * @TODO If you know why, please fix and explain it to me.
+                */
+               $unlParts = explode('://', $unl);
+
+               // Split again the last part as: address:port
+               $unlParts[1] = explode(':', $unlParts[1]);
+
+               // Now there is an almost useable array which then can be copied to the "real" array.
+               $unlData = array(
+                       LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
+                       LocateableNode::UNL_PART_ADDRESS  => $unlParts[1][0],
+                       LocateableNode::UNL_PART_EXTRA    => $unlParts[1][1],
+               );
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
+
+               // Call init method
+               $this->initUniversalNodeLocator($unlData);
+       }
+
+       /**
+        * Initializes the UNL instance by givena array. If an entry is found, it
+        * will be copied, otherwise the entry is set empty.
+        *
+        * @param       $unlData        An array with "raw" data from the database layer for the UNL. This parameter is optional.
+        * @return      void
+        */
+       private function initUniversalNodeLocator (array $unlData = array()) {
+               // Init UNL array
+               $this->unlData = array();
+
+               // Copy all found entries
+               foreach (array(
+                       LocateableNode::UNL_PART_PROTOCOL,
+                       LocateableNode::UNL_PART_ADDRESS,
+                       LocateableNode::UNL_PART_EXTRA,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
+                       NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
+                               // Init entry
+                               $this->unlData[$key] = NULL;
+
+                               // Is the key found?
+                               if (isset($unlData[$key])) {
+                                       // Debug message
+                                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: Copying unlData[' . $key . ']=' . $unlData[$key] . ' ...');
+
+                                       // The copy the entry
+                                       $this->unlData[$key] = $unlData[$key];
+                               } // END - if
+               } // END - foreach
        }
 
        /**
@@ -190,7 +280,7 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
         */
        public function parseStringAsUnl ($unl) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
 
                // Is it basically valid?
                if (!is_string($unl)) {
@@ -200,6 +290,20 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
 
                // Parse it
                $this->parseUniversalNodeLocator($unl);
+
+               // Is it matching own internal UNL?
+               if (HubTools::determineOwnInternalAddress() == $unl) {
+                       // Yes, then set it here
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=%s matches own internal address, setting ...', $unl));
+                       $this->unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL] = $unl;
+               }
+
+               // Is it matching own external UNL?
+               if (HubTools::determineOwnExternalAddress() == $unl) {
+                       // Yes, then set it here
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=%s matches own external address, setting ...', $unl));
+                       $this->unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] = $unl;
+               }
        }
 
        /**
@@ -211,93 +315,4 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi
                return $this->unlData;
        }
 
-       /**
-        * Parses the given UNL by splitting it up in its components. The UNL ...
-        *
-        * protocol://address[:port]
-        *
-        * ... becomes:
-        *
-        * array(
-        *     'protocol' => 'value',
-        *     'address'  => 'value',
-        *     'extra'    => 'port'
-        * )
-        *
-        * The value for 'extra' then must be handled by the overwriting
-        * parseUniversalNodeLocator() method of the individual protocol handler as
-        * this is protocol-specific.
-        *
-        * @param       $unl            Universal Node Locator (UNL) to "parse"
-        * @throws      InvalidArgumentException        If given UNL is not valid
-        */
-       private function parseUniversalNodeLocator ($unl) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('UNIVERSAL-NODE-LOCATOR: unl=[%s]=%s - CALLED!', gettype($unl), $unl));
-
-               // Make sure the UNL is valid
-               if (!NodeLocatorUtils::isValidUniversalNodeLocator($unl)) {
-                       // UNL is not valid
-                       throw new InvalidArgumentException(sprintf('unl[%s]=%s is not valid.', gettype($unl), $unl));
-               } // END - if
-
-               /*
-                * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
-                * @TODO If you know why, please fix and explain it to me.
-                */
-               $unlParts = explode('://', $unl);
-
-               // Split again the last part as: address:port
-               $unlParts[1] = explode(':', $unlParts[1]);
-
-               // Now there is an almost useable array which then can be copied to the "real" array.
-               $unlData = array(
-                       LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
-                       LocateableNode::UNL_PART_ADDRESS  => $unlParts[1][0],
-                       LocateableNode::UNL_PART_EXTRA    => $unlParts[1][1],
-               );
-
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
-
-               // Call init method
-               $this->initUniversalNodeLocator($unlData);
-       }
-
-       /**
-        * Initializes the UNL instance by givena array. If an entry is found, it
-        * will be copied, otherwise the entry is set empty.
-        *
-        * @param       $unlData        An array with "raw" data from the database layer for the UNL. This parameter is optional.
-        * @return      void
-        */
-       private function initUniversalNodeLocator (array $unlData = array()) {
-               // Init UNL array
-               $this->unlData = array();
-
-               // Copy all found entries
-               foreach (array(
-                       LocateableNode::UNL_PART_PROTOCOL,
-                       LocateableNode::UNL_PART_ADDRESS,
-                       LocateableNode::UNL_PART_EXTRA,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
-                       NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
-                               // Init entry
-                               $this->unlData[$key] = NULL;
-
-                               // Is the key found?
-                               if (isset($unlData[$key])) {
-                                       // Debug message
-                                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: Copying unlData[' . $key . ']=' . $unlData[$key] . ' ...');
-
-                                       // The copy the entry
-                                       $this->unlData[$key] = $unlData[$key];
-                               } // END - if
-               } // END - foreach
-       }
-
 }
index 98f7395dd7b696cb137824c9df873441a5727892..749d15b9d014d3df27731aa88bd1bafc23e83d34 100644 (file)
@@ -242,10 +242,10 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                // Is "cache" set?
                if (!isset($GLOBALS[__METHOD__])) {
                        // Get the UNL array back
-                       $unlInstance = $this->determineUniversalNodeLocator();
+                       $locatorInstance = $this->determineUniversalNodeLocator();
 
                        // Is the instance valid?
-                       if (NULL == $unlInstance) {
+                       if (NULL == $locatorInstance) {
                                // Throw NPE
                                throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                        } // END - if
@@ -253,10 +253,10 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                        // There are 2 UNLs, internal and external.
                        if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
                                // Public "external" UNL address
-                               $GLOBALS[__METHOD__] = $unlInstance->getExternalUnl();
+                               $GLOBALS[__METHOD__] = $locatorInstance->getExternalUnl();
                        } else {
                                // Non-public "internal" UNL address
-                               $GLOBALS[__METHOD__] = $unlInstance->getInternalUnl();
+                               $GLOBALS[__METHOD__] = $locatorInstance->getInternalUnl();
                        }
                } // END - if
 
@@ -764,7 +764,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
        /**
         * Determines an instance of a LocateableNode class
         *
-        * @return      $unlInstance    An instance of a LocateableNode class for this node
+        * @return      $locatorInstance        An instance of a LocateableNode class for this node
         */
        public function determineUniversalNodeLocator () {
                // Debug message
@@ -781,7 +781,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                } // END - if
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unlInstance= ' . $GLOBALS[__METHOD__]->__toString() . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: locatorInstance= ' . $GLOBALS[__METHOD__]->__toString() . ' - EXIT!');
                return $GLOBALS[__METHOD__];
        }
 
index f93693f0a03f27c0cdc8b3874a7e9368dc7ed08a..3ea63c3ae6891ae121835d3b277f3f7da3133be3 100644 (file)
@@ -293,7 +293,7 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera
        /**
         * Setter for private key hash
         *
-        * @param       $senderPrivateKeyHash           The new private key hash
+        * @param       $senderPrivateKeyHash   The new private key hash
         * @return      void
         */
        public final function setSenderPrivateKeyHash ($senderPrivateKeyHash) {
@@ -303,7 +303,7 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera
        /**
         * Getter for private key hash
         *
-        * @return      $senderPrivateKeyHash           Current private key hash
+        * @return      $senderPrivateKeyHash   Current private key hash
         */
        public final function getSenderPrivateKeyHash () {
                return $this->senderPrivateKeyHash;
index b58159191995b031350694d41c15f93cdb059cd3..b15b126210d92d957e63a3175d4d5aabbfd1c888 100644 (file)
@@ -489,7 +489,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * to all chunks and prepends a chunk with all hashes only in it. It will
         * return the final hash for faster processing of packages.
         *
-        * @param       $packageInstance                An instance of a DeliverablePackage class array
+        * @param       $packageInstance        An instance of a DeliverablePackage class array
         * @param       $helperInstance         An instance of a ConnectionHelper class
         * @return      $finalHash                      Final hash for faster processing
         * @todo        $helperInstance is unused
@@ -498,13 +498,24 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // Is this package already fragmented?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString()));
                if (!$this->isPackageProcessed($packageInstance)) {
-                       // First get all fields as array from PackageData class, implode() doesn't work as expected here.
+                       // First put it the right way together again, implode on getAllAsArray() won't work!
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
-                       $packageData = $packageInstance->getAllAsArray();
-
-                       // Then put it the right way together again
-                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageData=%s', __METHOD__, __LINE__, print_r($packageData, TRUE)));
-                       //$rawData = sprintf(
+                       /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance->allAsArray=%s', __METHOD__, __LINE__, print_r($packageInstance->getAllAsArray(), TRUE)));
+                       $rawData = sprintf('%s%s%d%s%s%s%s%s%s%s%s%s%s',
+                               $packageInstance->getSenderAddress(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getSenderPort(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getRecipientId(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getPackageContent(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getStatus(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getContentHash(),
+                               NetworkPackageHandler::PACKAGE_DATA_SEPARATOR,
+                               $packageInstance->getSenderPrivateKeyHash()
+                       );
 
                        // Generate the final hash from the raw data (not encoded!)
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
index 0c6634b6c90bf3227679b2a3fff978db1b73c225..fd5500c4d535e925ae0dd1dc2e41efa474ab0661 100644 (file)
@@ -237,10 +237,10 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
 
                // Get UNL data
-               $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
+               $locatorInstance = $handlerInstance->getUniversalNodeLocatorInstance();
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlInstance.unl=' . $unlInstance->generateUnl() . ' ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),locatorInstance.unl=' . $locatorInstance->generateUnl() . ' ...');
 
                // Default is all sockets
                $sockets = $this->getAllSockets();
@@ -281,10 +281,10 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                        } // END - if
 
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s,peerPort=%d,unlInstance.addressPart=%s', $peerAddress, $peerPort, $unlInstance->getAddressPart()));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s,peerPort=%d,locatorInstance.addressPart=%s', $peerAddress, $peerPort, $locatorInstance->getAddressPart()));
 
                        // If the "peer" IP and recipient is same, use it
-                       if ($peerAddress == $unlInstance->getAddressPart()) {
+                       if ($peerAddress == $locatorInstance->getAddressPart()) {
                                // IPs match, so take the socket and quit this loop
                                $socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
 
index 8164e72e74c0db13dc100bf215ec6cba81b441ae..b82569b43908e2b55c6ce56e2329f4eb9f1aa622 100644 (file)
@@ -85,7 +85,7 @@ class DirectRecipient extends BaseRecipient implements Recipient {
                foreach ($recipients as $recipient) {
                        // Try to sole a single recipient
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient);
-                       $unlData = HubTools::resolveSessionId($recipient);
+                       $unlData = HubTools::resolveSessionIdToUnl($recipient);
 
                        // Add it as recipient
                        $listInstance->addEntry('unl', $unlData);
index f90fedb56b722959e76000ca959a4727c9a9245e..3c69aef0f170d1da441ccd15a9bd696b27427fc2 100644 (file)
@@ -69,7 +69,7 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv
         * instance or null if it was not found.
         *
         * @param       $nodeInstance   An instance of a Node class
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        public function resolveUniversalNodeLocatorFromNode (Node $nodeInstance) {
                // Get search instance (to lookup database result)
@@ -98,10 +98,10 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv
                assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]);
 
                // Get UNL instance and handle over all data
-               $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromArray($current);
+               $locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromArray($current);
 
                // Return resolved instance
-               return $unlInstance;
+               return $locatorInstance;
        }
 
        /**
index 0729124946d78fe16b76a93ad7f26e4f9b4034d2..fba77c3fa145b3cdbf0d77f31906a59542350949 100644 (file)
@@ -98,11 +98,12 @@ class HubTools extends BaseHubSystem {
         * Resolves a session id into an instance of a LocateableNode class. The opposite method
         * is resolveSessionIdByUniversalNodeLocator()
         *
-        * @param       $sessionId                      A valid session id
+        * @param       $sessionId      A valid session id
         * @return      $recipientUniversalNodeLocator  Recipient as Universal Node Locator
         */
        protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
                // Init variable
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                $recipientUniversalNodeLocator = 'invalid://invalid:invalid';
 
                // And ask it for Universal Node Locator by given session id
@@ -112,7 +113,7 @@ class HubTools extends BaseHubSystem {
                // Is the recipient valid?
                if (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) {
                        // Then use this
-                       $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
+                       $recipientUnl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
                } else {
                        // Get the instance, this might throw a NPE
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Creating node instance ...');
@@ -121,12 +122,13 @@ class HubTools extends BaseHubSystem {
                        // Is the session id the same?
                        if ($nodeInstance->getSessionId() == $sessionId) {
                                // Then get an instance of a LocateableNode class from it, assume TCP by default
-                               $recipientUniversalNodeLocator = self::determineOwnExternalAddress() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
+                               $recipientUnl = self::determineOwnExternalAddress() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
                        } // END - if
                }
 
                // Return result
-               return $recipientUniversalNodeLocator;
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: recipientUnl=%s - EXIT!', $recipientUnl));
+               return $recipientUnl;
        }
 
        /**
@@ -137,6 +139,7 @@ class HubTools extends BaseHubSystem {
         */
        public static function resolveNodeIdBySessionId ($sessionId) {
                // Get an own instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
                $selfInstance = self::getSelfInstance();
 
                // And ask it for session id by given Universal Node Locator
@@ -147,6 +150,7 @@ class HubTools extends BaseHubSystem {
                assert(isset($nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID]));
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: nodeId=%s - EXIT!', $nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID]));
                return $nodeData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_NODE_ID];
        }
 
@@ -154,18 +158,20 @@ class HubTools extends BaseHubSystem {
         * Resolves a Universal Node Locator into a session id. The "opposite" method
         * is resolveUniversalNodeLocatorBySessionId().
         *
-        * @param       $unlInstance    Universal Node Locator
+        * @param       $locatorInstance        An instance of a LocateableNode class
         * @return      $sessionId              Valid session id
         */
-       public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $unlInstance) {
+       public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $locatorInstance) {
                // Get an own instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: locatorInstance=%s - CALLED!', $locatorInstance->__toString()));
                $selfInstance = self::getSelfInstance();
 
                // And ask it for session id by given Universal Node Locator
-               $recipient = DhtObjectFactory::createDhtInstance('node')->findNodeByUniversalNodeLocator($unlInstance);
+               $recipient = DhtObjectFactory::createDhtInstance('node')->findNodeByUniversalNodeLocator($locatorInstance);
                die(__METHOD__.':recipient='.print_r($recipient, TRUE));
 
                // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - EXIT!', $sessionId));
                return $sessionId;
        }
 
@@ -177,7 +183,7 @@ class HubTools extends BaseHubSystem {
         * @throws      InvalidSessionIdException       If the provided session id is invalid (and no Universal Node Locator)
         * @throws      NoValidHostnameException        If the provided hostname cannot be resolved into an IP address
         */
-       public static function resolveSessionId ($address) {
+       public static function resolveSessionIdToUnl ($address) {
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
@@ -242,31 +248,31 @@ class HubTools extends BaseHubSystem {
         */
        public static function determineOwnInternalAddress () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
 
                // Is the internal_address config entry set?
                if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...');
 
                        // Not allowed to publish internal address, so use external
                        $unl = self::determineOwnExternalAddress();
                } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address') != '') {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: Getting config entry internal_address ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry internal_address ...');
 
                        // Use it as internal address
                        $unl = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address');
                } else {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: Calling self::determineInternalUniversalNodeLocator() ...');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Calling self::determineInternalUniversalNodeLocator() ...');
 
                        // Determine own internal address
                        $unl = self::determineInternalUniversalNodeLocator();
                }
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unl=' . $unl . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!');
 
                // Return it
                return $unl;
@@ -279,7 +285,7 @@ class HubTools extends BaseHubSystem {
         */
        public static function determineInternalUniversalNodeLocator () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
 
                // Is there cache? (This shortens a lot calls)
                if (!isset($GLOBALS[__METHOD__])) {
@@ -296,7 +302,7 @@ class HubTools extends BaseHubSystem {
                } // END - if
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
                return $GLOBALS[__METHOD__];
        }
 
@@ -307,7 +313,7 @@ class HubTools extends BaseHubSystem {
         */
        public static function determineExternalUniversalNodeLocator () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: CALLED!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!');
 
                // Is there cache? (This shortens a lot calls)
                if (!isset($GLOBALS[__METHOD__])) {
@@ -324,7 +330,7 @@ class HubTools extends BaseHubSystem {
                } // END - if
 
                // Return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
                return $GLOBALS[__METHOD__];
        }
 
index 0eaa9f30807be695442cda57a05d0d937ac62a5a..78356fe6f9342fb83960af914ca654c7d6deefec 100644 (file)
@@ -101,7 +101,7 @@ interface HubInterface extends FrameworkInterface {
        /**
         * Getter for UNL instance
         *
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        function getUniversalNodeLocatorInstance ();
 
diff --git a/application/hub/interfaces/dht/.htaccess b/application/hub/interfaces/dht/.htaccess
deleted file mode 100644 (file)
index 3a42882..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Deny from all
index 64db85e05c7433b482f6f81e7c5ece7d76ef60b2..975b84c488f3c0bb9e9cbcee772b5cf3290048aa 100644 (file)
@@ -35,8 +35,8 @@ interface DiscoverableUniversalNodeLocator extends Discoverable {
         * "Discovers" an instance of a LocateableNode class for given Node class
         *
         * @param       $nodeInstance   An instance of a Node class
-        * @return      $unlInstance    An instance of a LocateableNode class
-        * @throws      NullPointerException    If $unlInstance is NULL
+        * @return      $locatorInstance        An instance of a LocateableNode class
+        * @throws      NullPointerException    If $locatorInstance is NULL
         */
        function discoverUniversalNodeLocatorByNode (Node $nodeInstance);
 
index 1115a9d16b5be66461fc904c67a569869e48b19d..108ff06a799fff32f146247b0e1b578a9c0f2b83 100644 (file)
@@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Dht\Node;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Dht\Distributable;
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
@@ -39,6 +40,14 @@ interface DistributableNode extends Distributable {
         */
        function findNodeLocalBySessionId ($sessionId);
 
+       /**
+        * Finds a node locally by given UNL instance
+        *
+        * @param       $locatorInstance        An instance of a LocateableNode class
+        * @return      $nodeData       Node-data array
+        */
+       function findNodeByUniversalNodeLocator (LocateableNode $locatorInstance);
+
        /**
         * Registers an other node with this node by given message data. The
         * following data must always be present:
index 5854f0178897997a7ed5f56a34a1ea023bd0d68f..5ef756c2cf8f94812487b04c82aa6f204a534e5e 100644 (file)
@@ -124,7 +124,7 @@ interface Node extends FrameworkInterface {
        /**
         * Determines an instance of a LocateableNode class
         *
-        * @return      $unlInstance    An instance of a LocateableNode class for this node
+        * @return      $locatorInstance        An instance of a LocateableNode class for this node
         */
        function determineUniversalNodeLocator ();
 
index 0f07d2f37dbb07c3f9676663f6e9a001975a704a..e056f29dd1782c743400526f43feb07a9e4964a6 100644 (file)
@@ -34,7 +34,7 @@ interface ProtocolResolver extends HubInterface {
         * instance or null if it was not found.
         *
         * @param       $nodeInstance   An instance of a Node class
-        * @return      $unlInstance    An instance of a LocateableNode class
+        * @return      $locatorInstance        An instance of a LocateableNode class
         */
        function resolveUniversalNodeLocatorFromNode (Node $nodeInstance);