]> git.mxchange.org Git - hub.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 9 Feb 2023 03:10:08 +0000 (04:10 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 9 Feb 2023 03:10:08 +0000 (04:10 +0100)
- moved non-generic constants to their proper interfaces
- moved fixed strings 'internal' and 'external' to proper interface constants

25 files changed:
application/hub/classes/class_BaseHubSystem.php
application/hub/classes/dht/node/class_NodeDhtFacade.php
application/hub/classes/discovery/node/class_UniversalNodeLocatorDiscovery.php
application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php
application/hub/classes/handler/chunks/class_ChunkHandler.php
application/hub/classes/handler/data/message-types/announcement/class_NodeMessageAnnouncementHandler.php
application/hub/classes/handler/data/message-types/answer/class_NodeMessageAnnouncementAnswerHandler.php
application/hub/classes/handler/data/message-types/answer/class_NodeMessageDhtBootstrapAnswerHandler.php
application/hub/classes/handler/data/message-types/answer/class_NodeMessageRequestNodeListAnswerHandler.php
application/hub/classes/handler/data/message-types/class_BaseMessageHandler.php
application/hub/classes/handler/data/message-types/dht/class_NodeMessageDhtBootstrapHandler.php
application/hub/classes/handler/data/message-types/requests/class_NodeMessageRequestNodeListHandler.php
application/hub/classes/handler/package/class_NetworkPackageHandler.php
application/hub/classes/helper/connection/class_BaseConnectionHelper.php
application/hub/classes/pools/peer/class_DefaultPeerPool.php
application/hub/classes/resolver/protocol/tcp/class_TcpProtocolResolver.php
application/hub/classes/streams/raw_data/input/class_RawDataInputStream.php
application/hub/classes/tools/hub/class_HubTools.php
application/hub/interfaces/class_HubInterface.php
application/hub/interfaces/container/socket/class_StorableSocket.php
application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php
application/hub/interfaces/distributable/node/class_DistributableNode.php
application/hub/interfaces/handler/chunks/class_HandleableChunks.php
application/hub/interfaces/handler/message-types/class_HandleableMessage.php [deleted file]
application/hub/interfaces/handler/messages/class_HandleableMessage.php [new file with mode: 0644]

index 69ae1c847910580071e138eb3e901e03eb8485f3..03273adb3bac6b33a6c98b5dda40d767f652c4cd 100644 (file)
@@ -33,23 +33,6 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 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
         *
index 3f5a73ae8df73cd160112828d2a52e091bca24c4..7f3ba2c71fa6c9e329266dafa6b2fa815873cfab 100644 (file)
@@ -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
index 90e3065f98f9846a40883552524984d4544a1259..9aabf154615bdf93f3bb94c21b2757ce9f20818c 100644 (file)
@@ -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).
index 8ecb5c2bb6b07fe48ad34f085f6a31051698480a..6cc3ddc64024b5028498b128d16c23cbe2aebb5c 100644 (file)
@@ -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
index a0e051e0781ee29c4a5397557b13b4af9dfae4d3..bd50a1e8e3a5de68613daea3186e8b69ad3108ed 100644 (file)
@@ -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
index b7c892e85b48d47e663f884f356d51491e0ef756..c965cc8b7b13697d7b729a0e706be2224063eac9 100644 (file)
@@ -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
index 3013120b365a7da86c8696f67942fc265ba27858..7b743f6f8d24f717bc84dc14185260691e591c1f 100644 (file)
@@ -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
index 856fb741ff5b5f48ce4056f4db8aaa17d8ab1b61..61c35941a3bb1e31dae5704a328065daaf9ed3a1 100644 (file)
@@ -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
index d529650d34f47f8861a783279c431dc3874ac243..3045dd95308debadabb7a60065d1adc486a9b715 100644 (file)
@@ -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
index e21203b1263d8dcb43979f5994c892a8c58bb803..3369d6df223a5323dcedc629846f44f5815253e7 100644 (file)
@@ -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) {
index 6dd576157bcf68d6f61ab0fed367e7093be34b53..83cf9eab6a934024b40363e7d3dd598c8da0f47e 100644 (file)
@@ -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
index 593b7431598b04d65e950a6b00150642b4690890..b3bbb86940bc842b2154bc9bb703e7e0eaa2e94d 100644 (file)
@@ -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
index 8d93f13130372248461054bf30aa02766e663db1..539f7104d6e8fb379bfdcce01e5901cded7c670c 100644 (file)
@@ -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);
index 9c72c2e30ac129b342a40f11dfa946efc158bd81..2b2029e65070333a4469773b3913316ff2f288fd 100644 (file)
@@ -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
index 622682b1006aa89df4b16c971ccb3f5b9dfe8c21..4655d04a2d2f38c4bf4bbb5a8944c9dfcc1360f3 100644 (file)
@@ -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
index b142e835e7ce132d78435f54afb1777a39fed7d3..ff686c5ff06617fde9b5e16709853d0bf9057178 100644 (file)
@@ -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;
                        }
