// Import framework stuff
use Org\Mxchange\CoreFramework\State\Stateable;
+use Org\Mxchange\CoreFramework\Traits\State\StateableTrait;
/**
* A general communicator class
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseCommunicator extends BaseHubSystem {
+ // Load traits
+ use StateableTrait;
+
/**
* Protected constructor
*
// 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
* 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
*/
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
* 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
*/
* 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)));
* 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)));
// 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);
// 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]);
// Add this entry
array_push($nodeList, $current);
- } // END - while
+ }
// Save last exception
$handlerInstance->setLastException($this->getFrontendInstance()->getLastException());
// 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
+ }
}
/**
if (!$resultInstance->valid()) {
// Then skip below loop
return array();
- } // END - if
+ }
// Init array
$recipients = [];
// Add instance to recipient list
array_push($recipients, $current);
- } // END - while
+ }
// Return filled array
return $recipients;
// Add instance to recipient list
array_push($recipients, $current);
- } // END - while
+ }
// Return filled array
return $recipients;
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;
abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Registerable {
// Load traits
use OutputStreamTrait;
+ use StateableTrait;
// Exception codes
const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100;
$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
$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')) {
$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);
$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
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
* 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
*/
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
// Load traits
use CryptoTrait;
use DatabaseFrontendTrait;
+ use StateableTrait;
/**
* Node types
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();
if ($errorCode > 0) {
// Handle the socket error
$socketInstance->handleSocketError(__METHOD__, __LINE__);
- } // END - if
+ }
}
/**
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.');
foreach ($socketArrays as $socketArray) {
// Add the socket
array_push($sockets, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
- } // END - foreach
+ }
// Return it
return $sockets;
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;
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()));
// 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)));
// Import framework stuff
use Org\Mxchange\CoreFramework\Executor\Executor;
+use Org\Mxchange\CoreFramework\State\Stateable;
/**
* An interface for communicators
* 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 ();
+
}
* @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 ();
+
}
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
*
*/
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 ();
+
}
// 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
*/
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 ();
+
}
-Subproject commit 303d853c3d98734f9d7a1a0445c98b6d6c444945
+Subproject commit 0ab475e77c70b60e323a87b97a73c39a695c6c13