]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 13:23:10 +0000 (14:23 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 26 Oct 2020 13:23:43 +0000 (14:23 +0100)
- implemented PackageData::getAllAsArray() with PHP's reflection classes
- added more debug code
- fixed various bugs
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
46 files changed:
application/hub/classes/container/socket/class_SocketContainer.php
application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php
application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/classes/decoder/package/class_PackageDecoder.php
application/hub/classes/dht/class_BaseDht.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php
application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php
application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php
application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php
application/hub/classes/factories/package/data/class_PackageDataFactory.php
application/hub/classes/factories/socket/class_SocketFactory.php
application/hub/classes/factories/states/peer/class_PeerStateFactory.php
application/hub/classes/handler/data/class_BaseDataHandler.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php
application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php
application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/listener/socket/class_SocketFileListener.php
application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php
application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php
application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php
application/hub/classes/listener/udp/class_UdpListener.php
application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php
application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.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/dht/class_DhtRecipient.php
application/hub/classes/recipient/direct/class_DirectRecipient.php
application/hub/classes/recipient/self/class_SelfRecipient.php
application/hub/classes/recipient/upper/class_UpperRecipient.php
application/hub/classes/registry/socket/class_SocketRegistry.php
application/hub/classes/resolver/state/peer/class_PeerStateResolver.php
application/hub/classes/tags/package/class_PackageTags.php
application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php
application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php
application/hub/exceptions/unl/class_InvalidUnlException.php
application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php
application/hub/interfaces/recipient/class_Recipient.php
core

index fed990f13928a0a6cea6ec072251c59d81441b4e..bad9de06911fc8922a481fd68d3b1f1dfc369f1e 100644 (file)
@@ -12,7 +12,7 @@ use Org\Shipsimu\Hub\Information\ShareableInfo;
 use Org\Shipsimu\Hub\Listener\BaseListener;
 use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
-use Org\Shipsimu\Hub\Network\Package\NetworkPackageHandler;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
@@ -119,14 +119,14 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         */
        public static final function createSocketContainer ($socketResource, $socketProtocol, DeliverablePackage $packageInstance) {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource[%s]=%s,socketProtocol=%s,packageInstance[]=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol, gettype($packageInstance)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketResource[%s]=%s,socketProtocol=%s,packageInstance[]=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol, gettype($packageInstance)));
                //* DEBUG-PRINT: */ printf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE));
 
                // Get a new instance
                $socketInstance = new SocketContainer();
 
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol));
 
                // Set protocol
                $socketInstance->setSocketProtocol($socketProtocol);
@@ -161,7 +161,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
         * @return      $packageDataInstance    An instance of a DeliverablePackage class
         */
        public function getPackageDataInstance () {
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Getting packageDataInstance=%s', strtoupper($this->getSocketProtocol()), $this->packageDataInstance));
                return $this->packageDataInstance;
        }
 
@@ -893,8 +892,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita
                // Valid?
                if ($result === TRUE) {
                        // Set both
-                       $this->getPackageDataInstance()->setAddress($peerAddress);
-                       $this->getPackageDataInstance()->setPort($peerPort);
+                       $this->setPeerAddress($peerAddress);
+                       $this->setPeerPort($peerPort);
                } // END - if
 
                // Trace message
index 752efd55b32b870b67422b6d62acaf65ddb89b69..ba1a180d76379f985ff89e4a0fe5112124030a79 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\Dht;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Node\BaseHubNode;
 
@@ -122,10 +121,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
         * @return      $searchInstance         An instance of a SearchCriteria class
         */
        private function prepareSearchInstance (array $nodeData) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
-
                // Assert on array elements
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
                assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
 
                // Get instance
@@ -135,10 +132,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
                $searchInstance->setLimit(1);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!');
-
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!');
                return $searchInstance;
        }
 
@@ -160,7 +155,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
         */
        private function prepareLocalDataSetInstance () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
 
                // Get node/request instances
                $nodeInstance = NodeObjectFactory::createNodeInstance();
@@ -180,27 +175,29 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
 
                // Make sure both is valid
                // @TODO Bad check on UNL, better use a proper validator
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl);
                assert($externalUnl !== 'invalid');
 
                // Get an array of all accepted object types
                $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
 
                // Make sure this is an array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: objectList()=' . count($objectList));
                assert(is_array($objectList));
 
                // Add public node data
                $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE       , $requestInstance->getRequestElement('mode'));
                $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $externalUnl);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeInstance->nodeId=' . $nodeInstance->getNodeId());
                $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID         , $nodeInstance->getNodeId());
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeInstance->sessionId=' . $nodeInstance->getSessionId());
                $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID      , $nodeInstance->getSessionId());
                $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getNodePrivateKeyHash());
                $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
                $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap()));
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!');
-
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: dataSetInstance=' . $dataSetInstance->__toString() . ' - EXIT!');
                return $dataSetInstance;
        }
 
@@ -211,10 +208,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
         * @return      $isRegistered   Whether *this* node is registered in the DHT
         */
        public function isLocalNodeRegistered () {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
-
                // Get a search criteria instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Get node instance
@@ -226,6 +221,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                // Make sure the external address is set and not invalid
                // @TODO Bad check on UNL, better use a proper validator
                $externalUnl = $unlInstance->getExternalUnl();
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl);
                assert($externalUnl != 'invalid');
 
                // Add Universal Node Locator/node id as criteria
@@ -240,10 +236,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                // Cache result of if there is an entry, valid() will tell us if an entry is there
                $isRegistered = $resultInstance->valid();
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
                // Return result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!');
                return $isRegistered;
        }
 
@@ -254,7 +248,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
         */
        public function registerLocalNode () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!');
 
                // Assert to make sure this method is called with no record in DB (the actual backend of the DHT)
                assert(!$this->isLocalNodeRegistered());