index 7fc371633e9a6abe3fe744e51a6ad5f1be6d8182..e27ba23980192c321743ddb6a288c16ca5869dca 100644 (file)
@@ -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);
index fcdcda41577c1048df09e9a82b866dbc8387ecfe..427ddb33baf59996561459bbf01392d3495954f7 100644 (file)
@@ -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!');
index 00a9dd74bd37177ef5ff0a81006f2fcb60b32187..135cb4cbc591419b2a2b4c28fc7f98799641497d 100644 (file)
@@ -29,5 +29,8 @@ use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface HubInterface extends FrameworkInterface {
+       // Exception codes
+       const EXCEPTION_BASE64_ENCODING_NOT_MODULO_4  = 0x910;
+       const EXCEPTION_BASE64_BAD_ENCODING           = 0x911;
 
 }
index cd0d27df579ef22c6d1ed140128e1e7b41aeae3d..94013338fb977bf6990e567f4bd523cf09ec2f3c 100644 (file)
@@ -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
         *
index 8bbf3f6dc2fdbd1f781a728ffeb564312acd97ae..bf143823d73820b19c2f23ac017575cf93982492 100644 (file)
@@ -31,6 +31,14 @@ use Org\Mxchange\CoreFramework\Discovery\Discoverable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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
         *
index 92745bfcd87b5ebdaaab96d1ec1deb5cf59badc2..a917c75ec2b02971c069a7ddbd343b3784bb3267 100644 (file)
@@ -33,6 +33,9 @@ use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface DistributableNode extends Distributable {
+       // Exception constants
+       const EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING = 0xb00;
+
        /**
         * Finds a node locally by given session id
         *
index f919b253948c8fe6a5fe7af6038699451863d3e0..932e66397b5308ecec7ffeff497e32349d32469c 100644 (file)
@@ -31,6 +31,9 @@ use Org\Mxchange\CoreFramework\Handler\Handleable;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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 (file)
index 43d5058..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-// Own namespace
-namespace Org\Shipsimu\Hub\Handler\Message;
-
-// Import application-specific stuff
-use Org\Shipsimu\Hub\Generic\HubInterface;
-use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
-use Org\Shipsimu\Hub\Network\Receive\Receivable;
-
-// Import framework stuff
-use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
-
-/**
- * An interface for message handlers
- *
- * @author             Roland Haeder <webmaster@shipsimu.org>
- * @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 <http://www.gnu.org/licenses/>.
- */
-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 (file)
index 0000000..414b0f0
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+// Own namespace
+namespace Org\Shipsimu\Hub\Handler\Message;
+
+// Import application-specific stuff
+use Org\Shipsimu\Hub\Generic\HubInterface;
+use Org\Shipsimu\Hub\Network\Message\DeliverableMessage;
+use Org\Shipsimu\Hub\Network\Receive\Receivable;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet;
+
+/**
+ * An interface for message handlers
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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);
+
+}