From 90792a5f0551fd9cf29afd35cb3343b5ab741b66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 6 Nov 2020 16:31:04 +0100 Subject: [PATCH] Continued: - $minableInstance moved to BaseMinerProducer - $peerSuffix can be empty 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 | 35 +++---------------- .../classes/listener/class_BaseListener.php | 6 +--- .../miner/class_BaseMinerProducer.php | 26 ++++++++++++++ 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 40a576dd3..787cb8cf3 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -12,7 +12,6 @@ use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\BaseListener; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; -use Org\Shipsimu\Hub\Miner\Minable; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; @@ -132,11 +131,6 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface */ private $packageInstance = NULL; - /** - * A Minable instance - */ - private $minableInstance = NULL; - /** * Name of used protocol */ @@ -298,7 +292,7 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * @param $privateKey The new private key * @return void */ - protected final function setPrivateKey ($privateKey) { + protected final function setPrivateKey (string $privateKey) { // Set it config now $this->getConfigInstance()->setConfigEntry('private_key', (string) $privateKey); } @@ -319,9 +313,9 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * @param $privateKeyHash The new private key hash * @return void */ - protected final function setNodePrivateKeyHash ($privateKeyHash) { + protected final function setNodePrivateKeyHash (string $privateKeyHash) { // Set it config now - $this->getConfigInstance()->setConfigEntry('private_key_hash', (string) $privateKeyHash); + $this->getConfigInstance()->setConfigEntry('private_key_hash', $privateKeyHash); } /** @@ -340,8 +334,8 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * @param $sessionId The new session id * @return void */ - protected final function setSessionId ($sessionId) { - $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId); + protected final function setSessionId (string $sessionId) { + $this->getConfigInstance()->setConfigEntry('session_id', $sessionId); } /** @@ -507,23 +501,4 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface return $this->packageInstance; } - /** - * Setter for Minable instance - * - * @param $minableInstance A Minable instance - * @return void - */ - protected final function setMinableInstance (Minable $minableInstance) { - $this->minableInstance = $minableInstance; - } - - /** - * Getter for minable instance - * - * @return $minableInstance A Minable instance - */ - protected final function getMinableInstance () { - return $this->minableInstance; - } - } diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index be43cdbcb..26833d6c5 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -349,16 +349,12 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * * @param $peerSuffix Suffix for peer name (e.g. :0 for TCP(/UDP?) connections) * @return void - * @throws InvalidArgumentException If $peerSuffix is empty * @throws LogicException If no info instance can be created */ protected function doListenSocketSelect (string $peerSuffix) { // Validate parameter and socket instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: peerSuffix=%s - CALLED!', strtoupper($this->getProtocolName()), $peerSuffix)); - if (empty($peerSuffix)) { - // Throw exception - throw new InvalidArgumentException('peerSuffix is empty'); - } elseif(!$this->getSocketInstance()->isValidSocket()) { + if(!$this->getSocketInstance()->isValidSocket()) { // Invalid socket throw new LogicException(sprintf('this->socketInstance->socketResource=%s is not valid', $this->getSocketInstance()->getSocketResource())); } diff --git a/application/hub/classes/producer/miner/class_BaseMinerProducer.php b/application/hub/classes/producer/miner/class_BaseMinerProducer.php index edb2e3d7e..037a109f3 100644 --- a/application/hub/classes/producer/miner/class_BaseMinerProducer.php +++ b/application/hub/classes/producer/miner/class_BaseMinerProducer.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Producer\Miner; // Import application-specific stuff +use Org\Shipsimu\Hub\Miner\Minable; use Org\Shipsimu\Hub\Producer\BaseProducer; // Import framework stuff @@ -31,6 +32,12 @@ use Org\Mxchange\CoreFramework\Registry\GenericRegistry; * along with this program. If not, see . */ abstract class BaseMinerProducer extends BaseProducer { + + /** + * A Minable instance + */ + private $minableInstance = NULL; + /** * Protected constructor * @@ -48,4 +55,23 @@ abstract class BaseMinerProducer extends BaseProducer { $minerInstance->blockProducerHasInitialized($this); } + /** + * Setter for Minable instance + * + * @param $minableInstance A Minable instance + * @return void + */ + protected final function setMinableInstance (Minable $minableInstance) { + $this->minableInstance = $minableInstance; + } + + /** + * Getter for minable instance + * + * @return $minableInstance A Minable instance + */ + protected final function getMinableInstance () { + return $this->minableInstance; + } + } -- 2.39.5