@@ -263,10 +257,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp
                $dataSetInstance = $this->prepareLocalDataSetInstance();
 
                // "Insert" this dataset instance completely into the database
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Calling this->queryInsertDataSet(' . $dataSetInstance->__toString() . ') ...');
                $this->queryInsertDataSet($dataSetInstance);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!');
        }
 
        /**
index a5c7c918b9ad7a452b1d76605291aa6d5287e550..1a9c356ff3ac084c814425965c71baaa10ec5905 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\PeerState;
 // Import application-specific sutff
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\LookupTable\Lookupable;
index 01f767f64e731ed8b04738f05b9b3deab37e7b16..22123edc38fc249889ccd9cf4397ebd8d82334a3 100644 (file)
@@ -154,7 +154,7 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable {
                $packageInstance = $this->getHandlerInstance()->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_PACKAGE);
 
                // Handle it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: decodedData(' . count($packageInstance) . ')=' . print_r($packageInstance, TRUE));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: packageInstance=' . $packageInstance->__toString() . ')=' . print_r($packageInstance, TRUE));
                $this->getPackageHandlerInstance()->handleRawData($packageInstance);
        }
 
index c1d79621e4c67cf6ffbdf465da8995a2bfc3a92c..dc6ba5a00daf4224582eb45e2ae27adfc9ee91f2 100644 (file)
@@ -245,6 +245,7 @@ abstract class BaseDht extends BaseHubSystem implements Distributable {
                $this->publishHelperInstance->getTemplateInstance()->assignMultipleVariables($entry);
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: Calling this->publishHelperInstance->sendPackage(' . $this->__toString() . ') ...');
                $this->publishHelperInstance->sendPackage($this);
        }
 
index cb66fa372d48db2fb0a53c961641c76fbe325a4e..9d042119bdee5d2eb22a0c961d8d8244223c33bb 100644 (file)
@@ -78,20 +78,26 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         */
        protected function insertDataIntoDht (array $dhtData) {
                // Check if there is already an entry for given node_id
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: dhtData()=%d - CALLED!', count($dhtData)));
                if ($this->getWrapperInstance()->isNodeRegistered($dhtData)) {
                        /*
                         * Update existing record. Please note that this step is not secure
                         * (e.g. DHT poisoning) it would be good to implement some checks if
                         * the both node owner trust each other (see sub-project 'DSHT').
                         */
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Updating existing node data ...');
                        $this->getWrapperInstance()->updateNode($dhtData);
                } else {
                        /*
                         * Inserts given node data into the DHT. As above, this step does
                         * currently not perform any security checks.
                         */
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Registering node data ...');
                        $this->getWrapperInstance()->registerNode($dhtData);
                }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!');
        }
 
        /**
@@ -101,16 +107,22 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         */
        public function initDht () {
                // Is the local node registered?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: CALLED!');
                if ($this->getWrapperInstance()->isLocalNodeRegistered()) {
                        // Then only update session id
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Updating local node data ...');
                        $this->getWrapperInstance()->updateLocalNode();
                } else {
                        // No, so register it
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Registering local node data ...');
                        $this->getWrapperInstance()->registerLocalNode();
                }
 
                // Change state
                $this->getStateInstance()->dhtHasInitialized();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!');
        }
 
        /**
@@ -131,10 +143,14 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $this->__toString()));
                $helperInstance->sendPackage($this);
 
                // Change state
                $this->getStateInstance()->dhtIsBooting();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!');
        }
 
        /**
@@ -145,7 +161,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         */
        public function findNodeLocalBySessionId ($sessionId) {
                // Default is empty data array
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FACADE: sessionid=%s - CALLED!', $sessionId));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: sessionId=%s - CALLED!', $sessionId));
                $nodeData = array();
 
                /*
@@ -168,7 +184,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
 
                // 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('DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData)));
                return $nodeData;
        }
 
@@ -191,18 +207,18 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData()));
 
                // Search for the node's session id and external address/hostname + TCP/UDP listen port
                foreach ($handlerInstance->getSearchData() as $key) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',key=' . $key);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',key=' . $key);
 
                        // Is it there?
                        assert(isset($messageData[$key]));
 
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]);
 
                        // Add criteria
                        $searchInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
@@ -249,10 +265,11 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
         */
        public function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) {
                // Make sure both keys are there
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: messageData()=%d,handlerInstance=%s,excludeKey=%s,andKey=%s,separator=%s - CALLED!', count($messageData), $handlerInstance->__toString(), $excludeKey, $andKey, $separator));
                assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey])));
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE));
 
                // Get a search criteria class
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
@@ -260,7 +277,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                // Add all keys
                foreach (explode($separator, $messageData[$andKey]) as $criteria) {
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria);
 
                        // Add it and leave any 'my-' prefix out
                        $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria);
@@ -290,7 +307,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                        assert(count($current) > 0);
 
                        // Debug message
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE));
 
                        /*
                         * Remove some keys as they should not be published.
@@ -305,6 +322,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                $handlerInstance->setLastException($this->getWrapperInstance()->getLastException());
 
                // Return node list (array)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeList()=%d - EXIT!', count($nodeList)));
                return $nodeList;
        }
 
@@ -320,7 +338,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                // If no node is in the list (array), skip the rest of this method
                if (count($nodeList) == 0) {
                        // Debug message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: No node record has been returned.');
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: No node record has been returned.');
 
                        // Abort here
                        return;
@@ -359,7 +377,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable {
                while ($resultInstance->next()) {
                        // Get current entry
                        $current = $resultInstance->current();
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: current=' . print_r($current, TRUE));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: current=' . print_r($current, TRUE));
 
                        // Add instance to recipient list
                        array_push($recipients, $current);
index ed01b23692da837bd92d1b2ed1934cb6c8a5f65d..d4288d02c6f6573ad372962cd6182527e7ee261a 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Discovery\Protocol;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Discovery\Node\BaseNodeDiscovery;
 use Org\Shipsimu\Hub\Factory\Tag\Package\PackageTagsFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 // Import framework stuff
index 29edd20f1923db6400c21b6faeb42e1e3f34d9b6..164792757f448e4a571c30abcc80d51b6e5c8632 100644 (file)
@@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Discovery\Network\Recipient;
 use Org\Shipsimu\Hub\Discovery\Recipient\BaseRecipientDiscovery;
 use Org\Shipsimu\Hub\Discovery\Recipient\Node\DiscoverableNodeRecipient;
 use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException;
@@ -69,7 +68,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
         * @param       $packageInstance        An instance of a DeliverablePackage class array
         * @return      void
         */
-       public function discoverRecipients (DeliverablePackage $packageInstance) {
+       public function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance) {
                // Init instance
                $recipientInstance = NULL;
 
@@ -89,7 +88,8 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
                        }
 
                        // Try to solve it
-                       $recipientInstance->resolveRecipient($packageInstance->getRecipientUnl(), $this->getListInstance(), $packageInstance);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Calling recipientInstance->resolveRecipientByPackageInstance(%s, %s) ...', $packageInstance->__toString(), $this->getListInstance()->__toString()));
+                       $recipientInstance->resolveRecipientByPackageInstance($packageInstance, $this->getListInstance());
                } catch (FrameworkException $e) {
                        // Could not find class, what ever failed
                        $this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage()));
index 9c8e0d7acac40bcd2ab31e44a262182aafd29bcb..7881fa9a6a3502cf235308e6fa550066eeaa071a 100644 (file)
@@ -10,7 +10,6 @@ use Org\Shipsimu\Hub\Discovery\Socket\DiscoverableSocket;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
 use Org\Shipsimu\Hub\Factory\Socket\SocketFactory;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol;
 use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
