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;
*/
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);
* @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;
}
// Valid?
if ($result === TRUE) {
// Set both
- $this->getPackageDataInstance()->setAddress($peerAddress);
- $this->getPackageDataInstance()->setPort($peerPort);
+ $this->setPeerAddress($peerAddress);
+ $this->setPeerPort($peerPort);
} // END - if
// Trace message
// 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;
* @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
$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;
}
*/
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();
// 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;
}
* @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
// 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
// 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;
}
*/
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());
$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!');
}
/**
// 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;
$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);
}
$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);
}
*/
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!');
}
/**
*/
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!');
}
/**
$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!');
}
/**
*/
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();
/*
// 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;
}
$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]);
*/
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');
// 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);
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.
$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;
}
// 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;
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);
// 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
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;
* @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;
}
// 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()));
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;
*/
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
/* 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;
}
/**
* 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);
<?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
// 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;
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);
$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(
$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(
* @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()) {
/**
* 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
}
// 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
$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 ...');
$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
$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);
/*
$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);
/*
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;
$discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
// Discover all recipients, this may throw an exception
- $discoveryInstance->discoverRecipients($packageInstance);
+ $discoveryInstance->discoverRecipientsByPackageInstance($packageInstance);
// Now get an iterator
$iteratorInstance = $discoveryInstance->getIterator();
*/
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));
// 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);
$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,
)
));
- // 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;
}
*/
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);
);
// 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!');
}
/**
*/
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()) {
$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!');
}
/**
// 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]);
$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;
}
// 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;
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
* 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) {
/**
* 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));
//* 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)));
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;
* 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) {
$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);
// 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();
* 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));
}
/**
* @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
// Render the XML content
$templateInstance->renderXmlContent();
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!');
}
/**
*/
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.
$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!');
}
}
//* 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);
/**
* 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.');
} // 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));
/**
* 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) {
/* 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);
}
}
/**
* 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.');
} // 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));
/**
* 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.');
} // 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));
/**
* 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
*/
/**
* 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.');
} // 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));
/**
* 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.');
} // 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));
$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
$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
// Import framework stuff
use Org\Mxchange\CoreFramework\Registry\Registerable;
+// Import SPL stuff
+use \ReflectionClass;
+use \ReflectionProperty;
+
/**
* A DeliverablePackage class for raw package data
*
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;
+ }
+
}
*/
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
*/
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!');
}
/**
* @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;
}
* @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 .
*/
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?
);
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: isProcessed=%d - EXIT!', intval($isProcessed)));
return $isProcessed;
}
*/
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;
}
*/
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
*/
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];
}
*/
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]++;
}
*/
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) -
assert($dataChunkSize > 0);
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d - CALLED!', $dataChunkSize));
return $dataChunkSize;
}
* 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;
}
*/
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!');
}
/**
*/
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
} // 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!');
}
/**
*/
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
);
// 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
array_push($this->chunks[$finalHash] , $rawData);
array_push($this->chunkHashes[$finalHash], $rawDataHash);
}
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!');
}
/**
*/
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!');
}
/**
*/
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);
$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;
}
*/
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
$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;
}
*/
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
// 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(
$this->nextChunkPointer($finalHash);
// Return the chunk array
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Returning rawDataChunk ... - EXIT!');
return $rawDataChunk;
}
*/
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!');
}
}
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;
/**
* "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
*/
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();
/**
* 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');
// 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]));
} // 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!');
}
}
* 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'));
// 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!');
}
}
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;
// Import framework stuff
use Org\Mxchange\CoreFramework\Lists\Listable;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A Self 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!');
}
}
* 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!');
}
}
// 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;
* 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
$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;
* @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
/**
* 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
$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]));
}
*/
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
* 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);
$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!');
}
/**
*/
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;
}
*/
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
$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;
}
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);
}
/**
// 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;
// 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;
* @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.
* 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);
}
-Subproject commit e1220edf0b09e635b818aba6465f2b7d47e7d310
+Subproject commit b4d42594f7eb8c7f254a14901743ffdef168e84f