From: Roland Häder Date: Thu, 9 Feb 2023 03:10:08 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e03ed61b9aa9fd7abde31c95fff22595b2f5bab;p=hub.git Continued: - moved non-generic constants to their proper interfaces - moved fixed strings 'internal' and 'external' to proper interface constants --- diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 69ae1c847..03273adb3 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -33,23 +33,6 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; * along with this program. If not, see . */ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface { - // Exception codes - const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x900; - const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x901; - const EXCEPTION_INVALID_CONNECTION_TYPE = 0x902; - const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0x903; - const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x904; - const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0x905; - const EXCEPTION_REQUEST_NOT_ACCEPTED = 0x906; - const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x907; - const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x908; - const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x909; - const EXCEPTION_INVALID_UNL = 0x90a; - const EXCEPTION_INVALID_PRIVATE_KEY_HASH = 0x90b; - - // Message status codes - const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; - /** * Protected constructor * diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index 3f5a73ae8..7f3ba2c71 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -294,7 +294,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { * Do not register non-existent nodes here. This is maybe fatal, * caused by "stolen" session id and/or not matching address. */ - throw new NodeSessionIdVerficationException(array($this, $messageInstance), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING); + throw new NodeSessionIdVerficationException(array($this, $messageInstance), DistributableNode::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING); } // Save last exception diff --git a/application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php b/application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php index 90e3065f9..9aabf1546 100644 --- a/application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php +++ b/application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php @@ -11,6 +11,9 @@ use Org\Shipsimu\Hub\Node\Node; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Registry\Registerable; +// Import SPL stuff +use \InvalidArgumentException; + /** * A UniversalNodeLocator discovery class * @@ -98,12 +101,17 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove public function discoverUniversalNodeLocatorByConfiguredAddress ($configKey) { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNL-DISCOVERY:configKey=' . $configKey . ' - CALLED!'); + // Validate parameter + if (empty($configKey)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "configKey" is empty'); + } else if (($configKey != DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL) && ($configKey != DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL)) { + // Can only be 'internal' or 'external' + throw new InvalidArgumentException(sprintf('configKey=%s is not expected.', $configKey)); + } // Is there cache? if (!isset($GLOBALS[__METHOD__][$configKey])) { - // Validate config key - assert(($configKey == 'internal') || ($configKey == 'external')); - /* * First get an instance from the configured hub communication protocol * type (which is mostly TCP, so you get a TcpProtocolResolver here). diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index 8ecb5c2bb..6cc3ddc64 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -4,8 +4,9 @@ namespace Org\Shipsimu\Hub\Network\Discovery\Socket; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Discovery\Recipient\BaseRecipientDiscovery; +use Org\Shipsimu\Hub\Discovery\Locator\DiscoverableUniversalNodeLocator; use Org\Shipsimu\Hub\Discovery\Protocol\ProtocolDiscovery; +use Org\Shipsimu\Hub\Discovery\Recipient\BaseRecipientDiscovery; use Org\Shipsimu\Hub\Discovery\Socket\DiscoverableSocket; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; @@ -174,7 +175,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera // Does the UNL validate? if (!$protocolInstance->isValidUniversalNodeLocatorByPackageInstance($packageInstance)) { // Not valid, throw exception - throw new InvalidUnlException(array($this, $protocolInstance, $packageInstance), BaseHubSystem::EXCEPTION_INVALID_UNL); + throw new InvalidUnlException(array($this, $protocolInstance, $packageInstance), DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_UNL); } // Get the listener instance diff --git a/application/hub/classes/handler/chunks/class_ChunkHandler.php b/application/hub/classes/handler/chunks/class_ChunkHandler.php index a0e051e07..bd50a1e8e 100644 --- a/application/hub/classes/handler/chunks/class_ChunkHandler.php +++ b/application/hub/classes/handler/chunks/class_ChunkHandler.php @@ -238,7 +238,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: chunkSplits()=%d - CALLED!', count($chunkSplits))); if (isset($this->finalPackageChunks[$chunkSplits[self::CHUNK_SPLITS_INDEX_SERIAL]])) { // Then throw an exception - throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), self::EXCEPTION_CHUNK_ALREADY_ASSEMBLED); + throw new ChunkAlreadyAssembledException(array($this, $chunkSplits), HandleableChunks::EXCEPTION_CHUNK_ALREADY_ASSEMBLED); } // Add the chunk data (index 2) to the final array and use the serial number as index diff --git a/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php b/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php index b7c892e85..c965cc8b7 100644 --- a/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php @@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Handler\Node\Message\Announcement; // Import application-specific stuff use Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseFrontend; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; -use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\Message\BaseMessageHandler; use Org\Shipsimu\Hub\Handler\Message\HandleableMessage; use Org\Shipsimu\Hub\Network\Message\DeliverableMessage; @@ -77,7 +76,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl // Init array $this->searchData = [ - XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, @@ -117,7 +116,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl * This node is not accepting announcements, then someone wants to * announce his node to a non-bootstrap and non-master node. */ - throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageInstance), BaseHubSystem::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED); + throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED); } // Register the announcing node with this node diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php index 3013120b3..7b743f6f8 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php @@ -115,7 +115,7 @@ class NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements * This node has never announced itself, so it doesn't expect * announcement answer messages. */ - throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageInstance), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED); + throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED); } // Register the announcing node with this node diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php index 856fb741f..61c35941a 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php @@ -113,7 +113,7 @@ class NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements * This DHT has never bootstrapped, so it doesn't expect * announcement answer messages. */ - throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageInstance), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED); + throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageInstance), HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED); } // Unfinished diff --git a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php index d529650d3..3045dd953 100644 --- a/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php +++ b/application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php @@ -104,7 +104,7 @@ class NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler impleme * This node has never announced itself, so it doesn't expect * request-node-list answer messages. */ - throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageInstance), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED); + throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED); } // Register the announcing node with this node diff --git a/application/hub/classes/handler/data/message-types/class_BaseMessageHandler.php b/application/hub/classes/handler/data/message-types/class_BaseMessageHandler.php index e21203b12..3369d6df2 100644 --- a/application/hub/classes/handler/data/message-types/class_BaseMessageHandler.php +++ b/application/hub/classes/handler/data/message-types/class_BaseMessageHandler.php @@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Handler\Message; use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\Data\BaseDataHandler; +use Org\Shipsimu\Hub\Handler\Message\HandleableMessage; use Org\Shipsimu\Hub\Network\Message\DeliverableMessage; use Org\Shipsimu\Hub\Network\Receive\Receivable; @@ -54,7 +55,7 @@ abstract class BaseMessageHandler extends BaseDataHandler { */ protected function getTranslatedStatusFromLastException () { // Default is all fine - $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY; + $statusCode = HandleableMessage::MESSAGE_STATUS_CODE_OKAY; // Is the last exception not NULL? if ($this->getLastException() instanceof FrameworkException) { diff --git a/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index 6dd576157..83cf9eab6 100644 --- a/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -108,7 +108,7 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl /* * This node is not accepting DHT bootstrap requests. */ - throw new DhtBootstrapNotAcceptedException(array($this, $messageInstance), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED); + throw new DhtBootstrapNotAcceptedException(array($this, $messageInstance), HandleableMessage::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED); } // Register the DHT bootstrap requesting node with this node diff --git a/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php b/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php index 593b74315..b3bbb8694 100644 --- a/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -96,7 +96,7 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha * This node is not accepting node list requests. Throw an * exception to abort any further processing. */ - throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageInstance), self::EXCEPTION_REQUEST_NOT_ACCEPTED); + throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageInstance), HandleableMessage::EXCEPTION_REQUEST_NOT_ACCEPTED); } // Register the announcing node with this node diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 8d93f1313..539f7104d 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Handler\Package; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseFrontend; +use Org\Shipsimu\Hub\Disovery\Locator\DiscoverableUniversalNodeLocator; use Org\Shipsimu\Hub\Factory\Assembler\Package\PackageAssemblerFactory; use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory; use Org\Shipsimu\Hub\Factory\Discovery\Package\PackageDiscoveryFactory; @@ -1587,7 +1588,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei throw new InvalidArgumentException('messageInstance does not contain senderId'); } elseif (empty($messageInstance->getSenderPrivateKeyHash())) { // This needs fixing - throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH); + throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH); } elseif (!$this->isMessageContentHashValid($messageInstance)) { // Is not valid, so throw an exception here ApplicationEntryPoint::exitApplication(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL); @@ -1640,7 +1641,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei throw new InvalidArgumentException('packageInstance does not contain senderId'); } elseif (empty($packageInstance->getSenderPrivateKeyHash())) { // This needs fixing - throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), BaseHubSystem::EXCEPTION_INVALID_PRIVATE_KEY_HASH); + throw new InvalidPrivateKeyHashException(array($this, $senderData, 'empty hash in decodedData'), DiscoverableUniversalNodeLocator::EXCEPTION_INVALID_PRIVATE_KEY_HASH); } elseif (!$this->isPackageContentHashValid($packageInstance)) { // Is not valid, so throw an exception here ApplicationEntryPoint::exitApplication(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . PHP_EOL); diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 9c72c2e30..2b2029e65 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -60,7 +60,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit use StorableSocketTrait; // Exception codes - const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100; + const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0xf00; /** * Sent data in bytes diff --git a/application/hub/classes/pools/peer/class_DefaultPeerPool.php b/application/hub/classes/pools/peer/class_DefaultPeerPool.php index 622682b10..4655d04a2 100644 --- a/application/hub/classes/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/classes/pools/peer/class_DefaultPeerPool.php @@ -118,7 +118,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Is the connection type valid? if (!$socketInstance->isValidConnectionType($connectionType)) { // Is not a valid connection type! - throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE); + throw new InvalidConnectionTypeException(array($this, $connectionType), StorableSocket::EXCEPTION_INVALID_CONNECTION_TYPE); } // Default is this peer's IP diff --git a/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php index b142e835e..ff686c5ff 100644 --- a/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php +++ b/application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php @@ -5,6 +5,7 @@ namespace Org\Shipsimu\Hub\Resolver\Protocol\Tcp; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Database\Frontend\Node\Information\NodeInformationDatabaseFrontend; +use Org\Shipsimu\Hub\Discovery\Locator\DiscoverableUniversalNodeLocator; use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Org\Shipsimu\Hub\Node\Node; use Org\Shipsimu\Hub\Resolver\Protocol\BaseProtocolResolver; @@ -120,11 +121,11 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv if (empty($address)) { // Okay, then find it switch ($configKey) { - case 'external': // External IP + case DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL: // External IP $address = ConsoleTools::determineExternalAddress(); break; - case 'internal': // Internal IP + case DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL: // Internal IP $address = ConsoleTools::acquireSelfIPAddress(); break; } 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 7fc371633..e27ba2398 100644 --- a/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php +++ b/application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Stream\Network\Input\RawData; // Import application-specific stuff use Org\Shipsimu\Hub\Generic\BaseHubSystem; +use Org\Shipsimu\Hub\Handler\Message\HandleableMessage; use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; // Import framework stuff @@ -89,7 +90,7 @@ class RawDataInputStream extends BaseStream implements InputStream { throw new InvalidArgumentException(sprintf('data=%s has different count of start/end markers set', $data)); } elseif (substr_count($data, HandleableRawData::STREAM_START_MARKER) > 1) { // Please do it outside this method - throw new MultipleMessageSentException(array($this, $data), BaseHubSystem::EXCEPTION_MULTIPLE_MESSAGE_SENT); + throw new MultipleMessageSentException(array($this, $data), HandleableMessage::EXCEPTION_MULTIPLE_MESSAGE_SENT); } // Remove both @@ -98,10 +99,10 @@ class RawDataInputStream extends BaseStream implements InputStream { // Can it be validated? if ((strlen($data) % 4) != 0) { // Length modulo 4 must be zero, else it is an invalid Base64 message - throw new Base64EncodingModuloException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4); + throw new Base64EncodingModuloException(array($this, $data), HubInterface::EXCEPTION_BASE64_ENCODING_NOT_MODULO_4); } elseif (!$this->isBase64Encoded($data)) { // Is not a valid Base64-encoded message - throw new Base64EncodingBadException(array($this, $data), BaseHubSystem::EXCEPTION_BASE64_BAD_ENCODING); + throw new Base64EncodingBadException(array($this, $data), HubInterface::EXCEPTION_BASE64_BAD_ENCODING); } else { // Decode the data with BASE64-encoding $data = base64_decode($data); diff --git a/application/hub/classes/tools/hub/class_HubTools.php b/application/hub/classes/tools/hub/class_HubTools.php index fcdcda415..427ddb33b 100644 --- a/application/hub/classes/tools/hub/class_HubTools.php +++ b/application/hub/classes/tools/hub/class_HubTools.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Tools; // Import application-specific stuff use Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseFrontend; +use Org\Shipsimu\Hub\Discovery\Locator\DiscoverableUniversalNodeLocator; use Org\Shipsimu\Hub\Factory\Dht\DhtObjectFactory; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; @@ -257,20 +258,20 @@ class HubTools extends BaseHubSystem { public static function determineOwnExternalAddress () { // Is the external_address config entry set? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!'); - if (isset(self::$cachedAddresses['external'])) { + if (isset(self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL])) { // Get entry from cache //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting external address from cache ...'); - $unl = self::$cachedAddresses['external']; + $unl = self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL]; } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address') != '') { // Use it as external address //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry external_address ...'); $unl = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('external_address'); - self::$cachedAddresses['external'] = $unl; + self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL] = $unl; } else { // Determine own external address by connecting to home server at 188.138.90.169 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Invoking self::determineExternalUniversalNodeLocator() ...'); $unl = self::determineExternalUniversalNodeLocator(); - self::$cachedAddresses['external'] = $unl; + self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL] = $unl; } // Return it @@ -286,25 +287,25 @@ class HubTools extends BaseHubSystem { public static function determineOwnInternalAddress () { // Is the internal_address config entry set? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: CALLED!'); - if (isset(self::$cachedAddresses['internal'])) { + if (isset(self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL])) { // Get entry from cache //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting internal address from cache ...'); - $unl = self::$cachedAddresses['internal']; + $unl = self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL]; } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('allow_publish_internal_address') == 'N') { // Not allowed to publish internal address, so use external //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Invoking self::determineOwnExternalAddress() as allow_publish_internal_address=N is set ...'); $unl = self::determineOwnExternalAddress(); - self::$cachedAddresses['internal'] = $unl; + self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL] = $unl; } elseif (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address') != '') { // Use it as internal address //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Getting config entry internal_address ...'); $unl = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('internal_address'); - self::$cachedAddresses['internal'] = $unl; + self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL] = $unl; } else { // Determine own internal address //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: Invoking self::determineInternalUniversalNodeLocator() ...'); $unl = self::determineInternalUniversalNodeLocator(); - self::$cachedAddresses['internal'] = $unl; + self::$cachedAddresses[DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL] = $unl; } // Return it @@ -324,7 +325,7 @@ class HubTools extends BaseHubSystem { $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); // 2) "Determine" it - $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal'); + $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress(DiscoverableUniversalNodeLocator::UNL_TYPE_INTERNAL); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!'); @@ -343,7 +344,7 @@ class HubTools extends BaseHubSystem { $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); // 2) "Determine" it - $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external'); + $unl = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress(DiscoverableUniversalNodeLocator::UNL_TYPE_EXTERNAL); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TOOLS: unl=' . $unl . ' - EXIT!'); diff --git a/application/hub/interfaces/class_HubInterface.php b/application/hub/interfaces/class_HubInterface.php index 00a9dd74b..135cb4cbc 100644 --- a/application/hub/interfaces/class_HubInterface.php +++ b/application/hub/interfaces/class_HubInterface.php @@ -29,5 +29,8 @@ use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; * along with this program. If not, see . */ interface HubInterface extends FrameworkInterface { + // Exception codes + const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4 = 0x910; + const EXCEPTION_BASE64_BAD_ENCODING = 0x911; } diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index cd0d27df5..94013338f 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -74,6 +74,9 @@ interface StorableSocket extends FrameworkInterface { */ const CONNECTION_TYPE_SERVER = 'server'; + // Exception codes + const EXCEPTION_INVALID_CONNECTION_TYPE = 0xd00; + /** * Tries to bind to attached socket file * diff --git a/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php index 8bbf3f6dc..bf143823d 100644 --- a/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php +++ b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php @@ -31,6 +31,14 @@ use Org\Mxchange\CoreFramework\Discovery\Discoverable; * along with this program. If not, see . */ interface DiscoverableUniversalNodeLocator extends Discoverable { + // Exception constants + const EXCEPTION_INVALID_UNL = 0x920; + const EXCEPTION_INVALID_PRIVATE_KEY_HASH = 0x921; + + // UNL address types + const UNL_TYPE_INTERNAL = 'internal'; + const UNL_TYPE_EXTERNAL = 'external'; + /** * "Discovers" an instance of a LocateableNode class for given Node class * diff --git a/application/hub/interfaces/distributable/node/class_DistributableNode.php b/application/hub/interfaces/distributable/node/class_DistributableNode.php index 92745bfcd..a917c75ec 100644 --- a/application/hub/interfaces/distributable/node/class_DistributableNode.php +++ b/application/hub/interfaces/distributable/node/class_DistributableNode.php @@ -33,6 +33,9 @@ use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet; * along with this program. If not, see . */ interface DistributableNode extends Distributable { + // Exception constants + const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0xb00; + /** * Finds a node locally by given session id * diff --git a/application/hub/interfaces/handler/chunks/class_HandleableChunks.php b/application/hub/interfaces/handler/chunks/class_HandleableChunks.php index f919b2539..932e66397 100644 --- a/application/hub/interfaces/handler/chunks/class_HandleableChunks.php +++ b/application/hub/interfaces/handler/chunks/class_HandleableChunks.php @@ -31,6 +31,9 @@ use Org\Mxchange\CoreFramework\Handler\Handleable; * along with this program. If not, see . */ interface HandleableChunks extends Handleable, HubInterface { + // Exception codes + const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x900; + /** * Adds all chunks if the last one verifies as a 'final chunk'. * diff --git a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php b/application/hub/interfaces/handler/message-types/class_HandleableMessage.php deleted file mode 100644 index 43d50587d..000000000 --- a/application/hub/interfaces/handler/message-types/class_HandleableMessage.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 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 . - */ -interface HandleableMessage extends HandleableDataSet, HubInterface { - /** - * Handles data array of the message - * - * @param $messageData An instance of a DeliverableMessage class - * @param $handlerInstance An instance of a Receivable class - * @return void - */ - function handleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance); - - /** - * Posty-handles data array of the message - * - * @param $messageData An instance of a DeliverableMessage class - * @param $handlerInstance An instance of a Receivable class - * @return void - */ - function postHandleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance); - -} diff --git a/application/hub/interfaces/handler/messages/class_HandleableMessage.php b/application/hub/interfaces/handler/messages/class_HandleableMessage.php new file mode 100644 index 000000000..414b0f0ea --- /dev/null +++ b/application/hub/interfaces/handler/messages/class_HandleableMessage.php @@ -0,0 +1,65 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 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 . + */ +interface HandleableMessage extends HandleableDataSet, HubInterface { + // Exception constants + const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0xa00; + const EXCEPTION_REQUEST_NOT_ACCEPTED = 0xa01; + const EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED = 0xa02; + const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0xa03; + const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0xa04; + const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0xa05; + + // Message status codes + const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; + + /** + * Handles data array of the message + * + * @param $messageData An instance of a DeliverableMessage class + * @param $handlerInstance An instance of a Receivable class + * @return void + */ + function handleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance); + + /** + * Posty-handles data array of the message + * + * @param $messageData An instance of a DeliverableMessage class + * @param $handlerInstance An instance of a Receivable class + * @return void + */ + function postHandleMessageData (DeliverableMessage $messageInstance, Receivable $handlerInstance); + +}