@@ -83,7 +82,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
         */
        public function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance) {
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: protocolInstance=' . $protocolInstance->__toString() . ' - CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: protocolInstance=' . $protocolInstance->__toString() . ',packageInstance=' . $packageInstance->__toString() . ' - CALLED!');
 
                /*
                 * Get the listener pool instance, we need to lookup the matching
@@ -130,10 +129,8 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Listener is NOT accepting package data.');
                } // END - foreach
 
-               // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance->__toString());
-
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance->__toString() . ' - EXIT!');
                return $listenerInstance;
        }
 
index 13398f47b9bb031df147703480ce1f21ebccf64b..34cb97932cad71005e63cc016e0a0d1845b7bea7 100644 (file)
@@ -87,12 +87,12 @@ class ProtocolHandlerFactory extends ObjectFactory {
        /**
         * Creates an instance of a protocol handler from given (raw) package data
         *
-        * @param       $packageData            An array with raw package data
+        * @param       $packageInstance                An array with raw package data
         * @return      $handlerInstance        A protocol handler instance
         */
        public static final function createProtocolHandlerFromPackageInstance (DeliverablePackage $packageInstance) {
                // "Discover" the protocol type
-               $protocolType = ProtocolDiscovery::discoverProtocolByPackageInstance($packageData);
+               $protocolType = ProtocolDiscovery::discoverProtocolByPackageInstance($packageInstance);
 
                // Call super factory method
                return self::createProtocolHandlerByType($protocolType);
index 9fbbb64ff34d7d9608b9aa15200e2b8356360913..7d6dceec926b2c790d8a6cc64b29a822d57f79e9 100644 (file)
@@ -1,69 +1,2 @@
 <?php
-// Own namespace
-namespace Org\Shipsimu\Hub\Factory\Network;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
-
-/**
- * A factory class for network packages
- *
- * @author             Roland Haeder <webmaster@shipsimu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class PackageDataFactory extends ObjectFactory {
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Returns a singleton DeliverablePackage instance. If an instance is found
-        * in the registry it will be returned, else a new instance is created and
-        * stored in the same registry entry.
-        *
-        * @return      $packageInstance        An instance of a DeliverablePackage class
-        */
-       public static final function createPackageDataInstance () {
-               // Do we have an instance in the registry?
-               if (GenericRegistry::getRegistry()->instanceExists('package_data')) {
-                       // Then use this instance
-                       $packageInstance = GenericRegistry::getRegistry()->getInstance('package_data');
-               } else {
-                       /*
-                        * Now prepare the network package for delivery so only need to do this
-                        * once just before the "big announcement loop".
-                        */
-                       $packageInstance = self::createObjectByConfiguredName('package_data_class');
-
-                       // Set the instance in registry for further use
-                       GenericRegistry::getRegistry()->addInstance('package_data', $packageInstance);
-               }
-
-               // Return the instance
-               return $packageInstance;
-       }
-
-}
+// @DEPRECATED
index 9ddf52870e3398aec682b35ef32bc9e06ffc9d2b..b9cabf147033254b9d4ca234928e61f312d43bf0 100644 (file)
@@ -4,8 +4,6 @@ namespace Org\Shipsimu\Hub\Factory\Socket;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
-use Org\Shipsimu\Hub\Factory\Network\PackageDataFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol;
 use Org\Shipsimu\Hub\Listener\BaseListener;
 use Org\Shipsimu\Hub\Listener\Listenable;
@@ -125,7 +123,7 @@ class SocketFactory extends ObjectFactory {
                assert(!empty($socketFile));
 
                // Init package instance
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Init main socket
                $socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0);
@@ -283,7 +281,7 @@ class SocketFactory extends ObjectFactory {
                $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
                // Init fake "package" instance, the SocketContainer class requires this
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Create socket instance
                $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
@@ -362,7 +360,7 @@ class SocketFactory extends ObjectFactory {
                $socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
 
                // Init fake package instance
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Create socket instance
                $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
@@ -488,17 +486,21 @@ class SocketFactory extends ObjectFactory {
         * @return      $socketInstance         An instance of a StorableSocket class
         */
        public static final function createIncomingSocketInstance ($socketResource, $socketProtocol) {
-               // Create socket instance
+               // Create package instance
                /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol));
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
+
+               // Create socket instance
                $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
                        $socketResource,
                        $socketProtocol,
+                       $packageInstance,
                ));
 
                // Set all socket data
                $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_INCOMING);
