From 481c2071a4c5656feb444c55d4439dbd86c0471d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 29 Oct 2020 11:50:42 +0100 Subject: [PATCH] Continued: - sorted members - public static methods are always there, no need to have them in interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...odeDistributedHashTableDatabaseWrapper.php | 18 +++---- .../socket/class_PackageSocketDiscovery.php | 2 +- .../connection/class_BaseConnectionHelper.php | 50 +++++++++---------- .../state/peer/class_PeerStateResolver.php | 2 +- .../frontend/class_NodeDhtWrapper.php | 19 +++---- .../connections/class_ConnectionHelper.php | 9 ---- .../resolver/state/class_StateResolver.php | 15 ------ 7 files changed, 41 insertions(+), 74 deletions(-) diff --git a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php index 6bfa6fb15..b5479aa19 100644 --- a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -144,15 +144,6 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp return $searchInstance; } - /** - * Getter for result instance for unpublished entries - * - * @return $unpublishedEntriesInstance Result instance - */ - public final function getUnpublishedEntriesInstance () { - return $this->unpublishedEntriesInstance; - } - /** * Prepares a "local" instance of a StoreableCriteria class with all node * data for insert/update queries. This data set contains data from *this* @@ -207,6 +198,15 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp return $dataSetInstance; } + /** + * Getter for result instance for unpublished entries + * + * @return $unpublishedEntriesInstance Result instance + */ + public final function getUnpublishedEntriesInstance () { + return $this->unpublishedEntriesInstance; + } + /** * Checks whether the local (*this*) node is registered in the DHT by * checking if the external address is found. diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index 1fce55633..172c201b2 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -228,7 +228,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera if ($helperInstance->getStateInstance() instanceof PeerStateable && $helperInstance->getPrintableState() !== $socketInstance->translateLastSocketErrorCodeToName()) { // Resolve the peer's state (but ignore return value) /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...'); - PeerStateResolver::resolveStateByPackage($helperInstance, $packageInstance, $socketInstance); + PeerStateResolver::createStateByPackageInstance($helperInstance, $packageInstance, $socketInstance); } } catch (InvalidSocketException $e) { // This cannot be fixed, so log it away diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index ef78abe86..9c2c87c72 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -113,45 +113,24 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit */ public final function __toString () { // Class name representation - $class = self::getConnectionClassNameFromSocket($this->getSocketInstance(), parent::__toString()); + $class = $this->getConnectionClassNameFromSocket(); // Return it return $class; } - /** - * Setter for isInitialized - * - * @param $isInitialized Name of used protocol in this connection - * @return void - */ - protected final function setIsInitialized ($isInitialized) { - $this->isInitialized = $isInitialized; - } - - /** - * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!) - * - * @return $isInitialized Name of used protocol in this connection - */ - protected final function isInitialized () { - return $this->isInitialized; - } - /** * Static "getter" for this connection class' name * - * @param $socketInstance An instance of a StorableSocket class - * @param $className Name of calling class * @return $class Expanded class name */ - public static function getConnectionClassNameFromSocket (StorableSocket $socketInstance, $className) { + private function getConnectionClassNameFromSocket () { // Get recipient address/port - $recipientAddress = $socketInstance->getSocketRecipientAddress(); - $recipientPort = $socketInstance->getSocketRecipientPort(); + $recipientAddress = $this->getSocketInstance()->getSocketRecipientAddress(); + $recipientPort = $this->getSocketInstance()->getSocketRecipientPort(); // Construct it - $class = sprintf('%s:%d:%s', $recipientAddress, $recipientPort, $className); + $class = sprintf('%s:%d:%s', $recipientAddress, $recipientPort, parent::__toString()); // ... and return it return $class; @@ -219,6 +198,25 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit return $rawData; } + /** + * Setter for isInitialized + * + * @param $isInitialized Name of used protocol in this connection + * @return void + */ + protected final function setIsInitialized ($isInitialized) { + $this->isInitialized = $isInitialized; + } + + /** + * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!) + * + * @return $isInitialized Name of used protocol in this connection + */ + protected final function isInitialized () { + return $this->isInitialized; + } + /** * "Accept" a visitor by simply calling it back * diff --git a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php index 42ebd2fc9..96a7e3371 100644 --- a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php +++ b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php @@ -72,7 +72,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver { * @throws InvalidSocketException If socketResource, even from getSocketResource() is no valid resource * @todo ~30% done */ - public static function resolveStateByPackage (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance) { + public static function createStateByPackageInstance (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance) { // Get temporary resolver instance $resolverInstance = self::createPeerStateResolver(); diff --git a/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php b/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php index f7c74349e..237a24e82 100644 --- a/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php @@ -33,13 +33,6 @@ use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet; * along with this program. If not, see . */ interface NodeDhtWrapper extends DatabaseWrapper { - /** - * Static getter for an array of all DHT database entries - * - * @return $elements All elements for the DHT dabase - */ - static function getAllElements (); - /** * Getter for result instance for unpublished entries * @@ -63,7 +56,7 @@ interface NodeDhtWrapper extends DatabaseWrapper { function registerLocalNode (); /** - * Updates local (*this*) node data in DHT, this is but not limited to the + * Updates local (*this*) node's data in DHT, this is but not limited to the * session id, ip number (and/or hostname) and port number. * * @return void @@ -145,18 +138,18 @@ interface NodeDhtWrapper extends DatabaseWrapper { function initEntryPublication (); /** - * Removes non-data from given array. + * Removes non-public data from given array. * - * @param $data An array with possible non-data that needs to be removed. - * @return $data A cleaned up array with only data. + * @param $data An array with possible non-public data that needs to be removed. + * @return $data A cleaned up array with only public data. */ function removeNonPublicDataFromArray(array $data); /** - * Find recipients for given package data and returns it as a result instance + * Find recipients for given package data and exclude the sender * * @param $packageInstance An instance of a DeliverablePackage class - * @return $recipients An indexed array with DHT recipients + * @return $recipients An indexed array with DHT recipients */ function getResultFromExcludedSender (DeliverablePackage $packageInstance); diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index 58f0ea6db..fe65e72e6 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -49,15 +49,6 @@ interface ConnectionHelper extends HubHelper { */ function doShutdown (); - /** - * Static "getter" for this connection class' name - * - * @param $socketInstance An instance of a StorableSocket class - * @param $className Name of calling class - * @return $class Expanded class name - */ - static function getConnectionClassNameFromSocket (StorableSocket $socketInstance, $className); - /** * Getter for shuttedDown * diff --git a/application/hub/interfaces/resolver/state/class_StateResolver.php b/application/hub/interfaces/resolver/state/class_StateResolver.php index d00d4a23e..ff33a0085 100644 --- a/application/hub/interfaces/resolver/state/class_StateResolver.php +++ b/application/hub/interfaces/resolver/state/class_StateResolver.php @@ -2,11 +2,6 @@ // Own namespace namespace Org\Shipsimu\Hub\Resolver\State; -// Import application-specific stuff -use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; -use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; - // Import framework stuff use Org\Mxchange\CoreFramework\Resolver\Resolver; @@ -33,16 +28,6 @@ use Org\Mxchange\CoreFramework\Resolver\Resolver; * along with this program. If not, see . */ interface StateResolver extends Resolver { - /** - * Returns an state instance for a given package raw data and socket resource - * - * @param $helperInstance An instance of a ConnectionHelper class - * @param $packageInstance An instance of a DeliverablePackage class - * @param $socketInstance An instance of a StorableSocket class - * @return $stateInstance An instance of a PeerStateable class - */ - static function resolveStateByPackage (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance); - /** * Checks whether the given state is valid * -- 2.39.5