]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 02:20:28 +0000 (03:20 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 02:20:28 +0000 (03:20 +0100)
- added missing traits
- more debugging info of setting socket instances
- updated core framework

Signed-off-by: Roland Häder <roland@mxchange.org>
16 files changed:
application/hub/classes/communicator/class_BaseCommunicator.php
application/hub/classes/crawler/class_BaseNodeCrawler.php
application/hub/classes/dht/class_BaseDht.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php
application/hub/classes/info/connection/class_ConnectionInfo.php
application/hub/classes/listener/class_BaseListener.php
application/hub/classes/miner/class_BaseHubMiner.php
application/hub/classes/nodes/class_BaseHubNode.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/interfaces/communicator/class_Communicator.php
application/hub/interfaces/crawler/class_Crawler.php
application/hub/interfaces/distributable/class_Distributable.php
application/hub/interfaces/miner/class_MinerHelper.php
core

index 1c0956e5bcb6039c7f598fdeb38974fdf543fdbb..a2217fe3ec1c5d7ddf7d9d37a71cb5d5e6f54bf0 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 abstract class BaseCommunicator extends BaseHubSystem {
+       // Load traits
+       use StateableTrait;
+
        /**
         * Protected constructor
         *
index 1a37d10496a18a3f241a309989db00ef2d550e5f..d436207f5d68b19d1015f630f8113bde5d1dcbb7 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 abstract class BaseNodeCrawler extends BaseHubSystem {
+       // Load traits
+       use StateableTrait;
+
        /**
         * Whether this Crawler is active
         */
index fda923cc6f014453bbfa92a2bdf1e08d0bcc61ea..7a663cd129f343afb1cbc1847914b32a137cdb55 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 abstract class BaseDht extends BaseHubSystem implements Distributable {
+       // Load traits
+       use StateableTrait;
+
        /**
         * Stacker name for "INSERT" node data
         */
index 9f6e1d3bab282ab3ed37f71b0654ba9bac5e8b63..3b19a24cedb5ad4715074fdd6dc5ce215daa58a6 100644 (file)
@@ -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;
index 3bfc8d1c25f108c13380d72c52523eb3680bf97b..4fe7cc17827eac1922527509aae26ba73643fe14 100644 (file)
@@ -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;
index 6d005b2894b96e36a868ded8da26cabc59ac5524..66e3696edc14619d0ae45653680e729c947babe2 100644 (file)
@@ -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')) {
index 1410062d80547374433ea2494d72cc375f9905cf..b71b77256800d0508b1852f3e4ef653d287f292d 100644 (file)
@@ -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);
 
index cffcf73ec2201cae4990c8a3b28b6f70feb8573c..b0803415bd15e15105f5943fbc9deaed88b41f25 100644 (file)
@@ -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
index 0fc26141c2f1b3ee05e3f23b3c0db31a69e2e3e3..6f6d0fb5064bfe816ee4ef18c9bf66bfe23e9b7b 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 abstract class BaseHubMiner extends BaseHubSystem implements Updateable {
+       // Load traits
+       use StateableTrait;
+
        /**
         * Version information
         */
index e37275f7eafbb2189101de6fa7839972d754ade7..180bd612fd720ac70a2178ae9ca2f6fd2705beb2 100644 (file)
@@ -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
index 4b135d1b0c327de1734faad3e4b337bdab925bd2..66fa3c699dd6871fe6972b2aa5c61e43bc032469 100644 (file)
@@ -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)));
index 410f6163cd0a08f30c8b2aec19b1991150af1639..27974a365667f7171ebe835f27ab8952969aad16 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
  */
 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 ();
+
 }
index 3a57461aa548d98f50438d02a30cbb036fe8f68b..8e12a94dbc50836ad14bc3d81217edbda48ebcb0 100644 (file)
@@ -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 ();
+
 }
index cb497e73361683e375aae888b88bd09f647ffca0..a71af3086803179ed813b6ca30410199ce46a45a 100644 (file)
@@ -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 ();
+
 }
index 656ee3f4458d8d44b3bc5a06355fdb5865683320..4c0000e3db7dd761c2e8c0c47b49144aae47acfd 100644 (file)
@@ -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 303d853c3d98734f9d7a1a0445c98b6d6c444945..0ab475e77c70b60e323a87b97a73c39a695c6c13 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 303d853c3d98734f9d7a1a0445c98b6d6c444945
+Subproject commit 0ab475e77c70b60e323a87b97a73c39a695c6c13