-               $socketInstance->setSocketAddress('invalid');
-               $socketInstance->setSocketPort('0');
+               $socketInstance->setPeerAddress('invalid');
+               $socketInstance->setPeerPort('0');
 
                // Is the socket resource valid?
                if (!$socketInstance->isValidSocket()) {
index 0f2f95d379be9ca8ab9aa64d4f41dfbdde9a1ad7..f2df80ef145d75906ba69ddbbfa9bb13039be647 100644 (file)
@@ -68,11 +68,11 @@ class PeerStateFactory extends ObjectFactory {
 
        /**
         * Creates a peer state instance based on errorCode if no entry is found in the lookup table
-        * for the peer given in $packageData 'sender' element or it changes the state if it differs
+        * for the peer given in $packageInstance 'sender' element or it changes the state if it differs
         * from current state.
         *
         * @param       $helperInstance         An instance of a ConnectionHelper class
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance                An instance of a DeliverablePackage class
         * @param       $socketInstance         A valid socket resource
         * @param       $errorCode                      The last error code
         * @return      $stateInstance          A Stateable class instance
@@ -97,12 +97,12 @@ class PeerStateFactory extends ObjectFactory {
                }
 
                // Do we have an entry?
-               if ($tableInstance->isSenderNewPeer($packageData)) {
+               if ($tableInstance->isSenderNewPeer($packageInstance)) {
                        // Debug output
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: errorCode=' . $errorCode);
 
                        // Register the new peer with its session id
-                       $tableInstance->registerPeerByPackageInstance($packageData, $socketInstance);
+                       $tableInstance->registerPeerByPackageInstance($packageInstance, $socketInstance);
 
                        /*
                         * It is a new peer so create the state instance based on error
@@ -111,8 +111,8 @@ class PeerStateFactory extends ObjectFactory {
                        $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
 
                        // And register it with the lookup table
-                       $tableInstance->registerPeerState($stateInstance, $packageData);
-               } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) {
+                       $tableInstance->registerPeerState($stateInstance, $packageInstance);
+               } elseif ($tableInstance->isSamePeerState($helperInstance, $packageInstance)) {
                        // Debug output
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state unchanged, re-generating old state ...');
 
@@ -132,7 +132,7 @@ class PeerStateFactory extends ObjectFactory {
                        $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
 
                        // The peer's state has changed, update database now
-                       $tableInstance->registerPeerState($stateInstance, $packageData);
+                       $tableInstance->registerPeerState($stateInstance, $packageInstance);
                }
 
                // Debug message
index 59a939740c5b4143614ef203edd9876fdeb8737b..df149e5fcff8014bd3b0f490ea2b1bbfe6a4e0fe 100644 (file)
@@ -130,6 +130,7 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface {
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // Deliver the package
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString()));
                $helperInstance->sendPackage($nodeInstance);
 
                /*
@@ -171,6 +172,7 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface {
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // Deliver the package
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString()));
                $helperInstance->sendPackage($nodeInstance);
 
                /*
index 621c0423d5be9e7e19d06ab2bfc143776587f60e..ad5726a2293a0e2d861fc9f587f6000caef1dfe6 100644 (file)
@@ -12,7 +12,6 @@ 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\PackageDataFactory;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
 use Org\Shipsimu\Hub\Generic\BaseHubSystem;
 use Org\Shipsimu\Hub\Handler\BaseHubHandler;
@@ -554,7 +553,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
 
                // Discover all recipients, this may throw an exception
-               $discoveryInstance->discoverRecipients($packageInstance);
+               $discoveryInstance->discoverRecipientsByPackageInstance($packageInstance);
 
                // Now get an iterator
                $iteratorInstance = $discoveryInstance->getIterator();
@@ -722,7 +721,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        private function generatePackageHash ($content, $senderId) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!');
 
                // Assert on variables
                assert(!empty($content));
@@ -731,12 +730,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                // Is the feature enabled?
                if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) {
                        // Feature is not enabled
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...');
                        return NULL;
                } // END - if
 
                // Fake package instance
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Set all fields
                $packageInstance->setSenderId($senderId);
@@ -744,7 +743,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $packageInstance->setSenderPrivateKeyHash($this->getNodeInstance()->getNodePrivateKeyHash());
 
                // Hash content and sender id together, use scrypt
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderId=' . $senderId . ',content()=' . strlen($content));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderId=' . $senderId . ',content()=' . strlen($content));
                $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array(
                        sprintf('%s:%s:%s',
                                $senderId,
@@ -753,10 +752,8 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                        )
                ));
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: hash=' . $hash . ' - EXIT!');
-
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: hash=' . $hash . ' - EXIT!');
                return $hash;
        }
 
@@ -805,11 +802,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: helperInstance=' . $helperInstance->__toString() . ' - CALLED!');
 
                // Get the raw content ...
                $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('content(' . strlen($content) . ')=' . $content);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('content(' . strlen($content) . ')=' . $content);
 
                // ... and compress it
                $compressed = $this->getCompressorInstance()->compressStream($content);
@@ -833,28 +830,29 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                );
 
                // Make sure required data is there
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
                assert(!empty($content));
                assert($this->getNodeInstance()->getSessionId() != '');
 
                // Init package instance
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Set all data
                $packageInstance->setSenderAddress($this->getNodeInstance()->getSessionId());
                $packageInstance->setSenderPort('0');
                $packageInstance->setRecipientType($helperInstance->getRecipientType());
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Setting packageContent=%s ...', $packageContent));
                $packageInstance->setPackageContent($packageContent);
                $packageInstance->setStatus(self::PACKAGE_STATUS_NEW);
                $packageInstance->setContentHash($this->generatePackageHash($content, $this->getNodeInstance()->getSessionId()));
                $packageInstance->setSenderPrivateKeyHash($this->getNodeInstance()->getNodePrivateKeyHash());
 
                // Now prepare the temporary array and push it on the 'undeclared' stack
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Pushing packageInstance=%s to stack %s ...', $packageInstance->__toString(), self::STACKER_NAME_UNDECLARED));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Pushing packageInstance=%s to stack %s ...', $packageInstance->__toString(), self::STACKER_NAME_UNDECLARED));
                $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, $packageInstance);
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
        }
 
        /**
@@ -936,7 +934,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
         */
        public function declareEnqueuedPackage () {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!');
 
                // Make sure this method isn't working if there is no package enqueued
                if (!$this->isPackageEnqueued()) {
@@ -952,10 +950,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED);
 
                // Declare the raw package data for delivery
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance->recipientType=%s is undeclared, declaring now ...', $packageInstance->getRecipientType()));
                $this->declareRawPackageData($packageInstance);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
        }
 
        /**
@@ -1376,10 +1375,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
 
                // Assert on count (should be always 3)
                assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE);
-               /* PRINTR-DEBUG: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
+               /* PRINTR-DIE: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
 
                // Create package instance
-               $packageInstance = PackageDataFactory::createPackageDataInstance();
+               $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
 
                // Set all data
                $packageInstance->setSenderAddress($decodedArray[self::INDEX_PACKAGE_SENDER_ADDRESS]);
@@ -1391,7 +1390,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei
                $packageInstance->setSenderPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]);
 
                // And return it
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString()));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString()));
                return $packageInstance;
        }
 
index f289c729df5ee5d4524851879964ffd9b0c5d035..7eaf4863fdadfab9332d41a3d3a75e88998424ad 100644 (file)
@@ -4,7 +4,6 @@ namespace Org\Shipsimu\Hub\Handler\Protocol\Network\IpV4;
 
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Handler\Protocol\BaseProtocolHandler;
 use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils;
index 576e85c81c9fad022df12c831bc12afd72de5fce..f3422631fcc18f54290043907af247feee618074 100644 (file)
@@ -7,7 +7,6 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
 use Org\Shipsimu\Hub\Generic\HubInterface;
 use Org\Shipsimu\Hub\Handler\BaseHubHandler;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 
 // Import framework stuff
index 46be16fc9e70dfa6babd96cdd3ea9ebe1d867d72..ef78abe867c5736ad918fa90651d1ac7670900cc 100644 (file)
@@ -177,7 +177,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
         * 1) Request a chunk from set fragmenter instance
         * 2) Finally return the chunk (array) to the caller
         *
-        * @param       $packageData    An instance of a DeliverablePackage class array
+        * @param       $packageInstance        An instance of a DeliverablePackage class array
         * @return      $chunkData              Raw data chunk
         */
        private function getRawDataFromPackageArray (DeliverablePackage $packageInstance) {
@@ -239,18 +239,18 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
        /**
         * Sends An instance of a DeliverablePackage class to the recipient
         *
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         */
        public function sendRawPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageData()=%d - CALLED!', count($packageData)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // The helper's state must be 'connected'
                $this->getStateInstance()->validatePeerStateConnected();
 
                // Implode the package data array and fragement the resulting string, returns the final hash
-               $finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageData, $this);
+               $finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageInstance, $this);
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
@@ -277,7 +277,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - BEFORE!', strlen($dataStream)));
 
                        // Convert the package data array to a raw data stream
-                       $dataStream = $this->getRawDataFromPackageArray($packageData);
+                       $dataStream = $this->getRawDataFromPackageArray($packageInstance);
 
                        // Debug message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - AFTER!', strlen($dataStream)));
index 90edd763d203d31de200071a1d65641d7d94c13d..0f8931f3fe782f32fb1c96e6854b341bf712c5cb 100644 (file)
@@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Helper\Connection\Network\IpV4\Tcp;
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
 use Org\Shipsimu\Hub\Factory\Socket\SocketFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper;
 use Org\Shipsimu\Hub\Helper\Connection\Network\IpV4\BaseIpV4ConnectionHelper;
 use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
@@ -56,7 +55,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         * recipient in package data. After you called this method you still need to
         * connect to the other node.
         *
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance                An instance of a DeliverablePackage class
         * @return      $socketInstance         An instance of a StorableSocket class
         */
        public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) {
@@ -64,7 +63,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                $helperInstance = new TcpConnectionHelper();
 
                // Construct container class, this won't be reached if an exception is thrown
-               $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageData);
+               $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageInstance);
 
                // Set the resource
                $helperInstance->setSocketInstance($socketInstance);
@@ -76,7 +75,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
                // Try to solve the recipient
                try {
                        // Get protocol handler back from package data
-                       $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageData);
+                       $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
 
                        // Get UNL instance
                        $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
index c541b4744704ac1e6c2638d1d6fddf5256873f7d..39ac6281708cf779bb7399c89e3c043800cf6d4f 100644 (file)
@@ -50,11 +50,11 @@ class UdpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection
         * recipient in package data. After you called this method you still need to
         * connect to the other node.
         *
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance                An instance of a DeliverablePackage class
         * @return      $socketInstance         An instance of a StorableSocket class
         */
        public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) {
-               $this->debugBackTrace(':  Unfinished method, packageData[]=' . count($packageData));
+               $this->debugBackTrace('Unfinished method, packageInstance=' . print_r($packageInstance, TRUE));
        }
 
        /**
index 96fe370256a5ef089b9a9f7d0fb3b10b0d7b841b..65b978c2602d21272b7d30c14c54c3203426cc2a 100644 (file)
@@ -74,10 +74,8 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
         * @return      void
         */
        public function loadDescriptorXml (Node $nodeInstance) {
-               // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting self-connect...');
-
                // Get a XML template instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: nodeInstance=' . $nodeInstance->__toString() . ' - CALLED!');
                $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_self_connect_template_class');
 
                // Set it for later use
@@ -88,6 +86,9 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
 
                // Render the XML content
                $templateInstance->renderXmlContent();
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!');
        }
 
        /**
@@ -98,6 +99,7 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
         */
        public function sendPackage (Node $nodeInstance) {
                // Sanity check: Is the node in the approx. state? (active)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: nodeInstance=' . $nodeInstance->__toString() . ' - CALLED!');
                $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrAnnouncing();
 
                // Compile the template, this inserts the loaded node data into the gaps.
@@ -107,7 +109,11 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode {
                $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance();
 
                // Next, feed the content in. The network package class is a pipe-through class.
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: Calling packageInstance->enqueueRawDataFromTemplate(' . $this->__toString() . ') ...');
                $packageInstance->enqueueRawDataFromTemplate($this);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!');
        }
 
 }
