From b5f7604ee36e6cc5de656493b27b3ce243a9a71d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 26 Oct 2020 11:01:11 +0100 Subject: [PATCH] Continued: - renamed *ByPackageData to *ByPackageInstance - renamed more old-lost remains of $packageData (removed type-unsafe array) with modern and type-safe $packageInstance MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.php | 4 +- .../container/class_BaseHubContainer.php | 4 +- .../socket/class_SocketContainer.php | 6 +- .../frontend/class_BaseHubDatabaseWrapper.php | 4 +- ...odeDistributedHashTableDatabaseWrapper.php | 10 +- .../class_PeerStateLookupDatabaseWrapper.php | 2 +- .../classes/dht/node/class_NodeDhtFacade.php | 9 +- .../protocol/class_ProtocolDiscovery.php | 14 +- .../dht/class_DhtRecipientDiscovery.php | 6 +- .../class_PackageRecipientDiscovery.php | 16 +- .../socket/class_PackageSocketDiscovery.php | 36 +-- .../chain/class_PackageFilterChainFactory.php | 2 +- .../handler/class_ProtocolHandlerFactory.php | 2 +- .../factories/socket/class_SocketFactory.php | 2 +- .../states/peer/class_PeerStateFactory.php | 2 +- .../classes/filter/class_BaseHubFilter.php | 4 +- .../classes/handler/class_BaseHubHandler.php | 4 +- .../package/class_NetworkPackageHandler.php | 205 +++++++++--------- .../ipv4/class_BaseIpV4ProtocolHandler.php | 12 +- .../raw_data/class_BaseRawDataHandler.php | 6 +- .../ipv4/tcp/class_TcpConnectionHelper.php | 12 +- .../classes/listener/class_BaseListener.php | 2 +- .../listener/class_BaseListenerDecorator.php | 2 +- .../hub/classes/nodes/class_BaseHubNode.php | 12 +- .../package/deliverable/class_PackageData.php | 54 ++++- .../fragmenter/class_PackageFragmenter.php | 6 +- .../recipient/dht/class_DhtRecipient.php | 2 +- .../registry/socket/class_SocketRegistry.php | 2 +- .../tags/package/class_PackageTags.php | 2 +- .../class_XmlObjectRegistryTemplateEngine.php | 2 +- ...class_UnexpectedPackageStatusException.php | 4 +- .../unl/class_InvalidUnlException.php | 2 +- .../hub/interfaces/class_HubInterface.php | 2 +- .../dht/class_DiscoverableDhtRecipient.php | 2 +- .../distributable/class_Distributable.php | 2 +- .../protocol/class_HandleableProtocol.php | 2 +- .../peer_states/class_LookupablePeerState.php | 2 +- 37 files changed, 254 insertions(+), 208 deletions(-) diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index c20c6f96a..8857121af 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -313,7 +313,7 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * @param $privateKeyHash The new private key hash * @return void */ - protected final function setPrivateKeyHash ($privateKeyHash) { + protected final function setNodePrivateKeyHash ($privateKeyHash) { // Set it config now $this->getConfigInstance()->setConfigEntry('private_key_hash', (string) $privateKeyHash); } @@ -323,7 +323,7 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * * @return $privateKeyHash Current private key hash */ - public final function getPrivateKeyHash () { + public final function getNodePrivateKeyHash () { // Get it from config return $this->getConfigInstance()->getConfigEntry('private_key_hash'); } diff --git a/application/hub/classes/container/class_BaseHubContainer.php b/application/hub/classes/container/class_BaseHubContainer.php index 284d82d64..53fa4b479 100644 --- a/application/hub/classes/container/class_BaseHubContainer.php +++ b/application/hub/classes/container/class_BaseHubContainer.php @@ -213,7 +213,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { * @param $privateKeyHash The new private key hash * @return void */ - protected final function setPrivateKeyHash ($privateKeyHash) { + protected final function setNodePrivateKeyHash ($privateKeyHash) { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } @@ -222,7 +222,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { * * @return $privateKeyHash Current private key hash */ - public final function getPrivateKeyHash () { + public final function getNodePrivateKeyHash () { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index 3e8987eaf..5ef1b3cb0 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -182,7 +182,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: unl=' . $unl . ',packageInstance=' . print_r($packageInstance, true)); // So, does both match? - $matches = (($packageInstance->getRecipient() !== '') && ($packageInstance->getRecipient() === $unl)); + $matches = (($packageInstance->getRecipientType() !== '') && ($packageInstance->getRecipientType() === $unl)); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: matches=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($matches))); @@ -346,10 +346,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita $packageInstance = $this->getPackageDataInstance(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: packageInstance.recipient=%s - EXIT!', strtoupper($this->getSocketProtocol()), $packageInstance->getRecipient())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: packageInstance.recipient=%s - EXIT!', strtoupper($this->getSocketProtocol()), $packageInstance->getRecipientType())); // Return it - return $packageInstance->getRecipient(); + return $packageInstance->getRecipientType(); } /** diff --git a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php index 3aa5e7ce0..f776e8091 100644 --- a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php @@ -212,7 +212,7 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub * @param $privateKeyHash The new private key hash * @return void */ - protected final function setPrivateKeyHash ($privateKeyHash) { + protected final function setNodePrivateKeyHash ($privateKeyHash) { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } @@ -221,7 +221,7 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub * * @return $privateKeyHash Current private key hash */ - public final function getPrivateKeyHash () { + public final function getNodePrivateKeyHash () { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php index 1248ffa62..752efd55b 100644 --- a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -193,7 +193,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $externalUnl); $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); - $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash()); + $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())); @@ -312,10 +312,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp * @return $nodeData Node data array */ public function findNodeLocalBySessionId ($sessionId) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: sessionId=' . $sessionId . ' - CALLED!'); - // Get search criteria + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: sessionId=' . $sessionId . ' - CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for session id and limit it to one entry @@ -325,10 +323,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp // Query database and get a result instance back $resultInstance = $this->doSelectByCriteria($searchInstance); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!'); - // Return result instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!'); return $resultInstance; } diff --git a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php index 32acb0e42..a5c7c918b 100644 --- a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php @@ -140,7 +140,7 @@ class PeerStateLookupDatabaseWrapper extends BaseHubDatabaseWrapper implements L * @return void * @throws PeerAlreadyRegisteredException If a peer is already registered */ - public function registerPeerByPackageData (DeliverablePackage $packageInstance, StorableSocket $socketInstance) { + public function registerPeerByPackageInstance (DeliverablePackage $packageInstance, StorableSocket $socketInstance) { // Make sure only new peers can be registered with package data if (!$this->isSenderNewPeer($packageInstance)) { // Throw an exception because this should normally not happen diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index 236933dd9..cb66fa372 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -145,6 +145,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { */ public function findNodeLocalBySessionId ($sessionId) { // Default is empty data array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FACADE: sessionid=%s - CALLED!', $sessionId)); $nodeData = array(); /* @@ -166,6 +167,8 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { } // END - if // 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))); return $nodeData; } @@ -333,12 +336,12 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { /** * Find recipients for given package data * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $recipients An indexed array with DHT recipients */ - public function findRecipientsByPackageData (DeliverablePackage $packageInstance) { + public function findRecipientsByPackageInstance (DeliverablePackage $packageInstance) { // Query get a result instance back from DHT database wrapper. - $resultInstance = $this->getWrapperInstance()->getResultFromExcludedSender($packageData); + $resultInstance = $this->getWrapperInstance()->getResultFromExcludedSender($packageInstance); // Make sure the result instance is valid assert($resultInstance instanceof SearchableResult); diff --git a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php index 348956f30..333320336 100644 --- a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php +++ b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php @@ -60,10 +60,10 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco /** * Determines the protoctol name * - * @param $packageData Valid package data + * @param $packageInstance An instance of a DeliverablePackage class * @return $protocolInstance An instance of a HandleableProtocol class */ - public static final function determineProtocolByPackageData (DeliverablePackage $packageInstance) { + public static final function determineProtocolByPackageInstance (DeliverablePackage $packageInstance) { // First we need a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); @@ -74,7 +74,7 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco * and if so we can re-use it. If there is no socket registered, we try * to make a new connection to the given Universal Node Locator. */ - $protocolInstance = $tagsInstance->chooseProtocolFromPackageInstance($packageData); + $protocolInstance = $tagsInstance->chooseProtocolFromPackageInstance($packageInstance); // Return it return $protocolInstance; @@ -84,17 +84,17 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco * "Discovers" the protocol type from given raw package data. This is done * by looking at the 'recipient' field and extract the first part from it. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections */ - public static final function discoverProtocolByPackageData (DeliverablePackage $packageInstance) { - //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + public static final function discoverProtocolByPackageInstance (DeliverablePackage $packageInstance) { + //* DEBUG: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE)); /* * "Explode" the 'recipient' array element into a new one, giving at * least two entries: protocol://address */ - $recipient = explode(':', $packageInstance->getRecipient()); + $recipient = explode(':', $packageInstance->getRecipientType()); // At least 2 entries must be found assert(count($recipient) >= 2); diff --git a/application/hub/classes/discovery/recipient/dht/class_DhtRecipientDiscovery.php b/application/hub/classes/discovery/recipient/dht/class_DhtRecipientDiscovery.php index 54dfe716b..56247a9f0 100644 --- a/application/hub/classes/discovery/recipient/dht/class_DhtRecipientDiscovery.php +++ b/application/hub/classes/discovery/recipient/dht/class_DhtRecipientDiscovery.php @@ -59,12 +59,12 @@ class DhtRecipientDiscovery extends BaseRecipientDiscovery implements Discoverab /** * Resolves one or more recipients for a DHT transfer by given package data. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $recipients An indexed array with DHT recipients */ - public function resolveRecipientsByPackageData (DeliverablePackage $packageInstance) { + public function resolveRecipientsByPackageInstance (DeliverablePackage $packageInstance) { // Use facade to get recipients back - $recipients = DhtObjectFactory::createDhtInstance('node')->findRecipientsByPackageData($packageData); + $recipients = DhtObjectFactory::createDhtInstance('node')->findRecipientsByPackageInstance($packageInstance); // Return it return $recipients; diff --git a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php index 8213e6193..881e99ab5 100644 --- a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php +++ b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -66,7 +66,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov /** * Tries to discover all recipients for given package data * - * @param $packageData An instance of a DeliverablePackage class array + * @param $packageInstance An instance of a DeliverablePackage class array * @return void */ public function discoverRecipients (DeliverablePackage $packageInstance) { @@ -80,16 +80,16 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov * recipient must be direct recipient then, otherwise a "virtual" * recipient. */ - if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipient())) { + if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientType())) { // Get instance (should not break) $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class'); } else { // Try to find the right class - $recipientInstance = ObjectFactory::createObjectByConfiguredName(strtolower($packageInstance->getRecipient()) . '_recipient_class'); + $recipientInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_recipient_class', strtolower($packageInstance->getRecipientType()))); } // Try to solve it - $recipientInstance->resolveRecipient($packageInstance->getRecipient(), $this->getListInstance(), $packageData); + $recipientInstance->resolveRecipient($packageInstance->getRecipientType(), $this->getListInstance(), $packageInstance); } 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())); @@ -112,7 +112,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance); // Is the 'recipient' field same as this peer's IP? - if ($handlerInstance->isOwnAddress($packageInstance->getRecipient())) { + if ($handlerInstance->isOwnAddress($packageInstance->getRecipientType())) { /* * Is same as own external address + TCP/UDP listen port or * internal address, don't do anything here so other classes found @@ -121,13 +121,13 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov */ // Debug output (may flood) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipient() . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientType() . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')'); } else { // Debug output (may flood) - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipient() . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientType() . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!'); // This package is to be delivered to someone else, so add it - // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $packageInstance->getRecipient()); + // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $packageInstance->getRecipientType()); } } diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index bf2fac542..1384a7111 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -78,7 +78,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * Tries to dicover the right listener instance * * @param $protocolInstance An instance of a HandleableProtocol class - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $listenerInstance An instance of a Listenable instance or null */ public function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance) { @@ -117,10 +117,10 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera assert($listenerInstance instanceof Listenable); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: Calling listenerInstance->ifListenerAcceptsPackageData(%d) ...', count($packageData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: Calling listenerInstance->ifListenerAcceptsPackageData(%s) ...', $packageInstance->__toString())); // Does the listener want that package? - if ($listenerInstance->ifListenerAcceptsPackageData($packageData)) { + if ($listenerInstance->ifListenerAcceptsPackageData($packageInstance)) { // This listener likes our package data, so abort here /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: Listener "%s" is accepting package data.', $listenerInstance->__toString())); break; @@ -141,7 +141,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * Tries to discover the right socket for given package data and returns a * matching socket resource for that protocol. * - * @param $packageData An instance of a DeliverablePackage class array + * @param $packageInstance An instance of a DeliverablePackage class array * @param $connectionType Type of connection, can be either 'incoming' or 'outgoing', but *NEVER* 'server'! * @return $socketResource A valid socket resource or FALSE if an error occured * @throws NoListGroupException If the procol group is not found in peer list @@ -152,8 +152,8 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera */ public function discoverSocket (DeliverablePackage $packageInstance, $connectionType) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageData()=' . count($packageData) . ',connectionType=' . $connectionType . ' - CALLED!'); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageData=' . print_r($packageData, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISOVERY: packageInstance=%s,connectionType=%s - CALLED!', $packageInstance->__toString(), $connectionType)); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageInstance=' . print_r($packageInstance, TRUE)); // Make sure all parameters are valid if (($connectionType != StorableSocket::CONNECTION_TYPE_INCOMING) && ($connectionType != StorableSocket::CONNECTION_TYPE_OUTGOING)) { @@ -162,25 +162,25 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera } // END - if // Determine protocol instance - $protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData); + $protocolInstance = ProtocolDiscovery::determineProtocolByPackageInstance($packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageInstance=' . print_r($packageInstance, TRUE)); // Is it valid? assert($protocolInstance instanceof HandleableProtocol); // Does the UNL validate? - if (!$protocolInstance->isValidUniversalNodeLocatorByPackageData($packageData)) { + if (!$protocolInstance->isValidUniversalNodeLocatorByPackageInstance($packageInstance)) { // Not valid, throw exception - throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL); + throw new InvalidUnlException(array($this, $protocolInstance, $packageInstance), BaseHubSystem::EXCEPTION_INVALID_UNL); } // END - if // Get the listener instance - $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData); + $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance . ',packageData=' . print_r($packageData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance . ',packageInstance=' . print_r($packageInstance, TRUE)); // If there is no listener who wants to have that package, we simply drop it here if (is_null($listenerInstance)) { @@ -197,7 +197,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * instance and pass over the whole package data to get the right * socket. */ - $socketInstance = $listenerInstance->getPoolInstance()->getSocketFromPackageInstance($packageData, $connectionType); + $socketInstance = $listenerInstance->getPoolInstance()->getSocketFromPackageInstance($packageInstance, $connectionType); // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: socketInstance[]=%s', gettype($socketInstance))); @@ -207,10 +207,10 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera // Try to create a new socket resource try { // Possibly noisy debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance->getProtocolName()) . ' connection to ' . $packageInstance->getRecipient() . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance->getProtocolName()) . ' connection to ' . $packageInstance->getRecipientType() . ' ...'); // Get a socket resource from our factory (if succeeded) - $socketInstance = SocketFactory::createSocketFromPackageInstance($packageData, $protocolInstance); + $socketInstance = SocketFactory::createSocketFromPackageInstance($packageInstance, $protocolInstance); } catch (SocketConnectionException $e) { // The connection fails of being established, so log it away self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); @@ -226,17 +226,17 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...'); // Resolve the peer's state (but ignore return value) - PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketInstance); + PeerStateResolver::resolveStateByPackage($helperInstance, $packageInstance, $socketInstance); } catch (InvalidSocketException $e) { // This cannot be fixed, so log it away - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageInstance->getRecipient() . ': ' . $e->getMessage()); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageInstance->getRecipientType() . ': ' . $e->getMessage()); // Make any failed attempts to 'FALSE' $socketInstance = NULL; } // And return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: socketResource=' . $socketInstance->getSocketResource() . ',packageData=' . print_r($packageData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: socketResource=' . $socketInstance->getSocketResource() . ',packageInstance=' . print_r($packageInstance, TRUE)); return $socketInstance; } diff --git a/application/hub/classes/factories/chain/class_PackageFilterChainFactory.php b/application/hub/classes/factories/chain/class_PackageFilterChainFactory.php index 76f5e5d30..72d027f51 100644 --- a/application/hub/classes/factories/chain/class_PackageFilterChainFactory.php +++ b/application/hub/classes/factories/chain/class_PackageFilterChainFactory.php @@ -65,7 +65,7 @@ class PackageFilterChainFactory extends ObjectFactory { * simply means the tag is not valid. This however should be * handled some calls before this method is called. */ - $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter_class'); + $filterInstance = self::createObjectByConfiguredName(sprintf('package_tag_%s_filter_class', $tag)); // Add this filter to the chain $chainInstance->addFilter($filterInstance); diff --git a/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php b/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php index 01cc53722..13398f47b 100644 --- a/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php +++ b/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php @@ -92,7 +92,7 @@ class ProtocolHandlerFactory extends ObjectFactory { */ public static final function createProtocolHandlerFromPackageInstance (DeliverablePackage $packageInstance) { // "Discover" the protocol type - $protocolType = ProtocolDiscovery::discoverProtocolByPackageData($packageData); + $protocolType = ProtocolDiscovery::discoverProtocolByPackageInstance($packageData); // Call super factory method return self::createProtocolHandlerByType($protocolType); diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index eb0c684cb..3532935b4 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -68,7 +68,7 @@ class SocketFactory extends ObjectFactory { $socketInstance = NULL; // Construct registry key - $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageInstance->getRecipient(); + $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageInstance->getRecipientType(); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey); diff --git a/application/hub/classes/factories/states/peer/class_PeerStateFactory.php b/application/hub/classes/factories/states/peer/class_PeerStateFactory.php index f96bcf451..0f2f95d37 100644 --- a/application/hub/classes/factories/states/peer/class_PeerStateFactory.php +++ b/application/hub/classes/factories/states/peer/class_PeerStateFactory.php @@ -102,7 +102,7 @@ class PeerStateFactory extends ObjectFactory { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: errorCode=' . $errorCode); // Register the new peer with its session id - $tableInstance->registerPeerByPackageData($packageData, $socketInstance); + $tableInstance->registerPeerByPackageInstance($packageData, $socketInstance); /* * It is a new peer so create the state instance based on error diff --git a/application/hub/classes/filter/class_BaseHubFilter.php b/application/hub/classes/filter/class_BaseHubFilter.php index dccea157d..6ba29c1de 100644 --- a/application/hub/classes/filter/class_BaseHubFilter.php +++ b/application/hub/classes/filter/class_BaseHubFilter.php @@ -74,7 +74,7 @@ abstract class BaseHubFilter extends BaseFilter { assert(isset($messageData[NetworkPackageHandler::PACKAGE_CONTENT_TAGS])); // Get a template instance from the factory - $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_' . $messageType . '_template_class'); + $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance(sprintf('node_%s_template_class', $messageType)); // Get message content $messageContent = $messageData[NetworkPackageHandler::PACKAGE_CONTENT_MESSAGE]; @@ -90,7 +90,7 @@ abstract class BaseHubFilter extends BaseFilter { * variables, so simply get them. If there is an invalid XML node * inside the message, the above method call will cause exceptions. */ - foreach ($this->dataXmlNodes as $key => $dummy) { + foreach (array_keys($this->dataXmlNodes) as $key) { // Call it $value = $templateInstance->readXmlData($key); diff --git a/application/hub/classes/handler/class_BaseHubHandler.php b/application/hub/classes/handler/class_BaseHubHandler.php index ed4fd0240..e861c610d 100644 --- a/application/hub/classes/handler/class_BaseHubHandler.php +++ b/application/hub/classes/handler/class_BaseHubHandler.php @@ -226,7 +226,7 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte * @param $privateKeyHash The new private key hash * @return void */ - protected final function setPrivateKeyHash ($privateKeyHash) { + protected final function setNodePrivateKeyHash ($privateKeyHash) { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } @@ -235,7 +235,7 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte * * @return $privateKeyHash Current private key hash */ - public final function getPrivateKeyHash () { + public final function getNodePrivateKeyHash () { throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 076b9c23f..3416e41b4 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -14,6 +14,7 @@ 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; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; @@ -403,7 +404,8 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $dhtInstance = DhtObjectFactory::createDhtInstance('node'); // Ask DHT for session id - $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getContentSender()); + /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderId=%s ...', $packageInstance->getSenderId())); + $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderId()); // Debugging: //* DEBUG-DIE: */ die(sprintf('[%s:%d]: senderData=%s', __METHOD__, __LINE__, print_r($senderData, TRUE))); @@ -411,13 +413,13 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Is an entry found? if (count($senderData) > 0) { // Make sure the element 'private_key_hash' is there - //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: senderData=' . print_r($senderData, TRUE)); + //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderData=' . print_r($senderData, TRUE)); assert(isset($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH])); // Don't accept empty hashes if (empty($senderData[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH])) { // Don't accept - throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in senderData'), self::EXCEPTION_INVALID_PRIVATE_KEY_HASH); + throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in senderData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH); } // END - if // Return it @@ -425,13 +427,13 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei } // END - if // Don't accept empty keys - if (empty($packageInstance->getContentPrivateKeyHash())) { + if (empty($packageInstance->getSenderPrivateKeyHash())) { // This needs fixing - throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), self::EXCEPTION_INVALID_PRIVATE_KEY_HASH); + throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH); } // END - if // There is no DHT entry so, accept the hash from decoded data - return $packageInstance->getContentPrivateKeyHash(); + return $packageInstance->getSenderPrivateKeyHash(); } /** @@ -442,7 +444,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private function getHashFromContent ($content) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); // Create the hash // @TODO md5() is very weak, but it needs to be fast @@ -455,7 +457,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei ); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); // And return it return $hash; @@ -516,7 +518,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function getHashFromContentSessionId (array $decodedContent, $sessionId) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_EXTENSION]); // Create the hash // @TODO md5() is very weak, but it needs to be fast @@ -539,7 +541,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei /** * Declares the given An instance of a DeliverablePackage class by discovering recipients * - * @param $packageData An instance of a DeliverablePackage class in an array + * @param $packageInstance An instance of a DeliverablePackage class in an array * @return void */ private function declareRawPackageData (DeliverablePackage $packageInstance) { @@ -552,7 +554,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance(); // Discover all recipients, this may throw an exception - $discoveryInstance->discoverRecipients($packageData); + $discoveryInstance->discoverRecipients($packageInstance); // Now get an iterator $iteratorInstance = $discoveryInstance->getIterator(); @@ -569,16 +571,16 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $currentRecipient = $iteratorInstance->current(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Setting recipient to ' . $currentRecipient . ',previous=' . packageInstance->getRecipient()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Setting recipient to ' . $currentRecipient . ',previous=' . $packageInstance->getRecipientType()); // Set the recipient $packageInstance->setRecipient($currentRecipient); // Push the declared package to the next stack. - $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData); + $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Package declared for recipient ' . $currentRecipient); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package declared for recipient ' . $currentRecipient); // Skip to next entry $iteratorInstance->next(); @@ -598,12 +600,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * the package), register the socket with the connection (handler/helper?) * instance and finally push the raw data on our outgoing queue. * - * @param $packageData An instance of a DeliverablePackage class in an array + * @param $packageInstance An instance of a DeliverablePackage class in an array * @return void */ private function deliverRawPackageData (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: packageData()=%d - CALLED!', count($packageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); /* * This package may become big, depending on the shared object size or @@ -620,16 +622,16 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $discoveryInstance = SocketDiscoveryFactory::createSocketDiscoveryInstance(); // Now discover the right socket instance from given package data - $socketInstance = $discoveryInstance->discoverSocket($packageData, StorableSocket::CONNECTION_TYPE_OUTGOING); + $socketInstance = $discoveryInstance->discoverSocket($packageInstance, StorableSocket::CONNECTION_TYPE_OUTGOING); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); // Get the connection helper from registry $helperInstance = GenericRegistry::getRegistry()->getInstance('connection'); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: stateInstance=' . $helperInstance->getStateInstance()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: stateInstance=' . $helperInstance->getStateInstance()); // And make sure it is valid assert($helperInstance instanceof ConnectionHelper); @@ -641,54 +643,54 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $infoInstance->fillWithConnectionHelperInformation($helperInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); // Is it not there? if (($socketInstance->isValidSocket()) && (!$this->getRegistryInstance()->isSocketRegistered($infoInstance, $socketInstance))) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Registering socket ' . $socketInstance . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Registering socket ' . $socketInstance . ' ...'); // Then register it $this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance); } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) { // Is not connected, then we cannot send - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); // Shutdown the socket $socketInstance->shutdownSocket(); } // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); // Make sure the connection is up $helperInstance->getStateInstance()->validatePeerStateConnected(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); // Enqueue it again on the out-going queue, the connection is up and working at this point - $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData); + $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); } /** * Sends waiting packages * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return void */ private function sendOutgoingRawPackageData (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: packageData()=%d - CALLED!', count($packageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Init sent bytes $sentBytes = 0; // Get the right connection instance - $infoInstance = $this->getRegistryInstance()->getInfoInstanceFromPackageInstance($packageData); + $infoInstance = $this->getRegistryInstance()->getInfoInstanceFromPackageInstance($packageInstance); // Test helper instance assert($infoInstance instanceof ShareableInfo); @@ -709,10 +711,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei } // END - if // Sent out package data - $helperInstance->sendRawPackageData($packageData); + $helperInstance->sendRawPackageData($packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -724,7 +726,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private function generatePackageHash ($content, $senderId) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: 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)); @@ -733,33 +735,30 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Is the feature enabled? if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { // Feature is not enabled - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: 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 = new NetworkPackageHandler(); + $packageInstance = PackageDataFactory::createPackageDataInstance(); // Set all fields - //$packageInstance->set - $data = array( - self::PACKAGE_CONTENT_SENDER => $senderId, - self::PACKAGE_CONTENT_MESSAGE => $content, - self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $this->getNodeInstance()->getPrivateKeyHash(), - ); + $packageInstance->setSenderId($senderId); + $packageInstance->setPackageContent($content); + $packageInstance->setSenderPrivateKeyHash($this->getNodeInstance()->getNodePrivateKeyHash()); // Hash content and sender id together, use scrypt - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: 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, $content, - $this->determineSenderPrivateKeyHash($data) + $this->determineSenderPrivateKeyHash($packageInstance) ) )); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: hash=' . $hash . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: hash=' . $hash . ' - EXIT!'); // Return it return $hash; @@ -775,7 +774,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private function isPackageHashValid (array $decodedArray) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: decodedArray=' . print_r($decodedArray, TRUE) . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: decodedArray=' . print_r($decodedArray, TRUE) . ' - CALLED!'); // Make sure the required array elements are there assert(isset($decodedArray[self::PACKAGE_CONTENT_SENDER])); @@ -786,17 +785,17 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Is the feature enabled? if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { // Feature is not enabled, so hashes are always valid - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Feature "hubcoin_reward" not available, not checking hash. Returning TRUE ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Feature "hubcoin_reward" not available, not checking hash. Returning TRUE ...'); return TRUE; } // END - if // Check validity - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',message()=' . strlen($decodedArray[self::PACKAGE_CONTENT_MESSAGE]) . ',hash=' . $decodedArray[self::PACKAGE_CONTENT_HASH]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderId=' . $decodedArray[self::PACKAGE_CONTENT_SENDER] . ',message()=' . strlen($decodedArray[self::PACKAGE_CONTENT_MESSAGE]) . ',hash=' . $decodedArray[self::PACKAGE_CONTENT_HASH]); //* DEBUG-DIE: */ die(__METHOD__ . ': decodedArray=' . print_r($decodedArray, TRUE)); $isHashValid = FrameworkFeature::callFeature('hubcoin_reward', 'checkHash', array($decodedArray[self::PACKAGE_CONTENT_SENDER] . ':' . $decodedArray[self::PACKAGE_CONTENT_MESSAGE] . ':' . $this->determineSenderPrivateKeyHash($decodedArray), $decodedArray[self::PACKAGE_CONTENT_HASH])); // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: isHashValid=' . intval($isHashValid) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: isHashValid=' . intval($isHashValid) . ' - EXIT!'); return $isHashValid; } @@ -810,7 +809,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function enqueueRawDataFromTemplate (HubHelper $helperInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -838,7 +837,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei ); // Make sure required data is there - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: 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() != ''); @@ -852,14 +851,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setPackageContent($packageContent); $packageInstance->setStatus(self::PACKAGE_STATUS_NEW); $packageInstance->setContentHash($this->generatePackageHash($content, $this->getNodeInstance()->getSessionId())); - $packageInstance->setPrivateKeyHash($this->getNodeInstance()->getPrivateKeyHash()); + $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: 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: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -869,7 +868,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isPackageEnqueued () { // Check whether the stacker is not empty - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); $isEnqueued = ( ($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)) @@ -877,7 +876,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Return the result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isEnqueued=%d - EXIT!', intval($isEnqueued))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isEnqueued=%d - EXIT!', intval($isEnqueued))); return $isEnqueued; } @@ -888,14 +887,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isPackageDeclared () { // Check whether the stacker is not empty - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); $isDeclared = ( ($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECLARED)) ); // Return the result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isDeclared=%d - EXIT!', intval($isDeclared))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isDeclared=%d - EXIT!', intval($isDeclared))); return $isDeclared; } @@ -906,11 +905,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isPackageWaitingForDelivery () { // Check whether the stacker is not empty - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); $isWaitingDelivery = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING))); // Return the result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isWaitingDelivery=%d - EXIT!', intval($isWaitingDelivery))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isWaitingDelivery=%d - EXIT!', intval($isWaitingDelivery))); return $isWaitingDelivery; } @@ -921,11 +920,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isEncodedDataPending () { // Check whether the stacker is not empty - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); $isPending = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING_STREAM)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING_STREAM))); // Return the result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isPending=%d - EXIT!', intval($isPending))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isPending=%d - EXIT!', intval($isPending))); return $isPending; } @@ -941,12 +940,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function declareEnqueuedPackage () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: 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()) { // This is not fatal but should be avoided - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: No raw package data waiting declaration, but ' . __METHOD__ . ' has been called!'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: No raw package data waiting declaration, but ' . __METHOD__ . ' has been called!'); return; } // END - if @@ -954,13 +953,13 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * Now there are for sure packages to deliver, so start with the first * one. */ - $packageData = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED); + $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED); // Declare the raw package data for delivery - $this->declareRawPackageData($packageData); + $this->declareRawPackageData($packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -972,12 +971,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function processDeclaredPackage () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Sanity check if we have packages declared if (!$this->isPackageDeclared()) { // This is not fatal but should be avoided - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: No package has been declared, but ' . __METHOD__ . ' has been called!'); return; } // END - if @@ -993,14 +992,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED); } catch (UnexpectedStateException $e) { // The state is not excepected (shall be 'connected') - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); // Mark the package with status failed $this->changePackageStatus($packageInstance, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED); } // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -1010,12 +1009,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function sendWaitingPackage () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Sanity check if we have packages waiting for delivery if (!$this->isPackageWaitingForDelivery()) { // This is not fatal but should be avoided - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); return; } // END - if @@ -1030,14 +1029,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getStackInstance()->popNamed(self::STACKER_NAME_OUTGOING); } catch (InvalidSocketException $e) { // Output exception message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Package was not delivered: ' . $e->getMessage()); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package was not delivered: ' . $e->getMessage()); // Mark package as failed $this->changePackageStatus($packageInstance, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED); } // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -1047,7 +1046,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function sendEncodedData () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Make sure there is pending encoded data assert($this->isEncodedDataPending()); @@ -1068,7 +1067,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $encodedDataArray[self::RAW_INDEX_SOCKET_INSTANCE] = NULL; // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: Calling socketInstance->writeBufferToSocketByArray(%d,%d) ...', count($encodedDataArray), $sentBytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Calling socketInstance->writeBufferToSocketByArray(%d,%d) ...', count($encodedDataArray), $sentBytes)); // And deliver it if (!$socketInstance->writeBufferToSocketByArray($encodedDataArray, $sentBytes)) { @@ -1077,7 +1076,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei } // END - if // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: sentBytes[%s]=%d', gettype($sentBytes), $sentBytes)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: sentBytes[%s]=%d', gettype($sentBytes), $sentBytes)); // If there was an error, don't continue here if (($sentBytes === 0) && (strlen($encodedDataArray[self::RAW_INDEX_ENCODED_DATA]) > 0)) { @@ -1100,7 +1099,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /////////////////////////////////////////////////////////////////////////// @@ -1114,13 +1113,13 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private function isRawDataPending () { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Just return whether the stack is not empty $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING)); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isPending=%d - EXIT!', intval($isPending))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isPending=%d - EXIT!', intval($isPending))); // Return the status return $isPending; @@ -1133,7 +1132,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isNewRawDataPending () { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: Calling this->getListenerPoolInstance()->accept(%s) ... - CALLED!', $this->getVisitorInstance())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Calling this->getListenerPoolInstance()->accept(%s) ... - CALLED!', $this->getVisitorInstance())); // Visit the pool. This monitors the pool for incoming raw data. $this->getListenerPoolInstance()->accept($this->getVisitorInstance()); @@ -1142,7 +1141,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $hasArrived = $this->isRawDataPending(); // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: hasArrived=%d - EXIT!', intval($hasArrived))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hasArrived=%d - EXIT!', intval($hasArrived))); // Return the status return $hasArrived; @@ -1162,12 +1161,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ if (!$this->isRawDataPending()) { // This is not fatal but should be avoided - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: No raw (decoded?) data is pending, but ' . __METHOD__ . ' has been called!'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: No raw (decoded?) data is pending, but ' . __METHOD__ . ' has been called!'); return; } // END - if // Very noisy debug message: - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Stacker size is ' . $this->getStackInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Stacker size is ' . $this->getStackInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); // "Pop" the next entry (the same array again) from the stack $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING); @@ -1177,14 +1176,14 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * only want to handle unhandled packages here. */ // Remove the last chunk SEPARATOR (because there is no need for it) - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: errorCode=' . $packageInstance->getErrorCode() . '(' . StorableSocket::SOCKET_ERROR_UNHANDLED . ')'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: errorCode=' . $packageInstance->getErrorCode() . '(' . StorableSocket::SOCKET_ERROR_UNHANDLED . ')'); if (substr($packageInstance->getRawData(), -1, 1) == PackageFragmenter::CHUNK_SEPARATOR) { // It is there and should be removed $packageInstance->setRawData(substr($packageInstance->getRawData(), 0, -1)); } // END - if // This package is "handled" and can be pushed on the next stack - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Pushing ' . strlen($packageInstance->getRawData()) . ' bytes to stack ' . self::STACKER_NAME_DECODED_HANDLED . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Pushing ' . strlen($packageInstance->getRawData()) . ' bytes to stack ' . self::STACKER_NAME_DECODED_HANDLED . ' ...'); $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_HANDLED, $packageInstance); } @@ -1202,7 +1201,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance = $handlerInstance->getNextRawData(); // Very noisy debug message: - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($packageInstance) . ']=' . print_r($packageInstance, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: decodedData[' . gettype($packageInstance) . ']=' . print_r($packageInstance, TRUE)); // And push it on our stack $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $packageInstance); @@ -1255,7 +1254,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function handleAssemblerPendingData () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Calling this->getAssemblerInstance()->handlePendingData() ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Calling this->getAssemblerInstance()->handlePendingData() ...'); // Handle it $this->getAssemblerInstance()->handlePendingData(); @@ -1268,7 +1267,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function handleMultipleMessages () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Calling this->getAssemblerInstance()->handleMultipleMessages() ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Calling this->getAssemblerInstance()->handleMultipleMessages() ...'); // Handle it $this->getAssemblerInstance()->handleMultipleMessages(); @@ -1302,7 +1301,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_HANDLED); // ... and push it on the 'chunked' stacker - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: Pushing ' . strlen($packageContent[HandleableRawData::PACKAGE_RAW_DATA]) . ' bytes on stack ' . self::STACKER_NAME_DECODED_CHUNKED . ',packageContent=' . print_r($packageContent, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Pushing ' . strlen($packageContent[HandleableRawData::PACKAGE_RAW_DATA]) . ' bytes on stack ' . self::STACKER_NAME_DECODED_CHUNKED . ',packageContent=' . print_r($packageContent, TRUE)); $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECODED_CHUNKED, $packageContent); } @@ -1314,7 +1313,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function accept (Visitor $visitorInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: ' . $visitorInstance->__toString() . ' has visited - CALLED!'); // Visit the package $visitorInstance->visitNetworkPackageHandler($this); @@ -1323,7 +1322,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getAssemblerInstance()->accept($visitorInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: ' . $visitorInstance->__toString() . ' has visited - EXIT!'); } /** @@ -1336,7 +1335,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->initStacks(TRUE); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: All stacker have been re-initialized.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: All stacker have been re-initialized.'); } /** @@ -1349,7 +1348,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function removeFirstFailedPackage () { // Get the package again - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); $packageInstance = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED); // Is the package status 'failed'? @@ -1362,7 +1361,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $this->getStackInstance()->popNamed(self::STACKER_NAME_DECLARED); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -1373,11 +1372,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function decodeRawContent ($rawPackageContent) { // Use the separator '#' to "decode" it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent))); $decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: decodedArray=' . print_r($decodedArray, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: decodedArray=' . print_r($decodedArray, TRUE)); // Assert on count (should be always 3) assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE); @@ -1392,10 +1391,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setPackageContent($decodedArray[self::INDEX_PACKAGE_CONTENT]); $packageInstance->setStatus(self::PACKAGE_STATUS_DECODED); $packageInstance->setContentHash($decodedArray[self::INDEX_PACKAGE_HASH]); - $packageInstance->setPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]); + $packageInstance->setSenderPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]); // And return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: packageInstance=%s - EXIT!', $packageInstance->__toString())); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString())); return $packageInstance; } @@ -1413,7 +1412,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * details of the array elements, see comments for constant * PACKAGE_MASK. */ - $decodedContent = explode(self::PACKAGE_MASK_SEPARATOR, $packageInstance->getContent()); + $decodedContent = explode(self::PACKAGE_MASK_SEPARATOR, $packageInstance->getPackageContent()); // Assert on array count for a very basic validation assert(count($decodedContent) == self::PACKAGE_CONTENT_ARRAY_SIZE); @@ -1436,7 +1435,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Hash from decoded raw data self::PACKAGE_CONTENT_HASH => $packageInstance->getHash(), // Hash of private key - self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $packageInstance->getPrivateKeyHash() + self::PACKAGE_CONTENT_PRIVATE_KEY_HASH => $packageInstance->getSenderPrivateKeyHash() ); // Is the checksum valid? @@ -1529,7 +1528,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $messageArray[self::MESSAGE_ARRAY_DATA][self::MESSAGE_ARRAY_TYPE] = $messageArray[self::MESSAGE_ARRAY_TYPE]; // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: messageArray=' . print_r($messageArray, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: messageArray=' . print_r($messageArray, TRUE)); // Create a handler instance from given message type $handlerInstance = MessageTypeHandlerFactory::createMessageTypeHandlerInstance($messageArray[self::MESSAGE_ARRAY_TYPE]); @@ -1553,7 +1552,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function feedHashToMiner (array $messageData) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: messageData()=%d - CALLED!', count($messageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: messageData()=%d - CALLED!', count($messageData))); // Is the feature enabled? if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { @@ -1577,7 +1576,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei unset($messageData[self::MESSAGE_ARRAY_DATA]); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: messageData=' . print_r($messageData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: messageData=' . print_r($messageData, TRUE)); // Resolve session id ('sender' is a session id) into node id $nodeId = HubTools::resolveNodeIdBySessionId($messageData[self::MESSAGE_ARRAY_SENDER]); diff --git a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php index 918a40b01..e1de79c23 100644 --- a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php +++ b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php @@ -74,26 +74,26 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler { * Validates given 'recipient' if it is a valid UNL. This means that the UNL * can be parsed by the protocol handler. * - * @param $packageData Valid raw package data + * @param $packageInstance Valid raw package data * @return $isValid Whether the UNL can be validated */ - public function isValidUniversalNodeLocatorByPackageData (DeliverablePackage $packageInstance) { + public function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance) { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: CALLED!'); // Is the correct handler choosen? - assert(substr($packageInstance->getRecipient(), 0, strlen($this->getHandlerName())) != $this->getHandlerName()); + assert(substr($packageInstance->getRecipientType(), 0, strlen($this->getHandlerName())) != $this->getHandlerName()); // Default is from generic validation - $isValid = NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipient()); + $isValid = NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientType()); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: packageInstance.recipient=' . $packageInstance->getRecipient() . ',isValid[' . gettype($isValid) . ']=' . intval($isValid)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: packageInstance.recipient=' . $packageInstance->getRecipientType() . ',isValid[' . gettype($isValid) . ']=' . intval($isValid)); // If this doesn't fail, continue validating the IP:port combination if ($isValid === TRUE) { // ... and validate IP:port, first "parse" the UNL - $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipient()); + $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientType()); // Set whole UNL instance // @TODO don't do this in a isValidFoo() method diff --git a/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php b/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php index d025a7c2e..69f44a6f0 100644 --- a/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php +++ b/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php @@ -139,19 +139,19 @@ abstract class BaseRawDataHandler extends BaseHubHandler implements HandleableRa * Checks whether the 'recipient' field matches our own an universal node * locator. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $matches Whether it matches * @todo This method will be moved to a better place */ protected function ifRecipientMatchesOwnUniversalNodeLocator (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: packageData()=%d - CALLED!', strlen($packageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Construct own address first $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator(); // Does it match? - $matches = ($ownAddress === $packageInstance->getRecipient()); + $matches = ($ownAddress === $packageInstance->getRecipientType()); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: matches=%d - EXIT!', intval($matches))); diff --git a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php index 04f808f7b..68038e271 100644 --- a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php @@ -85,23 +85,23 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection $helperInstance->setHandlerInstance($handlerInstance); } catch (NoValidHostnameException $e) { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageInstance->getRecipient() . ':' . $e->getMessage()); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageInstance->getRecipientType() . ':' . $e->getMessage()); // Is the recipient equal as configured UNL? - if (substr($packageInstance->getRecipient(), 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) { + if (substr($packageInstance->getRecipientType(), 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) { // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address $unlAddress = HubTools::determineExternalAddress(); // Do we have ip:port match? // @TODO Rewrite this test for UNLs - if (strpos($packageInstance->getRecipient(), ':') === FALSE) { + if (strpos($packageInstance->getRecipientType(), ':') === FALSE) { // No ip:port! - $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageInstance->getRecipient())); + $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageInstance->getRecipientType())); } // END - if // "explode" the ip:port, so index 1 will be the port number // @TODO Rewrite this test for UNLs - $recipientArray = explode(':', $packageInstance->getRecipient()); + $recipientArray = explode(':', $packageInstance->getRecipientType()); // Add the port $unlPort = $recipientArray[LocateableNode::UNL_PART_PORT]; @@ -111,7 +111,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection //$unlInstance =; } else { // It doesn't match, we need to take care of this later - $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s!=%s', __METHOD__, __LINE__, $packageInstance->getRecipient(), $helperInstance->getConfigInstance()->getConfigEntry('external_address'))); + $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s!=%s', __METHOD__, __LINE__, $packageInstance->getRecipientType(), $helperInstance->getConfigInstance()->getConfigEntry('external_address'))); } } diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index ad696f9f8..e4baf86c7 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -436,7 +436,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { $socketProtocol = $this->getSocketInstance()->getSocketProtocol(); // Get UNL instance - $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipient()); + $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientType()); // Get protocol from it $unlProtocol = $unlInstance->getUnlProtocol(); diff --git a/application/hub/classes/listener/class_BaseListenerDecorator.php b/application/hub/classes/listener/class_BaseListenerDecorator.php index a7f5f87f2..e4fcb578c 100644 --- a/application/hub/classes/listener/class_BaseListenerDecorator.php +++ b/application/hub/classes/listener/class_BaseListenerDecorator.php @@ -290,7 +290,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $privateKeyHash Current private key hash */ - public function getPrivateKeyHash () { + public function getNodePrivateKeyHash () { $this->partialSub('Please implement this method.'); } diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index c97cf0222..bbe3a881f 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -146,13 +146,13 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC // Hash and encrypt the string so we become a node id (also documented as "hub id") $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString)); - $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey())); + $this->setNodePrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey())); // Register the node id with our wrapper $this->getWrapperInstance()->registerPrivateKey($this, $searchInstance); // Output message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getNodePrivateKeyHash() . ''); } /** @@ -373,10 +373,10 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC } else { // Get the node id from result and set it $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))); - $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH)); + $this->setNodePrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH)); // Output message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . ''); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getNodePrivateKeyHash() . ''); } } else { /* @@ -412,7 +412,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC // Add the private key if acquired if ($this->getPrivateKey() != '') { $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey())); - $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash()); + $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getNodePrivateKeyHash()); } // END - if // Add own external and internal addresses as UNLs @@ -879,7 +879,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC // Add the private key if acquired if ($this->getPrivateKey() != '') { $nodeData[NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY] = base64_encode($this->getPrivateKey()); - $nodeData[NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH] = $this->getPrivateKeyHash(); + $nodeData[NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH] = $this->getNodePrivateKeyHash(); } // END - if // Debugging: diff --git a/application/hub/classes/package/deliverable/class_PackageData.php b/application/hub/classes/package/deliverable/class_PackageData.php index 56bc31ee3..7958b8379 100644 --- a/application/hub/classes/package/deliverable/class_PackageData.php +++ b/application/hub/classes/package/deliverable/class_PackageData.php @@ -47,6 +47,11 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera */ private $senderAddress; + /** + * Sender id + */ + private $senderId; + /** * Sender port */ @@ -62,6 +67,11 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera */ private $status; + /** + * Private key's hash + */ + private $senderPrivateKeyHash; + /** * Protected constructor * @@ -107,22 +117,41 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera /** * Getter for sender address * - * @return $senderAddress Sender address + * @return $senderAddress Sender address */ public function getSenderAddress () { return $this->senderAddress; } /** - * Setter for sender address + * Setter for sender id * - * @param $senderAddress Sender address + * @param $senderAddress Sender id * @return void */ public function setSenderAddress ($senderAddress) { $this->senderAddress = $senderAddress; } + /** + * Getter for sender id + * + * @return $senderId Sender id + */ + public function getSenderId () { + return $this->senderId; + } + + /** + * Setter for sender id + * + * @param $senderId Sender id + * @return void + */ + public function setSenderId ($senderId) { + $this->senderId = $senderId; + } + /** * Getter for sender port * @@ -199,4 +228,23 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera $this->contentHash = $contentHash; } + /** + * Setter for private key hash + * + * @param $senderPrivateKeyHash The new private key hash + * @return void + */ + public final function setSenderPrivateKeyHash ($senderPrivateKeyHash) { + $this->senderPrivateKeyHash = $senderPrivateKeyHash; + } + + /** + * Getter for private key hash + * + * @return $senderPrivateKeyHash Current private key hash + */ + public final function getSenderPrivateKeyHash () { + return $this->senderPrivateKeyHash; + } + } diff --git a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php index 0b487b356..9876361e3 100644 --- a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php @@ -172,9 +172,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) { return ( - $packageInstance->getSenderAddress() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . - $packageInstance->getRecipient() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . - $packageInstance->getContent() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR + $packageInstance->getSenderAddress() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . + $packageInstance->getRecipientType() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . + $packageInstance->getPackageContent() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR ); } diff --git a/application/hub/classes/recipient/dht/class_DhtRecipient.php b/application/hub/classes/recipient/dht/class_DhtRecipient.php index 92b15b614..781c077e4 100644 --- a/application/hub/classes/recipient/dht/class_DhtRecipient.php +++ b/application/hub/classes/recipient/dht/class_DhtRecipient.php @@ -82,7 +82,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { $discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class'); // "Discover" recipients by given package data - $recipients = $discoverInstance->resolveRecipientsByPackageData($packageInstance); + $recipients = $discoverInstance->resolveRecipientsByPackageInstance($packageInstance); // Now "walk" through all elements and add them to the list foreach ($recipients as $recipient) { diff --git a/application/hub/classes/registry/socket/class_SocketRegistry.php b/application/hub/classes/registry/socket/class_SocketRegistry.php index 6d5a42d1c..c3eb55e95 100644 --- a/application/hub/classes/registry/socket/class_SocketRegistry.php +++ b/application/hub/classes/registry/socket/class_SocketRegistry.php @@ -311,7 +311,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',socketInstance=' . $socketInstance->__toString()); // Is this a StorableSocket instance and is the address the same? - if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageInstance->getRecipient()))) { + if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageInstance->getRecipientType()))) { // Debug die //* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE)); diff --git a/application/hub/classes/tags/package/class_PackageTags.php b/application/hub/classes/tags/package/class_PackageTags.php index bcf0c093a..0e08f5b0f 100644 --- a/application/hub/classes/tags/package/class_PackageTags.php +++ b/application/hub/classes/tags/package/class_PackageTags.php @@ -121,7 +121,7 @@ class PackageTags extends BaseTag implements Tagable { * We take a look at the tags (in most cases only one is needed) so * first we need the content data splitted up into all it's parts. */ - $contentData = explode(NetworkPackageHandler::PACKAGE_MASK_SEPARATOR, $packageInstance->getContent()); + $contentData = explode(NetworkPackageHandler::PACKAGE_MASK_SEPARATOR, $packageInstance->getPackageContent()); // Get the tags and store them locally $this->setTags(explode(NetworkPackageHandler::PACKAGE_TAGS_SEPARATOR, $contentData[NetworkPackageHandler::INDEX_TAGS])); diff --git a/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php index b389c1166..3e8d6df18 100644 --- a/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php @@ -118,7 +118,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: Checking nodeName=%s ...', $nodeName)); if ($nodeName == self::OBJECT_TYPE_DATA_NAME) { // Output debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.'); $this->objectRegistryInstance->addEntry($nodeName, $characters); } // END - if diff --git a/application/hub/exceptions/package/class_UnexpectedPackageStatusException.php b/application/hub/exceptions/package/class_UnexpectedPackageStatusException.php index 1b40bd057..1d7db4f54 100644 --- a/application/hub/exceptions/package/class_UnexpectedPackageStatusException.php +++ b/application/hub/exceptions/package/class_UnexpectedPackageStatusException.php @@ -37,12 +37,12 @@ class UnexpectedPackageStatusException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf('[%s:%d] Unexpected package status %s!=%s detected, recipient=%s, sender=%s:%d, hash=%s.', + $message = sprintf('[%s:%d] Unexpected package status %s!=%s detected, recipientType=%s, sender=%s:%d, hash=%s.', $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->getPackageStatus(), $messageArray[2], - $messageArray[1]->getRecipient(), + $messageArray[1]->getRecipientType(), $messageArray[1]->getSenderAddress(), $messageArray[1]->getSenderPort(), $messageArray[1]->getHash() diff --git a/application/hub/exceptions/unl/class_InvalidUnlException.php b/application/hub/exceptions/unl/class_InvalidUnlException.php index d8b525806..b1a6c071a 100644 --- a/application/hub/exceptions/unl/class_InvalidUnlException.php +++ b/application/hub/exceptions/unl/class_InvalidUnlException.php @@ -44,7 +44,7 @@ class InvalidUnlException extends FrameworkException { $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), - $messageArray[2]->getRecipient() + $messageArray[2]->getRecipientType() ); // Call parent exception constructor diff --git a/application/hub/interfaces/class_HubInterface.php b/application/hub/interfaces/class_HubInterface.php index 98a986a8f..0eaa9f308 100644 --- a/application/hub/interfaces/class_HubInterface.php +++ b/application/hub/interfaces/class_HubInterface.php @@ -74,7 +74,7 @@ interface HubInterface extends FrameworkInterface { * * @return $privateKeyHash Current private key hash */ - function getPrivateKeyHash (); + function getNodePrivateKeyHash (); /** * Getter for session id diff --git a/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php b/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php index 95ebd9d06..710d9a2af 100644 --- a/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php +++ b/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php @@ -35,6 +35,6 @@ interface DiscoverableDhtRecipient extends DiscoverableRecipient { * @param $packageInstance An instance of a DeliverablePackage class * @return $recipients An indexed array with DHT recipients */ - function resolveRecipientsByPackageData (DeliverablePackage $packageInstance); + function resolveRecipientsByPackageInstance (DeliverablePackage $packageInstance); } diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index d37f20f2e..1388ed7dc 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -89,7 +89,7 @@ interface Distributable extends HubInterface { * @param $packageInstance An instance of a DeliverablePackage class * @return $recipients An indexed array with DHT recipients */ - function findRecipientsByPackageData (DeliverablePackage $packageInstance); + function findRecipientsByPackageInstance (DeliverablePackage $packageInstance); /** * Whether the DHT has fully bootstrapped (after state 'booting') diff --git a/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php b/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php index 4a17eee0b..d531a43a3 100644 --- a/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php +++ b/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php @@ -61,7 +61,7 @@ interface HandleableProtocol extends Handleable, HubInterface { * @param $packageInstance Valid raw package data * @return $isValid Whether the UNL can be validated */ - function isValidUniversalNodeLocatorByPackageData (DeliverablePackage $packageInstance); + function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance); /** * If the found UNL (address) matches own external or internal address diff --git a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php index b7a24c7d2..d3e839fb2 100644 --- a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php +++ b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php @@ -50,7 +50,7 @@ interface LookupablePeerState extends Lookupable { * @param $socketInstance An instance of a StorableSocket class * @return void */ - function registerPeerByPackageData (DeliverablePackage $packageInstance, StorableSocket $socketInstance); + function registerPeerByPackageInstance (DeliverablePackage $packageInstance, StorableSocket $socketInstance); /** * Registers the given peer state and An instance of a DeliverablePackage class -- 2.39.5