From: Roland Häder Date: Wed, 2 Dec 2020 02:20:28 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=13bc778e64f8aba89713860eb5913d480ab3e9c4;p=hub.git Continued: - added missing traits - more debugging info of setting socket instances - updated core framework Signed-off-by: Roland Häder --- diff --git a/application/hub/classes/communicator/class_BaseCommunicator.php b/application/hub/classes/communicator/class_BaseCommunicator.php index 1c0956e5b..a2217fe3e 100644 --- a/application/hub/classes/communicator/class_BaseCommunicator.php +++ b/application/hub/classes/communicator/class_BaseCommunicator.php @@ -8,6 +8,7 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; // Import framework stuff use Org\Mxchange\CoreFramework\State\Stateable; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; /** * A general communicator class @@ -32,6 +33,9 @@ use Org\Mxchange\CoreFramework\State\Stateable; * along with this program. If not, see . */ abstract class BaseCommunicator extends BaseHubSystem { + // Load traits + use StateableTrait; + /** * Protected constructor * diff --git a/application/hub/classes/crawler/class_BaseNodeCrawler.php b/application/hub/classes/crawler/class_BaseNodeCrawler.php index 1a37d1049..d436207f5 100644 --- a/application/hub/classes/crawler/class_BaseNodeCrawler.php +++ b/application/hub/classes/crawler/class_BaseNodeCrawler.php @@ -9,6 +9,7 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; // Import framework stuff use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\State\Stateable; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; /** * A general NodeCrawler class @@ -33,6 +34,9 @@ use Org\Mxchange\CoreFramework\State\Stateable; * along with this program. If not, see . */ abstract class BaseNodeCrawler extends BaseHubSystem { + // Load traits + use StateableTrait; + /** * Whether this Crawler is active */ diff --git a/application/hub/classes/dht/class_BaseDht.php b/application/hub/classes/dht/class_BaseDht.php index fda923cc6..7a663cd12 100644 --- a/application/hub/classes/dht/class_BaseDht.php +++ b/application/hub/classes/dht/class_BaseDht.php @@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; use Org\Mxchange\CoreFramework\Stacker\Stackable; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; /** * A general DHT class @@ -37,6 +38,9 @@ use Org\Mxchange\CoreFramework\Stacker\Stackable; * along with this program. If not, see . */ abstract class BaseDht extends BaseHubSystem implements Distributable { + // Load traits + use StateableTrait; + /** * Stacker name for "INSERT" node data */ diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index 9f6e1d3ba..3b19a24ce 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -196,7 +196,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { * should not happen). */ $nodeData = $resultInstance->current(); - } // END - if + } // Return node data //* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE))); @@ -230,7 +230,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { * should not happen). */ $nodeData = $resultInstance->current(); - } // END - if + } // Return node data //* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE))); @@ -267,7 +267,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add criteria /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: state=%s,messageData[%s]=%s', $this->getPrintableState(), $key, $messageData[$key])); $searchInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]); - } // END - foreach + } // Only one entry is fine $searchInstance->setLimit(1); @@ -321,7 +321,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add it and leave any 'my-' prefix out $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria); - } // END - foreach + } // Add exclusion key $searchInstance->addExcludeCriteria(str_replace('my-', '', $excludeKey), $messageData[$excludeKey]); @@ -356,7 +356,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add this entry array_push($nodeList, $current); - } // END - while + } // Save last exception $handlerInstance->setLastException($this->getFrontendInstance()->getLastException()); @@ -382,13 +382,13 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Abort here return; - } // END - if + } // Put them all into a stack foreach ($nodeList as $nodeData) { // Insert all entries $this->getStackInstance()->pushNamed(self::STACKER_NAME_INSERT_NODE, $nodeData); - } // END - foreach + } } /** @@ -408,7 +408,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { if (!$resultInstance->valid()) { // Then skip below loop return array(); - } // END - if + } // Init array $recipients = []; @@ -421,7 +421,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add instance to recipient list array_push($recipients, $current); - } // END - while + } // Return filled array return $recipients; @@ -460,7 +460,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add instance to recipient list array_push($recipients, $current); - } // END - while + } // Return filled array return $recipients; diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 3bfc8d1c2..4fe7cc178 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -21,6 +21,7 @@ use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Traits\Stream\Output\OutputStreamTrait; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; use Org\Mxchange\CoreFramework\Visitor\Visitable; use Org\Mxchange\CoreFramework\Visitor\Visitor; @@ -49,6 +50,7 @@ use Org\Mxchange\CoreFramework\Visitor\Visitor; abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Registerable { // Load traits use OutputStreamTrait; + use StateableTrait; // Exception codes const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100; 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 6d005b289..66e3696ed 100644 --- a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php @@ -67,6 +67,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageInstance); // Set the resource + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: Setting socketInstance=%s ...', $socketInstance->__toString())); $helperInstance->setSocketInstance($socketInstance); // @TODO The whole resolving part should be moved out and made more configurable @@ -85,7 +86,7 @@ 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->getRecipientUnl() . ':' . $e->getMessage()); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: Failed to resolve %s: %s', $packageInstance->getRecipientUnl(), $e->getMessage())); // Is the recipient equal as configured UNL? if (substr($packageInstance->getRecipientUnl(), 0, strlen(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address'))) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address')) { diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index 1410062d8..b71b77256 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -234,6 +234,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT , $socketPort); // Set socket here + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: Setting socketInstance=%s ...', $socketInstance->__toString())); //* DEBUG-DIE: */ die(sprintf('[%s:%d]: socketInstance=%s', __METHOD__, __LINE__, print_r($socketInstance, TRUE))); $this->setSocketInstance($socketInstance); diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index cffcf73ec..b0803415b 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -299,7 +299,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { $this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance); // And set it here - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Setting socketInstance ... (socketResource=%s)', strtoupper($this->getProtocolName()), $socketInstance->getSocketResource())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: Setting socketInstance=%s (socketResource=%s) ...', strtoupper($this->getProtocolName()), $socketInstance->__toString(), $socketInstance->getSocketResource())); $this->setSocketInstance($socketInstance); // Trace message diff --git a/application/hub/classes/miner/class_BaseHubMiner.php b/application/hub/classes/miner/class_BaseHubMiner.php index 0fc26141c..6f6d0fb50 100644 --- a/application/hub/classes/miner/class_BaseHubMiner.php +++ b/application/hub/classes/miner/class_BaseHubMiner.php @@ -13,6 +13,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Database\Updateable; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; /** * A general hub miner class @@ -37,6 +38,9 @@ use Org\Mxchange\CoreFramework\Registry\GenericRegistry; * along with this program. If not, see . */ abstract class BaseHubMiner extends BaseHubSystem implements Updateable { + // Load traits + use StateableTrait; + /** * Version information */ diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index e37275f7e..180bd612f 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -32,6 +32,7 @@ use Org\Mxchange\CoreFramework\Response\Responseable; use Org\Mxchange\CoreFramework\Task\Taskable; use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait; use Org\Mxchange\CoreFramework\Traits\Database\Frontend\DatabaseFrontendTrait; +use Org\Mxchange\CoreFramework\Traits\State\StateableTrait; /** * A general hub node class @@ -59,6 +60,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC // Load traits use CryptoTrait; use DatabaseFrontendTrait; + use StateableTrait; /** * Node types diff --git a/application/hub/classes/pools/peer/class_DefaultPeerPool.php b/application/hub/classes/pools/peer/class_DefaultPeerPool.php index 4b135d1b0..66fa3c699 100644 --- a/application/hub/classes/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/classes/pools/peer/class_DefaultPeerPool.php @@ -85,7 +85,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { if (!$socketInstance->isValidSocket()) { // Throw an exception throw new InvalidSocketException(array($this, $socketInstance->getSocketResource()), self::EXCEPTION_INVALID_SOCKET); - } // END - if + } // Get error code $errorCode = $socketInstance->getLastSocketErrorCode(); @@ -94,7 +94,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { if ($errorCode > 0) { // Handle the socket error $socketInstance->handleSocketError(__METHOD__, __LINE__); - } // END - if + } } /** @@ -133,7 +133,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { if (!$socketInstance->determineSocketPeerName($peerAddress, $peerPort)) { // Handle the socket error $socketInstance->handleSocketError(__METHOD__, __LINE__); - } // END - if + } } else { // Server sockets won't work with socket_getpeername() self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Socket resource is server socket (' . $socketInstance->getSocketResource() . '). This is not a bug.'); @@ -181,7 +181,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { foreach ($socketArrays as $socketArray) { // Add the socket array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]); - } // END - foreach + } // Return it return $sockets; @@ -217,12 +217,12 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->isValidConnectionType($connectionType)) { // Is not a valid connection type! throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE); - } // END - if + } // Add the socket array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]); - } // END - if - } // END - foreach + } + } // Return it return $sockets; @@ -281,7 +281,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { if (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->determineSocketPeerName($peerAddress, $peerPort)) { // Handle the socket error with given package data $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__); - } // END - if + } // If the "peer" IP and recipient is same, use it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s,peerPort=%d,locatorInstance->addressPart=%s', $peerAddress, $peerPort, $locatorInstance->getAddressPart())); @@ -292,8 +292,8 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE])); break; - } // END - if - } // END - foreach + } + } // Return the determined socket instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL: socketInstance[]=%s - EXIT!', gettype($socketInstance))); diff --git a/application/hub/interfaces/communicator/class_Communicator.php b/application/hub/interfaces/communicator/class_Communicator.php index 410f6163c..27974a365 100644 --- a/application/hub/interfaces/communicator/class_Communicator.php +++ b/application/hub/interfaces/communicator/class_Communicator.php @@ -4,6 +4,7 @@ namespace Org\ShipSimu\Hub\Communicator; // Import framework stuff use Org\Mxchange\CoreFramework\Executor\Executor; +use Org\Mxchange\CoreFramework\State\Stateable; /** * An interface for communicators @@ -28,4 +29,19 @@ use Org\Mxchange\CoreFramework\Executor\Executor; * along with this program. If not, see . */ interface Communicator extends Executor { + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + function setStateInstance (Stateable $stateInstance); + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + function getStateInstance (); + } diff --git a/application/hub/interfaces/crawler/class_Crawler.php b/application/hub/interfaces/crawler/class_Crawler.php index 3a57461aa..8e12a94db 100644 --- a/application/hub/interfaces/crawler/class_Crawler.php +++ b/application/hub/interfaces/crawler/class_Crawler.php @@ -82,4 +82,20 @@ interface Crawler extends HubInterface { * @return void */ function initCrawler (Stateable $stateInstance); + + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + function setStateInstance (Stateable $stateInstance); + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + function getStateInstance (); + } diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index cb497e733..a71af3086 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -6,6 +6,9 @@ namespace Org\Shipsimu\Hub\Dht; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; +// Import framework stuff +use Org\Mxchange\CoreFramework\State\Stateable; + /** * An interface for DHTs * @@ -121,4 +124,19 @@ interface Distributable extends HubInterface { */ function enableAcceptDhtBootstrap (); + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + function setStateInstance (Stateable $stateInstance); + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + function getStateInstance (); + } diff --git a/application/hub/interfaces/miner/class_MinerHelper.php b/application/hub/interfaces/miner/class_MinerHelper.php index 656ee3f44..4c0000e3d 100644 --- a/application/hub/interfaces/miner/class_MinerHelper.php +++ b/application/hub/interfaces/miner/class_MinerHelper.php @@ -9,6 +9,7 @@ use Org\Shipsimu\Hub\Producer\Block\BlockProducer; // Import framework stuff use Org\Mxchange\CoreFramework\Controller\Controller; use Org\Mxchange\CoreFramework\Response\Responseable; +use Org\Mxchange\CoreFramework\State\Stateable; /** * An interface for "node-helper" classes @@ -100,4 +101,19 @@ interface MinerHelper extends HubInterface { */ function blockProducerHasInitialized (BlockProducer $producerInstance); + /** + * Setter for state instance + * + * @param $stateInstance A Stateable instance + * @return void + */ + function setStateInstance (Stateable $stateInstance); + + /** + * Getter for state instance + * + * @return $stateInstance A Stateable instance + */ + function getStateInstance (); + } diff --git a/core b/core index 303d853c3..0ab475e77 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 303d853c3d98734f9d7a1a0445c98b6d6c444945 +Subproject commit 0ab475e77c70b60e323a87b97a73c39a695c6c13