index a57e8c3e4a51918b99846e357fa70912460eb2b7..2adc9de9324d2a13cd1766d939e6d57dcdcf9460 100644 (file)
@@ -403,11 +403,9 @@ abstract class BaseListener extends BaseHubSystem implements Visitable {
                //* DEBUG-DIE: */ $infoInstance->debugInstance();
 
                // Set all required data
-               $socketInstance->setSenderAddres($peerAddress . $peerSuffix);
+               $socketInstance->setSenderAddress($peerAddress . $peerSuffix);
                $socketInstance->setSenderPort($peerPort);
                $socketInstance->setRecipientId($nodeInstance->getSessionId());
-               $socketInstance->setStatus(NetworkPackageHandler::PACKAGE_STATUS_FAKED);
-               die(__METHOD__.': UNFINISHED!');
 
                // Register the socket with the registry and with the faked array
                $this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
index a72c6a7b5104513a365ec4c78d067ec459cf2162..e73e8b54c5b5e357e630d7f27906e6df1236c863 100644 (file)
@@ -120,15 +120,15 @@ class SocketFileListener extends BaseListener implements Listenable {
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // Call parent method
-               if (!parent::ifListenerAcceptsPackageData($packageData)) {
+               if (!parent::ifListenerAcceptsPackageData($packageInstance)) {
                        // Trace message
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
 
@@ -137,13 +137,13 @@ class SocketFileListener extends BaseListener implements Listenable {
                } // END - if
 
                // Debugging
-               /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE));
+               /* DEBUG-DIE: */ die(__METHOD__.':packageInstance='.print_r($packageInstance, TRUE));
 
                // Get a tags instance
                $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
 
                // So is the package accepted with this listener?
-               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this);
 
                // Trace message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: accepts=%d - EXIT!', $accepts));
index 6da5098109f08f2b44101af8b4731d7aa8a0a104..119bcfa4612cb69f0d6de9881c27df5e833de260 100644 (file)
@@ -93,7 +93,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
@@ -101,7 +101,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste
                /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance()->ifListenerAcceptsPackageData() ...');
 
                // Call inner method, no decoration is wanted in this method
-               return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageData);
+               return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance);
        }
 
 }
index a1b3ad23b4f0b54fde2597f831a9e0b9652a1771..532498afb7712926eb225d00df131bc4943a15f0 100644 (file)
@@ -93,15 +93,15 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // Invoke decorated listener's method
-               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
+               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) {
                        // Trace message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
 
@@ -110,13 +110,13 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen
                } // END - if
 
                // Debugging
-               /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+               /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
 
                // Get a tags instance
                $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
 
                // So is the package accepted with this listener?
-               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: accepts=%d - EXIT!', $accepts));
index 7f83f22d1344cace9ebc52c9c5dfd8c7207aa6cc..66dab9fad0f0cb16816c9bdca4ea6201352bdd5c 100644 (file)
@@ -93,15 +93,15 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // // Invoke decorated listener's method
-               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
+               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) {
                        // Trace message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
 
@@ -110,13 +110,13 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl
                } // END - if
 
                // Debugging
-               //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+               //* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
 
                // Get a tags instance
                $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
 
                // So is the package accepted with this listener?
-               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: accepts=%d - EXIT!', $accepts));
index 08f55d407cf2c0e52fdfa95c770d5fcfcc816146..671da1efb59969c38f469ca4125b2f2e1fb992f9 100644 (file)
@@ -119,7 +119,7 @@ class UdpListener extends BaseListener implements Listenable {
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         * @throws      UnsupportedOperationException   If this method is called
         */
index 209c538db5e00d06d6a0e5994662628c47f4b987..028738c22fb8523627148cb2aadb0213075ed8f1 100644 (file)
@@ -93,15 +93,15 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // Invoke decorated listener's method
-               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
+               if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) {
                        // Trace message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
 
@@ -110,13 +110,13 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen
                } // END - if
 
                // Debugging
-               /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+               /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
 
                // Get a tags instance
                $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
 
                // So is the package accepted with this listener?
-               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: accepts=%d - EXIT!', $accepts));
index 9baa90d0cde00d11c5ee28ea952ee39c5220978c..d67923d708eed09379ca60696b60889c76201948 100644 (file)
@@ -93,15 +93,15 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl
        /**
         * Checks whether the listener would accept the given package data array
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      $accepts                Whether this listener does accept
         */
        public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
                // Trace message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData)));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
 
                // Invoke decorated listener's method
-               if ($this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) {
+               if ($this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) {
                        // Trace message
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.');
 
@@ -110,13 +110,13 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl
                } // END - if
 
                // Debugging
-               /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+               /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE));
 
                // Get a tags instance
                $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
 
                // So is the package accepted with this listener?
-               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);
+               $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this);
 
                // Trace message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: accepts=%d - EXIT!', $accepts));
index bbe3a881f038fb810e536f239f19ccd2c42187e6..98f7395dd7b696cb137824c9df873441a5727892 100644 (file)
@@ -489,6 +489,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // "Publish" the descriptor by sending it to the bootstrap/list nodes
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: Calling helperInstance->sendPackage(%s) ...', $this->__toString()));
                $helperInstance->sendPackage($this);
 
                // Change the state, this should be the last line except debug output
@@ -520,6 +521,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC
                $helperInstance->getTemplateInstance()->compileConfigInVariables();
 
                // And send the package away
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: Calling helperInstance->sendPackage(%s) ...', $this->__toString()));
                $helperInstance->sendPackage($this);
 
                // Debug output
index badb7b7eb5fc8f2a79e241328f09492302d2b4f8..93beeecc62056ad83d0596f2ce5e1f3eb752de93 100644 (file)
@@ -8,6 +8,10 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 
+// Import SPL stuff
+use \ReflectionClass;
+use \ReflectionProperty;
+
 /**
  * A DeliverablePackage class for raw package data
  *
@@ -271,4 +275,45 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera
                return $this->senderPrivateKeyHash;
        }
 
+       /**
+        * Collecting "getter" for all class fields as array
+        *
+        * @return $packageData         An array with all fields from this class
+        */
+       public final function getAllAsArray () {
+               // Get reflection from this
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DATA: CALLED!');
+               $reflectionInstance = new ReflectionClass($this);
+
+               // Get all properties
+               $properties = $reflectionInstance->getProperties(ReflectionProperty::IS_PRIVATE);
+
+               // Init array
+               $packageData = array();
+
+               // Loop through all
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: properties()=%d', count($properties)));
+               foreach ($properties as $propertyInstance) {
+                       // Is the declaring class this one?
+                       //* DEBUG-DIE: */ die(sprintf('[%s:%d] propertyInstance=%s', __METHOD__, __LINE__, print_r($propertyInstance)));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: propertyInstance->declaringClass->name=%s', $propertyInstance->getDeclaringClass()->getName()));
+                       if ($propertyInstance->getDeclaringClass()->getName() !== $this->__toString()) {
+                               // No, then skip this one
+                               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: propertyInstance->declaringClass->name=%s is not matching - skip!', $propertyInstance->getDeclaringClass()->getName()));
+                               continue;
+                       }
+
+                       // Invoke getter method
+                       $value = call_user_func_array(array($this, sprintf('get%s', ucfirst($propertyInstance->getName()))), array());
+
+                       // Add name/value
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Adding %s[%s]=%s', $propertyInstance->getName(), gettype($value), $value));
+                       $packageData[$propertyInstance->getName()] = $value;
+               }
+
+               // Return array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: packageData()=%d - EXIT!', count($packageData)));
+               return $packageData;
+       }
+
 }
