From 4e6d72ee5c76a1e4a69f22c9fe4edc1fc348f5df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 2 Dec 2020 03:57:06 +0100 Subject: [PATCH] Continued: - introduced new trait StorableSocketTrait - added missing methods to interface(s) - updated core framework 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 | 131 ----------- .../container/class_BaseHubContainer.php | 114 ---------- .../class_BaseHubDatabaseFrontend.php | 109 --------- .../classes/handler/class_BaseHubHandler.php | 110 --------- .../package/class_NetworkPackageHandler.php | 2 +- .../ipv4/class_BaseIpV4ConnectionHelper.php | 4 + .../info/connection/class_ConnectionInfo.php | 4 + .../classes/listener/class_BaseListener.php | 2 + .../listener/class_BaseListenerDecorator.php | 55 ----- .../hub/classes/nodes/class_BaseHubNode.php | 214 +++++++++++++----- .../assembler/class_PackageAssembler.php | 24 ++ .../input/class_RawDataInputStream.php | 26 ++- .../output/class_RawDataOutputStream.php | 2 +- .../hub/interfaces/class_HubInterface.php | 51 ----- .../connections/class_ConnectionHelper.php | 15 ++ .../interfaces/listener/class_Listenable.php | 16 ++ .../hub/interfaces/nodes/class_Node.php | 28 +++ .../shareable/info/class_ShareableInfo.php | 15 ++ .../socket/class_StorableSocketTrait.php | 55 +++++ core | 2 +- 20 files changed, 346 insertions(+), 633 deletions(-) create mode 100644 application/hub/traits/container/socket/class_StorableSocketTrait.php diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 3e4c41e1c..b1af3fa71 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -4,7 +4,6 @@ namespace Org\Shipsimu\Hub\Generic; // Import application-specific stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; -use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; @@ -56,11 +55,6 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface */ const BOOTSTRAP_NODES_SEPARATOR = ';'; - /** - * A StorableSocket instance - */ - private $socketInstance = NULL; - /** * Protected constructor * @@ -72,129 +66,4 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface parent::__construct($className); } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public final function ifStartEndMarkersSet ($data) { - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: data()=%d - CALLED!', strlen($data))); - - // Determine it - $isset = ( - ( - substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER - ) && ( - substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER - ) - ); - - // ... and return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-SYSTEM: isset=%d - EXIT!', intval($isset))); - return $isset; - } - - /** - * Setter for node id - * - * @param $nodeId The new node id - * @return void - */ - protected final function setNodeId ($nodeId) { - // Set it config now - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('node_id', (string) $nodeId); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - public final function getNodeId () { - // Get it from config - return FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('node_id'); - } - - /** - * Setter for private key - * - * @param $privateKey The new private key - * @return void - */ - protected final function setPrivateKey (string $privateKey) { - // Set it config now - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('private_key', (string) $privateKey); - } - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - public final function getPrivateKey () { - // Get it from config - return FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('private_key'); - } - - /** - * Setter for private key hash - * - * @param $privateKeyHash The new private key hash - * @return void - */ - protected final function setNodePrivateKeyHash (string $privateKeyHash) { - // Set it config now - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('private_key_hash', $privateKeyHash); - } - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - public final function getNodePrivateKeyHash () { - // Get it from config - return FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('private_key_hash'); - } - - /** - * Setter for session id - * - * @param $sessionId The new session id - * @return void - */ - protected final function setSessionId (string $sessionId) { - FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('session_id', $sessionId); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public final function getSessionId () { - return FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('session_id'); - } - - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - public final function setSocketInstance (StorableSocket $socketInstance) { - $this->socketInstance = $socketInstance; - } - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - public final function getSocketInstance () { - return $this->socketInstance; - } - } diff --git a/application/hub/classes/container/class_BaseHubContainer.php b/application/hub/classes/container/class_BaseHubContainer.php index 3e842fc44..1a3a29582 100644 --- a/application/hub/classes/container/class_BaseHubContainer.php +++ b/application/hub/classes/container/class_BaseHubContainer.php @@ -3,8 +3,6 @@ namespace Org\Shipsimu\Hub\Container; // Import application-specific stuff -use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Pool\Poolable; @@ -45,11 +43,6 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { */ private $listenerPoolInstance = NULL; - /** - * A StorableSocket instance - */ - private $socketInstance = NULL; - /** * Protected constructor * @@ -62,28 +55,6 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { parent::__construct($className); } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public final function ifStartEndMarkersSet ($data) { - // Determine it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-CONTAINER: data()=%d - CALLED!', strlen($data))); - $isset = ( - ( - substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER - ) && ( - substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER - ) - ); - - // ... and return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-CONTAINER: isset=%d - EXIT!', intval($isset))); - return $isset; - } - /** * Setter for listener pool instance * @@ -103,91 +74,6 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { return $this->listenerPoolInstance; } - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - public final function setSocketInstance (StorableSocket $socketInstance) { - $this->socketInstance = $socketInstance; - } - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - public final function getSocketInstance () { - return $this->socketInstance; - } - - /** - * Setter for node id - * - * @param $nodeId The new node id - * @return void - */ - protected final function setNodeId ($nodeId) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - public final function getNodeId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key - * - * @param $privateKey The new private key - * @return void - */ - protected final function setPrivateKey ($privateKey) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - public final function getPrivateKey () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key hash - * - * @param $privateKeyHash The new private key hash - * @return void - */ - protected final function setNodePrivateKeyHash ($privateKeyHash) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - public final function getNodePrivateKeyHash () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public final function getSessionId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - /** * Setter for listener instance * diff --git a/application/hub/classes/database/frontend/class_BaseHubDatabaseFrontend.php b/application/hub/classes/database/frontend/class_BaseHubDatabaseFrontend.php index ef72ac266..3b678b9b3 100644 --- a/application/hub/classes/database/frontend/class_BaseHubDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/class_BaseHubDatabaseFrontend.php @@ -3,8 +3,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend; // Import application-specific stuff -use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Node\Node; use Org\Shipsimu\Hub\Pool\Poolable; @@ -46,11 +44,6 @@ abstract class BaseHubDatabaseFrontend extends BaseDatabaseFrontend implements H */ private $listenerPoolInstance = NULL; - /** - * A StorableSocket instance - */ - private $socketInstance = NULL; - /** * Node instance */ @@ -67,23 +60,6 @@ abstract class BaseHubDatabaseFrontend extends BaseDatabaseFrontend implements H parent::__construct($className); } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public final function ifStartEndMarkersSet ($data) { - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-DATABASE-WRAPPER: data()=%d - CALLED!', strlen($data))); - - // Determine it - $isset = ((substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER) && (substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER)); - - // ... and return it - return $isset; - } - /** * Setter for listener pool instance * @@ -103,91 +79,6 @@ abstract class BaseHubDatabaseFrontend extends BaseDatabaseFrontend implements H return $this->listenerPoolInstance; } - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - public final function setSocketInstance (StorableSocket $socketInstance) { - $this->socketInstance = $socketInstance; - } - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - public final function getSocketInstance () { - return $this->socketInstance; - } - - /** - * Setter for node id - * - * @param $nodeId The new node id - * @return void - */ - protected final function setNodeId ($nodeId) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - public final function getNodeId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key - * - * @param $privateKey The new private key - * @return void - */ - protected final function setPrivateKey ($privateKey) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - public final function getPrivateKey () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key hash - * - * @param $privateKeyHash The new private key hash - * @return void - */ - protected final function setNodePrivateKeyHash ($privateKeyHash) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - public final function getNodePrivateKeyHash () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public final function getSessionId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - /** * Setter for listener instance * diff --git a/application/hub/classes/handler/class_BaseHubHandler.php b/application/hub/classes/handler/class_BaseHubHandler.php index d87e3e39a..eef5130f4 100644 --- a/application/hub/classes/handler/class_BaseHubHandler.php +++ b/application/hub/classes/handler/class_BaseHubHandler.php @@ -3,8 +3,6 @@ namespace Org\Shipsimu\Hub\Handler; // Import application-specific stuff -use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; @@ -57,11 +55,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte */ private $nodeInstance = NULL; - /** - * A StorableSocket instance - */ - private $socketInstance = NULL; - /** * An instance of a LocateableNode class */ @@ -93,24 +86,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte parent::__construct($className); } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public final function ifStartEndMarkersSet ($data) { - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-HANDLER: data(%d)=%s - CALLED!', strlen($data), $data)); - - // Determine it - $isset = ((substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER) && (substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER)); - - // ... and return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-HANDLER: isset=%d - EXIT!', intval($isset))); - return $isset; - } - /** * Setter for listener pool instance * @@ -130,25 +105,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte return $this->listenerPoolInstance; } - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - public final function setSocketInstance (StorableSocket $socketInstance) { - $this->socketInstance = $socketInstance; - } - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - public final function getSocketInstance () { - return $this->socketInstance; - } - /** * Setter for UNL instance * @@ -170,72 +126,6 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte return $this->universalNodeLocatorInstance; } - /** - * Setter for node id - * - * @param $nodeId The new node id - * @return void - */ - protected final function setNodeId ($nodeId) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - public final function getNodeId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key - * - * @param $privateKey The new private key - * @return void - */ - protected final function setPrivateKey ($privateKey) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - public final function getPrivateKey () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Setter for private key hash - * - * @param $privateKeyHash The new private key hash - * @return void - */ - protected final function setNodePrivateKeyHash ($privateKeyHash) { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - public final function getNodePrivateKeyHash () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public final function getSessionId () { - throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); - } - /** * Setter for listener instance * diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index a338aecaa..3e6d1c5e1 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -16,7 +16,6 @@ use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; 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; use Org\Shipsimu\Hub\Helper\HubHelper; use Org\Shipsimu\Hub\Information\ShareableInfo; @@ -572,6 +571,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei public function getHashFromPackageSessionId (DeliverablePackage $packageInstance) { // Is session id set? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); + /* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE))); if (empty($packageInstance->getSessionId())) { // Throw exception throw new InvalidArgumentException('packageInstance has no sessionId set.'); diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index 853fc73ab..407b84537 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Helper\Connection\Network\IpV4; use Org\Shipsimu\Hub\Factory\State\Peer\PeerStateFactory; use Org\Shipsimu\Hub\Helper\Connection\BaseConnectionHelper; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; +use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; @@ -35,6 +36,9 @@ use Org\Mxchange\CoreFramework\Handler\Handleable; * along with this program. If not, see . */ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { + // Load traits + use StorableSocketTrait; + /** * Name of used protocol */ diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index b71b77256..aaa0e308b 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -9,6 +9,7 @@ use Org\Shipsimu\Hub\Information\BaseInfo; use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; +use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Registry\Registerable; @@ -40,6 +41,9 @@ use \InvalidArgumentException; * along with this program. If not, see . */ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { + // Load traits + use StorableSocketTrait; + /** * Listener instance */ diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index b0803415b..3d27b7a29 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -14,6 +14,7 @@ use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Pool\Peer\PoolablePeer; use Org\Shipsimu\Hub\Pool\Poolable; +use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; @@ -57,6 +58,7 @@ use \LogicException; abstract class BaseListener extends BaseHubSystem implements Visitable { // Load traits use IteratorTrait; + use StorableSocketTrait; // Exception code constants const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01; diff --git a/application/hub/classes/listener/class_BaseListenerDecorator.php b/application/hub/classes/listener/class_BaseListenerDecorator.php index 69c9f54d2..08384f31a 100644 --- a/application/hub/classes/listener/class_BaseListenerDecorator.php +++ b/application/hub/classes/listener/class_BaseListenerDecorator.php @@ -224,61 +224,6 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable return $this->socketInstance; } - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - public function ifStartEndMarkersSet ($data) { - $this->partialSub('Please implement this method.'); - } - - /** - * Getter for listener pool instance - * - * @return $listenerPoolInstance Our current listener pool instance - */ - public function getListenerPoolInstance () { - $this->partialSub('Please implement this method.'); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - public function getNodeId () { - $this->partialSub('Please implement this method.'); - } - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - public function getPrivateKey () { - $this->partialSub('Please implement this method.'); - } - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - public function getNodePrivateKeyHash () { - $this->partialSub('Please implement this method.'); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public function getSessionId () { - $this->partialSub('Please implement this method.'); - } - /** * Setter for listener instance * diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index 180bd612f..765b46814 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -112,6 +112,26 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC */ private $searchInstance = NULL; + /** + * Node id + */ + private $nodeId = 'invalid'; + + /** + * Private key + */ + private $privateKey = 'invalid'; + + /** + * Node's private-key hash + */ + private $nodePrivateKeyHash = 'invalid'; + + /** + * Session id + */ + private $sessionId = 'invalid'; + /** * Protected constructor * @@ -677,6 +697,141 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC $this->isActive = $isActive; } + /** + * Enables whether this node accepts announcements + * + * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE) + * @return void + */ + protected final function enableAcceptingAnnouncements (bool $acceptAnnouncements = TRUE) { + $this->acceptAnnouncements = $acceptAnnouncements; + } + + /** + * Enables whether this node accepts DHT bootstrap requests + * + * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE) + * @return void + */ + public final function enableAcceptDhtBootstrap (bool $acceptDhtBootstrap = TRUE) { + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: Enabling DHT bootstrap requests ...'); + $this->acceptDhtBootstrap = $acceptDhtBootstrap; + } + + /** + * Setter for listener pool instance + * + * @param $listenerPoolInstance The new listener pool instance + * @return void + */ + protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) { + $this->listenerPoolInstance = $listenerPoolInstance; + } + + /** + * Getter for listener pool instance + * + * @return $listenerPoolInstance Our current listener pool instance + */ + public final function getListenerPoolInstance () { + return $this->listenerPoolInstance; + } + + /** + * Setter for search instance + * + * @param $searchInstance Searchable criteria instance + * @return void + */ + public final function setSearchInstance (LocalSearchCriteria $searchInstance) { + $this->searchInstance = $searchInstance; + } + + /** + * Getter for search instance + * + * @return $searchInstance Searchable criteria instance + */ + public final function getSearchInstance () { + return $this->searchInstance; + } + + /** + * Setter for node id + * + * @param $nodeId The new node id + * @return void + */ + protected final function setNodeId (string $nodeId) { + $this->nodeId = $nodeId; + } + + /** + * Getter for node id + * + * @return $nodeId Current node id + */ + public final function getNodeId () { + return $this->nodeId; + } + + /** + * Setter for private key + * + * @param $privateKey The new private key + * @return void + */ + protected final function setPrivateKey (string $privateKey) { + $this->privateKey = $privateKey; + } + + /** + * Getter for private key + * + * @return $privateKey Current private key + */ + public final function getPrivateKey () { + return $this->privateKey; + } + + /** + * Setter for private key hash + * + * @param $nodePrivateKeyHash The new private key hash + * @return void + */ + protected final function setNodePrivateKeyHash (string $nodePrivateKeyHash) { + $this->nodePrivateKeyHash = $nodePrivateKeyHash; + } + + /** + * Getter for private key hash + * + * @return $privateKeyHash Current private key hash + */ + public final function getNodePrivateKeyHash () { + return $this->nodePrivateKeyHash; + } + + /** + * Setter for session id + * + * @param $sessionId The new session id + * @return void + */ + protected final function setSessionId (string $sessionId) { + $this->sessionId = $sessionId; + } + + /** + * Getter for session id + * + * @return $sessionId Current session id + */ + public final function getSessionId () { + return $this->sessionId; + } + /** * Checks whether this node accepts announcements * @@ -743,27 +898,6 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC return $hasAnnouncementCompleted; } - /** - * Enables whether this node accepts announcements - * - * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE) - * @return void - */ - protected final function enableAcceptingAnnouncements (bool $acceptAnnouncements = TRUE) { - $this->acceptAnnouncements = $acceptAnnouncements; - } - - /** - * Enables whether this node accepts DHT bootstrap requests - * - * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE) - * @return void - */ - public final function enableAcceptDhtBootstrap (bool $acceptDhtBootstrap = TRUE) { - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: Enabling DHT bootstrap requests ...'); - $this->acceptDhtBootstrap = $acceptDhtBootstrap; - } - /** * Checks wether this node is accepting node-list requests * @@ -908,42 +1042,4 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC return $nodeData; } - /** - * Setter for listener pool instance - * - * @param $listenerPoolInstance The new listener pool instance - * @return void - */ - protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) { - $this->listenerPoolInstance = $listenerPoolInstance; - } - - /** - * Getter for listener pool instance - * - * @return $listenerPoolInstance Our current listener pool instance - */ - public final function getListenerPoolInstance () { - return $this->listenerPoolInstance; - } - - /** - * Setter for search instance - * - * @param $searchInstance Searchable criteria instance - * @return void - */ - public final function setSearchInstance (LocalSearchCriteria $searchInstance) { - $this->searchInstance = $searchInstance; - } - - /** - * Getter for search instance - * - * @return $searchInstance Searchable criteria instance - */ - public final function getSearchInstance () { - return $this->searchInstance; - } - } diff --git a/application/hub/classes/package/assembler/class_PackageAssembler.php b/application/hub/classes/package/assembler/class_PackageAssembler.php index 8bcdfceb6..14704afd0 100644 --- a/application/hub/classes/package/assembler/class_PackageAssembler.php +++ b/application/hub/classes/package/assembler/class_PackageAssembler.php @@ -440,4 +440,28 @@ class PackageAssembler extends BaseHubSystem implements Assembler, Registerable, /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-ASSEMBLER: EXIT!'); } + /** + * Checks whether start/end marker are set + * + * @param $data Data to be checked + * @return $isset Whether start/end marker are set + */ + private function ifStartEndMarkersSet (string $data) { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: data()=%d - CALLED!', strlen($data))); + + // Determine it + $isset = ( + ( + substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER + ) && ( + substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER + ) + ); + + // ... and return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-ASSEMBLER: isset=%d - EXIT!', intval($isset))); + return $isset; + } + } diff --git a/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php b/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php index 1108b6425..e4f8546de 100644 --- a/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php +++ b/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php @@ -71,7 +71,7 @@ class RawDataInputStream extends BaseStream implements InputStream { * @throws Base64EncodingBadException If the data contains characters which are not in the "alphabet" of BASE64 messages. * @throws MultipleMessageSentException If the sender has sent two messages and both end up here */ - public function streamData ($data) { + public function streamData (string $data) { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RAW-INPUT-STREAM: data(' . strlen($data) . ')=' . $data . ' - CALLED!'); @@ -109,4 +109,28 @@ class RawDataInputStream extends BaseStream implements InputStream { return $data; } + /** + * Checks whether start/end marker are set + * + * @param $data Data to be checked + * @return $isset Whether start/end marker are set + */ + private function ifStartEndMarkersSet (string $data) { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-INPUT-STREAM: data()=%d - CALLED!', strlen($data))); + + // Determine it + $isset = ( + ( + substr($data, 0, strlen(HandleableRawData::STREAM_START_MARKER)) == HandleableRawData::STREAM_START_MARKER + ) && ( + substr($data, -1 * strlen(HandleableRawData::STREAM_END_MARKER), strlen(HandleableRawData::STREAM_END_MARKER)) == HandleableRawData::STREAM_END_MARKER + ) + ); + + // ... and return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-INPUT-STREAM: isset=%d - EXIT!', intval($isset))); + return $isset; + } + } diff --git a/application/hub/classes/streams/raw_data/output/class_RawDataOutputStream.php b/application/hub/classes/streams/raw_data/output/class_RawDataOutputStream.php index 8ea061fa4..68a4243c9 100644 --- a/application/hub/classes/streams/raw_data/output/class_RawDataOutputStream.php +++ b/application/hub/classes/streams/raw_data/output/class_RawDataOutputStream.php @@ -61,7 +61,7 @@ class RawDataOutputStream extends BaseStream implements OutputStream { * @param $data The data (string mostly) to "stream" * @return $data The data (string mostly) to "stream" */ - public function streamData ($data) { + public function streamData (string $data) { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-OUTPUT-STREAM: data()=%d - CALLED!', strlen($data))); diff --git a/application/hub/interfaces/class_HubInterface.php b/application/hub/interfaces/class_HubInterface.php index 0e856696b..e18dde28a 100644 --- a/application/hub/interfaces/class_HubInterface.php +++ b/application/hub/interfaces/class_HubInterface.php @@ -33,55 +33,4 @@ use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; */ interface HubInterface extends FrameworkInterface { - /** - * Checks whether start/end marker are set - * - * @param $data Data to be checked - * @return $isset Whether start/end marker are set - */ - function ifStartEndMarkersSet ($data); - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - function getNodeId (); - - /** - * Getter for private key - * - * @return $privateKey Current private key - */ - function getPrivateKey (); - - /** - * Getter for private key hash - * - * @return $privateKeyHash Current private key hash - */ - function getNodePrivateKeyHash (); - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - function getSessionId (); - - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - function setSocketInstance (StorableSocket $socketInstance); - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - function getSocketInstance (); - } diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index fe65e72e6..e343631c5 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -56,4 +56,19 @@ interface ConnectionHelper extends HubHelper { */ function isShuttedDown (); + /** + * Setter for socket instance + * + * @param $socketInstance A StorableSocket instance + * @return void + */ + function setSocketInstance (StorableSocket $socketInstance); + + /** + * Getter for socket instance + * + * @return $socketInstance An instance of a StorableSocket class + */ + function getSocketInstance (); + } diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index 7ec1368ca..bb475d7e5 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Listener; // Import application-specific stuff +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; @@ -80,4 +81,19 @@ interface Listenable extends HubInterface { */ function getPoolInstance (); + /** + * Setter for socket instance + * + * @param $socketInstance A StorableSocket instance + * @return void + */ + function setSocketInstance (StorableSocket $socketInstance); + + /** + * Getter for socket instance + * + * @return $socketInstance An instance of a StorableSocket class + */ + function getSocketInstance (); + } diff --git a/application/hub/interfaces/nodes/class_Node.php b/application/hub/interfaces/nodes/class_Node.php index ae1a1210c..b736abbf9 100644 --- a/application/hub/interfaces/nodes/class_Node.php +++ b/application/hub/interfaces/nodes/class_Node.php @@ -218,4 +218,32 @@ interface Node extends FrameworkInterface { */ function getSearchInstance (); + /** + * Getter for node id + * + * @return $nodeId Current node id + */ + function getNodeId (); + + /** + * Getter for private key + * + * @return $privateKey Current private key + */ + function getPrivateKey (); + + /** + * Getter for private key hash + * + * @return $privateKeyHash Current private key hash + */ + function getNodePrivateKeyHash (); + + /** + * Getter for session id + * + * @return $sessionId Current session id + */ + function getSessionId (); + } diff --git a/application/hub/interfaces/shareable/info/class_ShareableInfo.php b/application/hub/interfaces/shareable/info/class_ShareableInfo.php index b48d8f2dc..314ac9d30 100644 --- a/application/hub/interfaces/shareable/info/class_ShareableInfo.php +++ b/application/hub/interfaces/shareable/info/class_ShareableInfo.php @@ -66,4 +66,19 @@ interface ShareableInfo extends HubInterface { */ function getConnectionType (); + /** + * Setter for socket instance + * + * @param $socketInstance A StorableSocket instance + * @return void + */ + function setSocketInstance (StorableSocket $socketInstance); + + /** + * Getter for socket instance + * + * @return $socketInstance An instance of a StorableSocket class + */ + function getSocketInstance (); + } diff --git a/application/hub/traits/container/socket/class_StorableSocketTrait.php b/application/hub/traits/container/socket/class_StorableSocketTrait.php new file mode 100644 index 000000000..146673b22 --- /dev/null +++ b/application/hub/traits/container/socket/class_StorableSocketTrait.php @@ -0,0 +1,55 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.shipsimu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +trait StorableSocketTrait { + /** + * A StorableSocket instance + */ + private $socketInstance = NULL; + + /** + * Setter for socket instance + * + * @param $socketInstance A StorableSocket instance + * @return void + */ + public final function setSocketInstance (StorableSocket $socketInstance) { + $this->socketInstance = $socketInstance; + } + + /** + * Getter for socket instance + * + * @return $socketInstance An instance of a StorableSocket class + */ + public final function getSocketInstance () { + return $this->socketInstance; + } + +} diff --git a/core b/core index 0ab475e77..8b3d55749 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 0ab475e77c70b60e323a87b97a73c39a695c6c13 +Subproject commit 8b3d5574973066ee9e99759f283005ca0c8d519b -- 2.39.5