From: Roland Häder Date: Fri, 18 May 2012 20:20:56 +0000 (+0000) Subject: Added internal IP handling (unfinished), added package tags X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4c4dbb818c6da362302cd02a601cce0c78413bfb;p=hub.git Added internal IP handling (unfinished), added package tags --- diff --git a/application/hub/config.php b/application/hub/config.php index a5712268d..00cfefb7d 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -285,6 +285,9 @@ $cfg->setConfigEntry('producer_incoming_queue', 'FiFoStacker'); // CFG: STACKER-ANNOUNCEMENT-MAX-SIZE $cfg->setConfigEntry('stacker_announcement_max_size', 20); +// CFG: STACKER-ANNOUNCEMENT-ANSWER-MAX-SIZE +$cfg->setConfigEntry('stacker_announcement_answer_max_size', 20); + // CFG: STACKER-SELF-CONNECT-MAX-SIZE $cfg->setConfigEntry('stacker_self_connect_max_size', 10); @@ -588,6 +591,9 @@ $cfg->setConfigEntry('session_id', ''); // CFG: EXTERNAL-IP $cfg->setConfigEntry('external_ip', ''); +// CFG: INTERNAL-IP +$cfg->setConfigEntry('internal_ip', ConsoleTools::acquireSelfIPAddress()); + // CFG: NODE-STATUS $cfg->setConfigEntry('node_status', 'invalid'); @@ -621,6 +627,10 @@ $cfg->setConfigEntry('chunk_handler_class', 'ChunkHandler'); // CFG: PACKAGE-DECODER-CLASS $cfg->setConfigEntry('package_decoder_class', 'PackageDecoder'); +// CFG: PACKAGE-RECIPIENT-MAX-COUNT +// @TODO This is very static, rewrite it to more flexible +$cfg->setConfigEntry('package_recipient_max_count', 3); + /////////////////////////////////////////////////////////////////////////////// // Peer states /////////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php index 40c9e5fe7..1879cef23 100644 --- a/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php +++ b/application/hub/exceptions/announcement/class_AnnouncementNotAcceptedException.php @@ -32,12 +32,13 @@ class AnnouncementNotAcceptedException extends FrameworkException { */ public function __construct (array $messageArray, $code) { // Construct the message - $message = sprintf("[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,ip=%s,tcp.port=%s,udp.port=%s,status=%s.", + $message = sprintf("[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,ip=%s/%s,tcp.port=%s,udp.port=%s,status=%s.", $messageArray[0]->__toString(), $this->getLine(), $messageArray[1]->__toString(), $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP], + $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT], $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS] diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 9939c6bdd..b1fdccdbd 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -27,6 +27,9 @@ class BaseHubSystem extends BaseFrameworkSystem { const EXCEPTION_CHUNK_ALREADY_ASSEMBLED = 0x901; const EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED = 0x902; + // Message status codes + const MESSAGE_STATUS_CODE_OKAY = 'OKAY'; + /** * Separator for all bootstrap node entries */ diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 5f0217506..4ec539e9c 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -97,6 +97,12 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl $this->debugBackTrace('Unsupported protocol ' . $protocol . ' specified!'); break; } // END - switch + + // Now put both together + $recipient = $recipientIp . ':' . $recipientPort; + + // Debug message + $this->debugOutput('DATABASE-WRAPPER: sessionId[' . $protocol . ']=' . $sessionId . ' resolved as recipient=' . $recipient); } // END - if // Return result diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index a5cd4e144..73a463867 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -87,7 +87,29 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable // This may be a direct recipient (node's session id) default: - $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); + /* + * Try to solve it, if an exception comes back, it is not a + * session-id, nor IP:port and not a hostname:port combination. + */ + try { + // "Explode" all recipients + $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); + + // Is maximum reached? + assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')); + + // Try it on all + foreach ($recipients as $recipient) { + // Try to sole a single recipient + $ipPort = HubTools::resolveSessionId($recipient, $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]); + + // Add it as recipient + $this->getListInstance()->addEntry('ip_port', $ipPort); + } // END - foreach + } catch (FrameworkException $e) { + // Didn't work, pleace add more code + $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',packageData=' . print_r($packageData, true) . ',exception=' . $e->__toString() . ',message=' . $e->getMessage()); + } break; } // END - switch } diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index a133e4a4d..78464e821 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -117,6 +117,9 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } // END - if + // Debug message + /* NOISY-DEBUG: */ $this->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, true)); + /* * Now we have the listener instance, we can determine the right * resource to continue. The first step is to get the attached pool diff --git a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php index 409ebc658..426664dc5 100644 --- a/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php +++ b/application/hub/main/filter/tags/class_PackageAnnouncementTagFilter.php @@ -39,6 +39,7 @@ class PackageAnnouncementTagFilter extends BaseFilter implements FilterablePacka // Init array $this->dataXmlNodes = array( XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP => '', + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '', XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT => 9060, diff --git a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php index adbd31554..368a15652 100644 --- a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php @@ -37,11 +37,19 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl // Init message data array $this->messageDataElements = array( XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP, + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT, XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT ); + + // Init message-data->configuration translation array + $this->messageToConfig = array( + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP => 'other_external_ip', + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_IP => 'other_internal_ip', + XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'other_session_id' + ); } /** @@ -102,6 +110,44 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]); } // END - foreach } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + */ + protected function initMessageConfigurationData (array $messageData) { + // "Walk" throught the translation array + foreach ($this->messageToConfig as $messageKey => $configKey) { + // Set the element in configuration + $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]); + } // END - foreach + + // Translate last exception into a status code + $statusCode = $this->getTranslatedStatusFromLastException(); + + // Set it in configuration (temporarily) + $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode); + } + + /** + * Removes configuration data with given message data array from global + * configuration + * + * @param $messageData An array with all message data + * @return void + */ + protected function removeMessageConfigurationData (array $messageData) { + // "Walk" throught the translation array again + foreach ($this->messageToConfig as $dummy => $configKey) { + // Now unset this configuration entry (to save some memory) + $this->getConfigInstance()->unsetConfigEntry($configKey); + } // END - foreach + + // Remove 'answer_status' as well + $this->getConfigInstance()->unsetConfigEntry('answer_status'); + } } // [EOF] diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 5b9382856..4763b03cd 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -1,6 +1,7 @@ * @version 0.0.0 @@ -21,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseMessageHandler extends BaseHandler { +abstract class BaseMessageHandler extends BaseHandler { /** * Array with search criteria elements */ @@ -32,6 +33,17 @@ class BaseMessageHandler extends BaseHandler { */ protected $messageDataElements = array(); + /** + * Array for translating message data elements (other node's data mostly) + * into configuration elements. + */ + protected $messageToConfig = array(); + + /** + * Last exception instance from database layer or NULL (default) + */ + private $lastException = NULL; + /** * Protected constructor * @@ -50,6 +62,34 @@ class BaseMessageHandler extends BaseHandler { ); } + /** + * Getter for last exception + * + * @return $lastException Last thrown exception + */ + protected final function getLastException () { + return $this->lastException; + } + + /** + * "Getter" for a translated last exception as a status code + * + * @return $statusCode Translated status code from last exception + */ + protected function getTranslatedStatusFromLastException () { + // Default is all fine + $statusCode = self::MESSAGE_STATUS_CODE_OKAY; + + // Is the last exception not NULL? + if ($this->lastException instanceof FrameworkException) { + // "Determine" the right status code (may differ from exception to exception) + $this->debugInstance('lastException=' . $this->lastException->__toString() . ',message=' . $this->lastException->getMessage() . ' is not finished!'); + } // END - if + + // Return the status code + return $statusCode; + } + /** * Registers an other node with this node by given message data. The * following data must always be present: @@ -88,6 +128,9 @@ class BaseMessageHandler extends BaseHandler { // Nothing found, so register it $wrapperInstance->registerNodeByMessageData($messageData, $this); } + + // Save last exception + $this->lastException = $wrapperInstance->getLastException(); } /** @@ -104,6 +147,12 @@ class BaseMessageHandler extends BaseHandler { // Load descriptor XML $helperInstance->loadDescriptorXml(); + /* + * Set missing (temporary) configuration data, mostly it needs to be + * copied from message data array. + */ + $this->initMessageConfigurationData($messageData); + // Compile any configuration variables $helperInstance->getTemplateInstance()->compileConfigInVariables(); @@ -112,7 +161,29 @@ class BaseMessageHandler extends BaseHandler { // Deliver the package $helperInstance->sendPackage($nodeInstance); + + /* + * Remove temporary configuration + */ + $this->removeMessageConfigurationData($messageData); } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function initMessageConfigurationData (array $messageData); + + /** + * Removes configuration data with given message data array from global + * configuration + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function removeMessageConfigurationData (array $messageData); } // [EOF] diff --git a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php index 642b07d99..ddaa83b01 100644 --- a/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php +++ b/application/hub/main/handler/message-types/self-connect/class_NodeMessageSelfConnectHandler.php @@ -85,6 +85,30 @@ class NodeMessageSelfConnectHandler extends BaseMessageHandler implements Handle // Please don't call this method! throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + * @throws UnsupportedOperationException If this method is called + */ + protected function initMessageConfigurationData (array $messageData) { + // Please don't call this method! + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } + + /** + * Removes configuration data with given message data array from global configuration + * + * @param $messageData An array with all message data + * @return void + * @throws UnsupportedOperationException If this method is called + */ + protected function removeMessageConfigurationData (array $messageData) { + // Please don't call this method! + throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION); + } } // [EOF] diff --git a/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php b/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php index 9605ce5ce..08ff14441 100644 --- a/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php +++ b/application/hub/main/helper/hub/answer/announcement/class_NodeAnnouncementMessageAnswerHelper.php @@ -32,8 +32,8 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements // Call parent constructor parent::__construct(__CLASS__); - // Set recipient type to 'other' - $this->setRecipientType(NetworkPackage::NETWORK_TARGET_OTHER); + // Init package tags + $this->setPackageTags(array('announcement_answer')); } /** @@ -46,6 +46,9 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements // Get new instance $helperInstance = new NodeAnnouncementMessageAnswerHelper(); + // Set session id of other peer as recipient + $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]); + // Set message data $helperInstance->setMessageData($messageData); @@ -92,7 +95,7 @@ class NodeAnnouncementMessageAnswerHelper extends BaseHubAnswerHelper implements $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this); + $packageInstance->enqueueRawDataFromTemplate($this, 'TCP'); } } diff --git a/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php b/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php index c5850d249..cfa4d407a 100644 --- a/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php +++ b/application/hub/main/helper/hub/answer/class_BaseHubAnswerHelper.php @@ -27,6 +27,12 @@ class BaseHubAnswerHelper extends BaseHubHelper { */ private $messageData = array(); + /** + * Package tags + */ + private $packageTags = array(); + + /** * Protected constructor * @@ -55,6 +61,25 @@ class BaseHubAnswerHelper extends BaseHubHelper { public final function getMessageData () { return $this->messageData; } + + /** + * Getter for package tags in a simple array + * + * @return $packageTags An array with all tags for the currently handled package + */ + public final function getPackageTags () { + return $this->packageTags; + } + + /** + * Setter for package tags in a simple array + * + * @param $packageTags An array with all tags for the currently handled package + * @return void + */ + public final function setPackageTags (array $packageTags) { + $this->packageTags = $packageTags; + } } // [EOF] diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index f36ef3727..531276919 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -125,6 +125,11 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ const PACKAGE_DATA_SEPARATOR = '#'; + /** + * Separator for more than one recipient + */ + const PACKAGE_RECIPIENT_SEPARATOR = ':'; + /** * Network target (alias): 'upper hubs' */ @@ -135,11 +140,6 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ const NETWORK_TARGET_SELF = 'self'; - /** - * Network target (alias): 'other' - */ - const NETWORK_TARGET_OTHER = 'other'; - /** * TCP package size in bytes */ @@ -413,6 +413,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Get current entry $currentRecipient = $iteratorInstance->current(); + // Debug message + $this->debugOutput('NETWORK-PACKAGE: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]); + // Set the recipient $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient; @@ -420,7 +423,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData); // Debug message - $this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient); + $this->debugOutput('NETWORK-PACKAGE: Package declared for recipient ' . $currentRecipient); // Skip to next entry $iteratorInstance->next(); @@ -462,7 +465,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $socketResource = $discoveryInstance->discoverSocket($packageData); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after discoverSocket() has been called.'); // We have to put this socket in our registry, so get an instance $registryInstance = SocketRegistry::createSocketRegistry(); @@ -471,38 +474,38 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $helperInstance = Registry::getRegistry()->getInstance('connection'); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: stateInstance=' . $helperInstance->getStateInstance()); - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: stateInstance=' . $helperInstance->getStateInstance()); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.'); // Is it not there? if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) { // Debug message - $this->debugOutput('PACKAGE: Registering socket ' . $socketResource . ' ...'); + $this->debugOutput('NETWORK-PACKAGE: Registering socket ' . $socketResource . ' ...'); // Then register it $registryInstance->registerSocket($helperInstance, $socketResource, $packageData); } elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) { // Is not connected, then we cannot send - $this->debugOutput('PACKAGE: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); + $this->debugOutput('NETWORK-PACKAGE: Unexpected peer state ' . $helperInstance->getStateInstance()->__toString() . ' detected.'); // Shutdown the socket $this->shutdownSocket($socketResource); } // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.'); // Make sure the connection is up $helperInstance->getStateInstance()->validatePeerStateConnected(); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.'); // Enqueue it again on the out-going queue, the connection is up and working at this point $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Reached line ' . __LINE__ . ' after pushNamed() has been called.'); } /** @@ -696,7 +699,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Sanity check if we have packages declared if (!$this->isPackageDeclared()) { // This is not fatal but should be avoided - $this->debugOutput('PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!'); + $this->debugOutput('NETWORK-PACKAGE: No package has been declared, but ' . __METHOD__ . ' has been called!'); return; } // END - if @@ -711,7 +714,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED); } catch (InvalidStateException $e) { // The state is not excepected (shall be 'connected') - $this->debugOutput('PACKAGE: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); + $this->debugOutput('NETWORK-PACKAGE: Caught ' . $e->__toString() . ',message=' . $e->getMessage()); // Mark the package with status failed $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED); @@ -730,7 +733,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Sanity check if we have packages waiting for delivery if (!$this->isPackageWaitingForDelivery()) { // This is not fatal but should be avoided - $this->debugOutput('PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); + $this->debugOutput('NETWORK-PACKAGE: No package is waiting for delivery, but ' . __METHOD__ . ' was called.'); return; } // END - if @@ -745,7 +748,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackerInstance()->popNamed(self::STACKER_NAME_OUTGOING); } catch (InvalidSocketException $e) { // Output exception message - $this->debugOutput('PACKAGE: Package was not delivered: ' . $e->getMessage()); + $this->debugOutput('NETWORK-PACKAGE: Package was not delivered: ' . $e->getMessage()); // Mark package as failed $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED); @@ -805,7 +808,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R } // END - if // Very noisy debug message: - /* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: Stacker size is ' . $this->getStackerInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); + /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: Stacker size is ' . $this->getStackerInstance()->getStackCount(self::STACKER_NAME_DECODED_INCOMING) . ' entries.'); // "Pop" the next entry (the same array again) from the stack $decodedData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECODED_INCOMING); @@ -848,7 +851,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $decodedData = $handlerInstance->getNextDecodedData(); // Very noisy debug message: - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true)); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: decodedData[' . gettype($decodedData) . ']=' . print_r($decodedData, true)); // And push it on our stack $this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECODED_INCOMING, $decodedData); @@ -923,13 +926,13 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ public function accept (Visitor $visitorInstance) { // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - START'); // Visit the package $visitorInstance->visitNetworkPackage($this); // Debug message - //* NOISY-DEBUG: */ $this->debugOutput('PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); + //* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: ' . $visitorInstance->__toString() . ' has visited - FINISHED'); } /** @@ -942,7 +945,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->initStackers(true); // Debug message - /* DEBUG: */ $this->debugOutput('PACKAGE: All stacker have been re-initialized.'); + /* DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: All stacker have been re-initialized.'); } /** @@ -1114,8 +1117,6 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Handle message data $handlerInstance->handleMessageData($messageArray[self::MESSAGE_ARRAY_DATA], $this); - - die(__METHOD__ . ':messageArray='.print_r($messageArray,true)); } } diff --git a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php index fca8784ee..224014728 100644 --- a/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php +++ b/application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php @@ -29,6 +29,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil const ANNOUNCEMENT_DATA_SESSION_ID = 'session-id'; const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status'; const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip'; + const ANNOUNCEMENT_DATA_INTERNAL_IP = 'internal-ip'; const ANNOUNCEMENT_DATA_TCP_PORT = 'tcp-port'; const ANNOUNCEMENT_DATA_UDP_PORT = 'udp-port'; @@ -72,6 +73,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil self::ANNOUNCEMENT_DATA_UDP_PORT, self::ANNOUNCEMENT_DATA_SESSION_ID, self::ANNOUNCEMENT_DATA_EXTERNAL_IP, + self::ANNOUNCEMENT_DATA_INTERNAL_IP, 'object-type-list', ); } @@ -265,8 +267,10 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil return false; } // END - if - // Assign the found characters to variable and use the last entry from - // stack as the name + /* + * Assign the found characters to variable and use the last entry from + * stack as the name. + */ parent::assignVariable($this->getStackerInstance()->getNamed('announcement'), $characters); } @@ -398,6 +402,16 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP); } + /** + * Starts the private ip + * + * @return void + */ + private function startInternalIp () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_INTERNAL_IP); + } + /** * Starts the object type list * @@ -448,6 +462,16 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil $this->getStackerInstance()->popNamed('announcement'); } + /** + * Finishes the private ip + * + * @return void + */ + private function finishInternalIp () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement'); + } + /** * Finishes the public ip * diff --git a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php index f24014b8e..951f62567 100644 --- a/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php +++ b/application/hub/main/template/answer/announcement/class_XmlAnnouncementAnswerTemplateEngine.php @@ -27,13 +27,27 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseTemplateEngine implements * Main nodes in the XML tree */ private $mainNodes = array( - '|||' + 'announcement-answer' ); /** * Sub nodes in the XML tree */ private $subNodes = array( + // These nodes don't contain any data + 'node-data', + 'other-data', + // Data from *this* node + 'node-external-ip', + 'node-tcp-port', + 'node-udp-port', + 'node-session-id', + 'node-status', + // Data from other node + 'other-external-ip', + 'other-session-id', + // Answer status (code) + 'answer-status' ); /** @@ -111,7 +125,7 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseTemplateEngine implements * Load a specified announcement-answer template into the engine * * @param $template The announcement-answer template we shall load which is - * located in 'announcement-answer' by default + * located in 'announcement_answer' by default * @return void */ public function loadAnnouncementAnswerTemplate ($template = 'announcement_answer') { @@ -240,10 +254,11 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseTemplateEngine implements return false; } // END - if - // Get current XML node name as an array index - $nodeName = $this->getStackerInstance()->getNamed('announcement-answer'); - - $this->partialStub('TODO: Do something with the gathered data.'); + /* + * Assign the found characters to variable and use the last entry from + * stack as the name. + */ + parent::assignVariable($this->getStackerInstance()->getNamed('announcement_answer'), $characters); } /** @@ -256,23 +271,263 @@ class XmlAnnouncementAnswerTemplateEngine extends BaseTemplateEngine implements } /** - * Starts the ||| + * Starts the announcement-answer * * @return void */ private function startAnnouncementAnswer () { // Push the node name on the stacker - $this->getStackerInstance()->pushNamed('announcement-answer', '|||'); + $this->getStackerInstance()->pushNamed('announcement_answer', 'announcement-answer'); + } + + /** + * Starts the node-data + * + * @return void + */ + private function startNodeData () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-data'); + } + + /** + * Starts the node-external-ip + * + * @return void + */ + private function startNodeExternalIp () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-external-ip'); + } + + /** + * Starts the node-internal-ip + * + * @return void + */ + private function startNodeInternalIp () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-internal-ip'); + } + + /** + * Starts the node-tcp-port + * + * @return void + */ + private function startNodeTcpPort () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-tcp-port'); + } + + /** + * Starts the node-udp-port + * + * @return void + */ + private function startNodeUdpPort () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-udp-port'); + } + + /** + * Starts the node-session-id + * + * @return void + */ + private function startNodeSessionId () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-session-id'); + } + + /** + * Starts the node-status + * + * @return void + */ + private function startNodeStatus () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'node-status'); + } + + /** + * Finishes the node-status + * + * @return void + */ + private function finishNodeStatus () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-session-id + * + * @return void + */ + private function finishNodeSessionId () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-udp-port + * + * @return void + */ + private function finishNodeUdpPort () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-tcp-port + * + * @return void + */ + private function finishNodeTcpPort () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-internal-ip + * + * @return void + */ + private function finishNodeInternalIp () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-external-ip + * + * @return void + */ + private function finishNodeExternalIp () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the node-data + * + * @return void + */ + private function finishNodeData () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Starts the other-data + * + * @return void + */ + private function startOtherData () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'other-data'); + } + + /** + * Starts the other-external-ip + * + * @return void + */ + private function startOtherExternalIp () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'other-external-ip'); + } + + /** + * Starts the other-internal-ip + * + * @return void + */ + private function startOtherInternalIp () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'other-internal-ip'); + } + + /** + * Starts the other-session-id + * + * @return void + */ + private function startOtherSessionId () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'other-session-id'); + } + + /** + * Finishes the other-session-id + * + * @return void + */ + private function finishOtherSessionId () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the other-internal-ip + * + * @return void + */ + private function finishOtherInternalIp () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the other-external-ip + * + * @return void + */ + private function finishOtherExternalIp () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Finishes the other-data + * + * @return void + */ + private function finishOtherData () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); + } + + /** + * Starts the answer-status + * + * @return void + */ + private function startAnswerStatus () { + // Push the node name on the stacker + $this->getStackerInstance()->pushNamed('announcement_answer', 'answer-status'); + } + + /** + * Finishes the answer-status + * + * @return void + */ + private function finishAnswerStatus () { + // Pop the last entry + $this->getStackerInstance()->popNamed('announcement_answer'); } /** - * Finishes the ||| + * Finishes the announcement-answer * * @return void */ private function finishAnnouncementAnswer () { // Pop the last entry - $this->getStackerInstance()->popNamed('announcement-answer'); + $this->getStackerInstance()->popNamed('announcement_answer'); } } diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 95198e7a6..fec7d60c0 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -211,6 +211,25 @@ class HubTools extends BaseHubSystem { // Return it return $ip; } + + /** + * Determine IP or 'internal_ip' if set + * + * @return $ip The determined external ip of this node + */ + public static function determineOwnInternalIp () { + // Is the external_ip config entry set? + if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip') != '') { + // Use it as internal ip + $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip'); + } else { + // Determine own internal ip by connecting to my (coder) server at 188.138.90.169 + $ip = ConsoleTools::acquireSelfIPAddress(); + } + + // Return it + return $ip; + } } // [EOF] diff --git a/application/hub/templates/xml/announcement/self_announcement.xml b/application/hub/templates/xml/announcement/self_announcement.xml index e7fc7878d..957531e0b 100644 --- a/application/hub/templates/xml/announcement/self_announcement.xml +++ b/application/hub/templates/xml/announcement/self_announcement.xml @@ -33,6 +33,8 @@ along with this program. If not, see {?external_ip?} + + {?internal_ip?} {?node_tcp_listen_port?} {?node_udp_listen_port?} diff --git a/application/hub/templates/xml/answer/announcement/announcement_answer.xml b/application/hub/templates/xml/answer/announcement/announcement_answer.xml index fbef1a408..9360edd83 100644 --- a/application/hub/templates/xml/answer/announcement/announcement_answer.xml +++ b/application/hub/templates/xml/answer/announcement/announcement_answer.xml @@ -23,4 +23,56 @@ You should have received a copy of the GNU General Public License along with this program. If not, see //--> + + + + {?external_ip?} + + {?internal_ip?} + + {?node_tcp_listen_port?} + + {?node_udp_listen_port?} + + {?session_id?} + + {?node_status?} + + + + + {?other_external_ip?} + + {?other_internal_ip?} + + {?other_session_id?} + + + {?answer_status?} diff --git a/application/hub/templates/xml/object_registry/object_registry.xml b/application/hub/templates/xml/object_registry/object_registry.xml index feabd6d8c..bdc52c341 100644 --- a/application/hub/templates/xml/object_registry/object_registry.xml +++ b/application/hub/templates/xml/object_registry/object_registry.xml @@ -39,10 +39,11 @@ along with this program. If not, see upper hub + + + + announcement_answer + + direct + + 1 + + tcp + + hub +