index 837c88b98484ad461f7e512e9a978e95a1b5b3fb..271c9a804ae3fee7ee6ed1f448e38ef38d39b6aa 100644 (file)
@@ -130,6 +130,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public static final function createPackageFragmenter () {
                // Get new instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!');
                $fragmenterInstance = new PackageFragmenter();
 
                // Get a crypto instance and set it here
@@ -147,11 +148,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function initFragmenter () {
                // Load some configuration entries and "cache" them:
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!');
                // - Chunk size in bits
                $this->chunkSize = $this->getConfigInstance()->getConfigEntry('package_chunk_size');
 
                // - Maximum serial number
                $this->maxSerialNumber = $this->hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH));
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -161,6 +166,8 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @return      void
         */
        private function initPointer ($finalHash) {
+               // Init counter
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                $this->chunkPointers[$finalHash] = 0;
        }
 
@@ -171,6 +178,8 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         * @return      $index                  Array index for processedPackages
         */
        private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) {
+               // Generate array index
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                return (
                        $packageInstance->getSenderAddress()  . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
                        $packageInstance->getRecipientUnl()   . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
@@ -186,6 +195,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function isPackageProcessed (DeliverablePackage $packageInstance) {
                // Get array index
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $index = $this->getProcessedPackagesIndex($packageInstance);
 
                // Is the array index there?
@@ -196,6 +206,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                );
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: isProcessed=%d - EXIT!', intval($isProcessed)));
                return $isProcessed;
        }
 
@@ -207,6 +218,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function markPackageDataProcessed (DeliverablePackage $packageInstance) {
                // Remember it (until we may remove it)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = TRUE;
        }
 
@@ -218,6 +230,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function getFinalHashFromPackageInstance (DeliverablePackage $packageInstance) {
                // Make sure it is there
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)]));
 
                // Return it
@@ -231,13 +244,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function getCurrentChunkPointer ($finalHash) {
                // Is the final hash valid?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                assert(strlen($finalHash) > 0);
 
                // Is the pointer already initialized?
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
                assert(isset($this->chunkPointers[$finalHash]));
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: Returning chunk pointers for finalHash=%s - EXIT!', $finalHash));
                return $this->chunkPointers[$finalHash];
        }
 
@@ -248,10 +262,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function nextChunkPointer ($finalHash) {
                // Is the pointer already initialized?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                assert(isset($this->chunkPointers[$finalHash]));
 
                // Count one up
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash));
                $this->chunkPointers[$finalHash]++;
        }
 
@@ -263,6 +278,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function getDataChunkSizeFromHash ($hash) {
                // Calculate real (data) chunk size
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - CALLED!', $hash));
                $dataChunkSize = (
                        // Real chunk size
                        ($this->chunkSize / 8) -
@@ -278,6 +294,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                assert($dataChunkSize > 0);
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d - CALLED!', $dataChunkSize));
                return $dataChunkSize;
        }
 
@@ -293,9 +310,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                 * Get the crypto instance and hash the data with no extra salt because
                 * the other peer doesn't have *this* peer's salt.
                 */
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s - CALLED!', $rawData));
                $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE);
 
                // Return it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - EXIT!', $hash));
                return $hash;
        }
 
@@ -310,16 +329,20 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function appendEndOfPackageChunk ($lastChunk, $finalHash) {
                // Generate end-of-package marker
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: lastChunk=%s,finalHash[%s]=%s - CALLED!', $lastChunk, gettype($finalHash), $finalHash));
                $chunkData =
                        self::END_OF_PACKAGE_IDENTIFIER .
                        $finalHash . self::CHUNK_HASH_SEPARATOR .
                        $this->generateHashFromRawData($lastChunk);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...');
 
                // Add it as regular chunk
                $this->addChunkData($finalHash, $chunkData);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -333,6 +356,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function splitEncodedDataIntoChunks ($rawData, $finalHash) {
                // Make sure final hashes with at least 32 bytes can pass
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s,finalHash[%s]=%s - CALLED!', $rawData, gettype($finalHash), $finalHash));
                assert(strlen($finalHash) >= 32);
 
                // Calculate real (data) chunk size
@@ -353,10 +377,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                } // END - for
 
                // Debug output
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).');
 
                // Add end-of-package chunk
                $this->appendEndOfPackageChunk($chunkData, $finalHash);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -370,6 +397,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) {
                // Hash it
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s,chunkData=%s,prepend=%d - CALLED!', gettype($finalHash), $finalHash, $chunkData, intval($prepend)));
                $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE);
 
                // Prepend the hash to the chunk
@@ -380,7 +408,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                );
 
                // Make sure the chunk is not larger than a TCP package can hold
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: assert: ' . strlen($rawData) . '/' . NetworkPackageHandler::TCP_PACKAGE_SIZE . ' ...');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: assert: ' . strlen($rawData) . '/' . NetworkPackageHandler::TCP_PACKAGE_SIZE . ' ...');
                // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackageHandler::TCP_PACKAGE_SIZE);
 
                // Add it to the array
@@ -404,6 +432,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        array_push($this->chunks[$finalHash]     , $rawData);
                        array_push($this->chunkHashes[$finalHash], $rawDataHash);
                }
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -414,10 +445,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        private function prependHashChunk ($finalHash) {
                // "Implode" the whole array of hashes into one string
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]);
 
                // Prepend chunk
                $this->addChunkData($finalHash, $rawData, TRUE);
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
        /**
@@ -428,6 +463,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function getNextHexSerialNumber ($finalHash) {
                // Assert on maximum serial number length
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                assert(isset($this->serialNumber[$finalHash]));
                assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber);
 
@@ -439,7 +475,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                $this->serialNumber[$finalHash]++;
 
                // Return the encoded serial number
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: encodedSerialNumber=' . $encodedSerialNumber);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: encodedSerialNumber=' . $encodedSerialNumber . ' - EXIT!');
                return $encodedSerialNumber;
        }
 
@@ -456,14 +492,19 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance) {
                // 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 we need to "implode" the array
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...');
                        $rawData = implode(NetworkPackageHandler::PACKAGE_DATA_SEPARATOR, $packageInstance->getAllAsArray());
 
                        // Generate the final hash from the raw data (not encoded!)
+                       //* DEBUG-DIE: */ die(sprintf('[%s:%d]: rawData[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($rawData), $rawData));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData));
                        $finalHash = $this->generateHashFromRawData($rawData);
 
                        // Remember it
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
                        $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash;
 
                        // Init pointer and reset serial number
@@ -480,11 +521,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                        $this->markPackageDataProcessed($packageInstance);
                } else {
                        // Get the final hash from the package data
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...');
                        $finalHash = $this->getFinalHashFromPackageInstance($packageInstance);
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash));
                }
 
                // Return final hash
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash));
                return $finalHash;
        }
 
@@ -499,7 +542,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function getNextRawDataChunk ($finalHash) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
 
                try {
                        // Get current chunk index
@@ -518,12 +561,12 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                // If there is no entry left, return an empty array
                if ((!isset($this->chunkHashes[$finalHash][$current])) || (!isset($this->chunks[$finalHash][$current]))) {
                        // No more entries found
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!');
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!');
                        return array();
                } // END - if
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...');
 
                // Generate the array
                $rawDataChunk = array(
@@ -534,6 +577,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
                $this->nextChunkPointer($finalHash);
 
                // Return the chunk array
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Returning rawDataChunk ... - EXIT!');
                return $rawDataChunk;
        }
 
@@ -545,10 +589,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera
         */
        public function resetSerialNumber ($finalHash) {
                // Final hash must be set
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash));
                assert((is_string($finalHash)) && (!empty($finalHash)));
 
                // Reset/set serial number
                $this->serialNumber[$finalHash] = 0;
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
        }
 
 }
index 4f1ddec50647505c003d9e99e971c95e53316fb5..0c6634b6c90bf3227679b2a3fff978db1b73c225 100644 (file)
@@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Pool\Peer;
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Connection\InvalidConnectionTypeException;
 use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Listener\Listenable;
 use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
@@ -221,7 +220,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
        /**
         * "Getter" for a valid socket resource from given packae data.
         *
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @param       $connectionType         Type of connection, can be 'incoming', 'outgoing', 'server' or default
         * @return      $socketInstance         An instance of a StorableSocket class
         * @throws      InvalidConnectionTypeException  If the provided connection type is not valid
@@ -229,13 +228,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
         */
        public function getSocketFromPackageInstance (DeliverablePackage $packageInstance, $connectionType = NULL) {
                // Trace message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL:packageInstance=%s,connectionType[%s]=%s - CALLED!', $packageInstance->__toString(), gettype($connectionType), $connectionType));
 
                // Default is no socket
                $socketInstance = NULL;
 
                // Resolve recipient (UNL) into a handler instance
-               $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageData);
+               $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
 
                // Get UNL data
                $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
index 781c077e459d6d01b61618c6db6b679e3cae5b89..cb043fe35ceabf71c8cc3df55572fe46da92d60f 100644 (file)
@@ -61,22 +61,23 @@ class DhtRecipient extends BaseRecipient implements Recipient {
 
        /**
         * Tries to resolve given recipient into session ids or Universal Node Locator
-        * depending on implementation (hint: Template Method Pattern). This
-        * implementation will add more than one recipient to the list as a DHT is
-        * distributed and the package might go to more than one recipient.
+        * depending on implementation (hint: Template Method Pattern)
         *
-        * @param       $recipient                      Recipient to resolve (e.g. could be a virtual recipient or direct session id)
-        * @param       $listInstance           An instance of a Listable class
         * @param       $packageInstance        An instance of a DeliverablePackage class
-        * @return      void
+        * @param       $listInstance           An instance of a Listable class
+        * @return      $resolved                       Resolved recipient or VOID if only the set list has been filled
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
         */
-       public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
+       public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) {
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient . ' - CALLED!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
+
+               // Get recipient UNL
+               $recipientUnl = $packageInstance->getRecipientUnl();
 
                // Make sure the recipient is valid
-               assert($recipient == NetworkPackageHandler::NETWORK_TARGET_DHT);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipientUnl=' . $recipientUnl);
+               assert($recipientUnl == NetworkPackageHandler::NETWORK_TARGET_DHT);
 
                // Get recipient discovery instance
                $discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class');
@@ -87,6 +88,7 @@ class DhtRecipient extends BaseRecipient implements Recipient {
                // Now "walk" through all elements and add them to the list
                foreach ($recipients as $recipient) {
                        // These array elements must exist for this loop:
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient);
                        // @TODO Unfinished
                        die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE));
                        assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]));
@@ -100,7 +102,7 @@ class DhtRecipient extends BaseRecipient implements Recipient {
                } // END - foreach
 
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient . ' - EXIT!');
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: EXIT!');
        }
 
 }
index 5497d48d20950aa22e2f22798463eb4b1ef12c08..8164e72e74c0db13dc100bf215ec6cba81b441ae 100644 (file)
@@ -62,18 +62,21 @@ class DirectRecipient extends BaseRecipient implements Recipient {
         * Tries to resolve given recipient into session ids or Universal Node Locator
         * depending on implementation (hint: Template Method Pattern)
         *
-        * @param       $recipient                      Recipient to resolve (e.g. could be a virtual recipient or direct session id)
-        * @param       $listInstance           An instance of a Listable class
         * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @param       $listInstance           An instance of a Listable class
         * @return      $resolved                       Resolved recipient or VOID if only the set list has been filled
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
         */
-       public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
+       public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) {
                // Debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
+
+               // Get recipient UNL
+               $recipientUnl = $packageInstance->getRecipientUnl();
 
                // "Explode" all recipients
-               $recipients = explode(NetworkPackageHandler::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipientUnl=' . $recipientUnl);
+               $recipients = explode(NetworkPackageHandler::PACKAGE_RECIPIENT_SEPARATOR, $recipientUnl);
 
                // Is maximum reached?
                assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
@@ -81,11 +84,15 @@ class DirectRecipient extends BaseRecipient implements Recipient {
                // Try it on all
                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);
 
                        // Add it as recipient
                        $listInstance->addEntry('unl', $unlData);
                } // END - foreach
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: EXIT!');
        }
 
 }
index a08741b7f1b0db8eb52a795a93fdfda57458edac..0aa0ee45484d0a41c9d5ab6021aaefe434c719d9 100644 (file)
@@ -3,7 +3,6 @@
 namespace Org\Shipsimu\Hub\Network\Recipient\Loopback;
 
 // Import application-specific sutff
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
 use Org\Shipsimu\Hub\Network\Recipient\BaseRecipient;
 use Org\Shipsimu\Hub\Network\Recipient\Recipient;
@@ -12,6 +11,9 @@ use Org\Shipsimu\Hub\Tools\HubTools;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Lists\Listable;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A Self recipient
  *
@@ -62,26 +64,28 @@ class SelfRecipient extends BaseRecipient implements Recipient {
         * Tries to resolve given recipient into session ids or Universal Node Locator
         * depending on implementation (hint: Template Method Pattern)
         *
-        * @param       $recipient                      Recipient to resolve (e.g. could be a virtual recipient or direct session id)
-        * @param       $listInstance           An instance of a Listable class
         * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @param       $listInstance           An instance of a Listable class
         * @return      $resolved                       Resolved recipient or VOID if only the set list has been filled
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
         */
-       public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
-               // Make sure the recipient is valid
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient);
-               // @TODO Add more checks on data
-               assert($recipient == NetworkPackageHandler::NETWORK_TARGET_SELF);
+       public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
 
                // Determine IP or 'external_address' if set
                $unl = HubTools::determineOwnExternalAddress();
 
                // Is it not empty?
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: unl=' . $unl);
                if (!empty($unl)) {
                        // Add it to the list
                        $listInstance->addEntry('unl', $unl);
                } // END - if
+
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: EXIT!');
        }
 
 }
index f0d1f4c3e642360cfe6250f22883a1dcdefed46b..c12a771e7793bd38befd12a3bfbb3c711efbbfe3 100644 (file)
@@ -62,34 +62,40 @@ class UpperRecipient extends BaseRecipient implements Recipient {
         * Tries to resolve given recipient into session ids or Universal Node Locator
         * depending on implementation (hint: Template Method Pattern)
         *
-        * @param       $recipient                      Recipient to resolve (e.g. could be a virtual recipient or direct session id)
-        * @param       $listInstance           An instance of a Listable class
         * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @param       $listInstance           An instance of a Listable class
         * @return      $resolved                       Resolved recipient or VOID if only the set list has been filled
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
         */
-       public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
-               // Make sure the recipient is valid
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: recipient=' . $recipient);
-               assert($recipient == NetworkPackageHandler::NETWORK_TARGET_UPPER);
+       public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
+
+               // Get recipient UNL
+               $recipientUnl = $packageInstance->getRecipientUnl();
+
+               // Check recipient UNL
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: recipientUnl=' . $recipientUnl);
+               assert($recipientUnl == NetworkPackageHandler::NETWORK_TARGET_UPPER);
 
                // Get all bootstrap nodes
                foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) {
                        // Is maximum reached?
                        if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
-                               // Debug message
-                               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
-
                                // Then stop adding more
+                               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
                                break;
                        } // END - if
 
                        // Debug message
-                       /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
+                       /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
 
                        // Add the entry
                        $listInstance->addEntry('unl', $unlData);
                } // END - foreach
+
+               // Trace message
+               /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: EXIT!');
        }
 
 }
index 6e944b1709af3e0e7f7002bf0890a70a90434e6b..d16cfa63ca6b2f89917fe6c5507015167675ccb9 100644 (file)
@@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Registry\Socket;
 // Import application-specific stuff
 use Org\Shipsimu\Hub\Container\Socket\StorableSocket;
 use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory;
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
 use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper;
 use Org\Shipsimu\Hub\Information\ShareableInfo;
 use Org\Shipsimu\Hub\Listener\BaseListener;
index 30584132fc9c79028133bac90246de86b11fe68c..8706dc1eb9d020b686b10d391445aa9181c006b9 100644 (file)
@@ -66,7 +66,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver {
         * Returns an state instance for a given raw package data and socket resource
         *
         * @param       $helperInstance         An instance of a ConnectionHelper class
-        * @param       $packageData            An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @param       $socketInstance         An instance of a StorableSocket class
         * @return      $stateInstance          An instance of the resolved state
         * @throws      InvalidSocketException  If socketResource, even from getSocketResource() is no valid resource
@@ -96,7 +96,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver {
                $errorName = $socketInstance->translateLastSocketErrorCodeToName();
 
                // Create a state instance based on $errorCode. This factory does the hard work for us
-               $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketInstance, $errorName);
+               $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageInstance, $socketInstance, $errorName);
 
                // Return the prepared instance
                return $stateInstance;
index 7079839cc11b2b99824ef1a0bf7bb1ec738cf58a..b348edfaf786cb8066a191681ae23df00504b059 100644 (file)
@@ -86,10 +86,8 @@ class PackageTags extends BaseTag implements Tagable {
         * @return      void
         */
        private function initObjectRegistry () {
-               // Output debug message
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - CALLED!');
-
                // Get the application instance
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - CALLED!');
                $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
 
                // Get a XML template instance
@@ -111,12 +109,13 @@ class PackageTags extends BaseTag implements Tagable {
        /**
         * Extracts the tags from given package data
         *
-        * @param       $packageData    An instance of a DeliverablePackage class
+        * @param       $packageInstance        An instance of a DeliverablePackage class
         * @return      void
         */
        private function extractTagsFromPackageInstance (DeliverablePackage $packageInstance) {
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: packageData=' . print_r($packageData, TRUE));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+               //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: packageInstance' . print_r($packageInstance, TRUE));
 
                /*
                 * We take a look at the tags (in most cases only one is needed) so
@@ -125,6 +124,7 @@ class PackageTags extends BaseTag implements Tagable {
                $contentData = explode(NetworkPackageHandler::PACKAGE_MASK_SEPARATOR, $packageInstance->getPackageContent());
 
                // Get the tags and store them locally
+               //* PRINTR-DIE: */ die(sprintf('[%s:%d]: contentData(%d)=%s', __METHOD__, __LINE__, count($contentData), print_r($contentData, TRUE)));
                $this->setTags(explode(NetworkPackageHandler::PACKAGE_TAGS_SEPARATOR, $contentData[NetworkPackageHandler::INDEX_TAGS]));
        }
 
@@ -140,6 +140,7 @@ class PackageTags extends BaseTag implements Tagable {
         */
        private function verifyAllTags (DeliverablePackage $packageInstance) {
                // Get the registry
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
 
                // "Walk" over all tags
@@ -154,6 +155,8 @@ class PackageTags extends BaseTag implements Tagable {
                         * If it is no array or the array is empty or an entry is missing
                         * the entry is invalid.
                         */
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: entry[]=%s', gettype($entry)));
+                       //* PRINTR-DIE: */ die(sprintf('[%s:%d] entry=%s', __METHOD__, __LINE__, print_r($entry, TRUE)));
                        if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
                                // Invalid entry found
                                throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
@@ -163,6 +166,9 @@ class PackageTags extends BaseTag implements Tagable {
                        $this->lastProtocol      = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
                        $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
                } // END - foreach
+
+               // Trace message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!');
        }
 
        /**
@@ -173,12 +179,14 @@ class PackageTags extends BaseTag implements Tagable {
         */
        public function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance) {
                // Extract the tags
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->extractTagsFromPackageInstance($packageInstance);
 
                // Now we need to verify every single tag
                $this->verifyAllTags($packageInstance);
 
                // Return the last (and only) found protocol (e.g. 'tcp' is very usual)
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: this->lastProtocol=%s - EXIT!', $this->lastProtocol->__toString()));
                return $this->lastProtocol;
        }
 
@@ -191,6 +199,7 @@ class PackageTags extends BaseTag implements Tagable {
         */
        public function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance) {
                // Extract the tags
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString()));
                $this->extractTagsFromPackageInstance($packageInstance);
 
                // Now every single tag needs to be validated
@@ -200,6 +209,7 @@ class PackageTags extends BaseTag implements Tagable {
                $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
 
                // And return the result
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: accepts=%d - EXIT!', $accepts));
                return $accepts;
        }
 
index 3e8d6df18d08fef6deae76e141e59535f2ee90e8..6101c514f1516e81ddca8b5d0ce0963536356f9e 100644 (file)
@@ -119,11 +119,11 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C
                if ($nodeName == self::OBJECT_TYPE_DATA_NAME) {
                        // Output debug message
                        /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.');
-                       $this->objectRegistryInstance->addEntry($nodeName, $characters);
                } // END - if
 
                // Add it to the registry
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!');
+               $this->objectRegistryInstance->addEntry($nodeName, $characters);
        }
 
        /**
index 4b2cf7dfcadcdfc0df0c47dc7da75104bc43564e..b7e79f978f6f09d7515f8b6b8f0501b149854b01 100644 (file)
@@ -2,9 +2,6 @@
 // Own namespace
 namespace Org\Shipsimu\Hub\Peer;
 
-// Import application-specific stuff
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
-
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\FrameworkException;
 
index ecf8aac05c86d60fbc3ada2419157e6cdfc37c12..3da76fa754938d3a3f2578fde7a773aa6c2cc606 100644 (file)
@@ -2,9 +2,6 @@
 // Own namespace
 namespace Org\Shipsimu\Hub\Unl;
 
-// Import application-specific stuff
-use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
-
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\FrameworkException;
 
index 98175d3f66cd2a6ca0abd4e132c720881b12e086..07d03b92a8f5cf7144c8936bcbc1672a11a2ede7 100644 (file)
@@ -35,7 +35,7 @@ interface DiscoverableNodeRecipient extends DiscoverableRecipient {
         * @param       $packageInstance        An instance of a DeliverablePackage class array
         * @return      void
         */
-       function discoverRecipients (DeliverablePackage $packageInstance);
+       function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance);
 
        /**
         * Tries to discover all recipients by given decoded package data.
index 3cdc5a60ea38fc579f7d0134d0c542c04508b503..58840d4e05a4567e4a82f5e16b5ec6957722b4d0 100644 (file)
@@ -36,11 +36,10 @@ interface Recipient extends HubInterface {
         * Tries to resolve given recipient into session ids or Universal Node Locator
         * depending on implementation (hint: Template Method Pattern)
         *
-        * @param       $recipient      Recipient to resolve (e.g. could be a virtual recipient or direct session id)
-        * @param       $listInstance   An instance of a Listable class
         * @param       $packageInstance        An instance of a DeliverablePackage class
+        * @param       $listInstance   An instance of a Listable class
         * @return      $resolved       Resolved recipient or VOID if only the set list has been filled
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
         */
-       function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance);
+       function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance);
 }
diff --git a/core b/core
index e1220edf0b09e635b818aba6465f2b7d47e7d310..b4d42594f7eb8c7f254a14901743ffdef168e84f 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit e1220edf0b09e635b818aba6465f2b7d47e7d310
+Subproject commit b4d42594f7eb8c7f254a14901743ffdef168e84f