3 * A general hub node class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseHubNode extends BaseHubSystem implements Updateable {
28 const NODE_TYPE_BOOT = 'boot';
29 const NODE_TYPE_MASTER = 'master';
30 const NODE_TYPE_LIST = 'list';
31 const NODE_TYPE_REGULAR = 'regular';
33 // Exception constants
34 const EXCEPTION_HUB_ALREADY_ANNOUNCED = 0xe00;
37 const OBJECT_LIST_SEPARATOR = ',';
40 * IP/port number of bootstrapping node
42 private $bootIpPort = '';
45 * Query connector instance
47 private $queryConnectorInstance = NULL;
50 * Queue connector instance
52 private $queueConnectorInstance = NULL;
55 * Whether this node is anncounced (KEEP ON false!)
58 private $hubIsAnnounced = false;
61 * Whether this hub is active (default: false)
63 private $isActive = false;
66 * Whether this node accepts announcements (default: false)
68 private $acceptAnnouncements = false;
71 * Protected constructor
73 * @param $className Name of the class
76 protected function __construct ($className) {
77 // Call parent constructor
78 parent::__construct($className);
80 // Init state which sets the state to 'init'
85 * Initializes the node's state which sets it to 'init'
89 private function initState() {
91 * Get the state factory and create the initial state, we don't need
92 * the state instance here
94 NodeStateFactory::createNodeStateInstanceByName('init', $this);
98 * Generates a private key and hashes it (for speeding up things)
100 * @param $searchInstance An instance of a LocalSearchCriteria class
103 private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
104 // Get an RNG instance (Random Number Generator)
105 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
107 // Generate a pseudo-random string
108 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
110 // Get a crypto instance
111 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
113 // Hash and encrypt the string so we become a node id (also documented as "hub id")
114 $this->setPrivateKey($cryptoInstance->encryptString($randomString));
115 $this->setPrivateKeyHash($cryptoInstance->hashString($this->getPrivateKey()));
117 // Get a wrapper instance
118 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
120 // Register the node id with our wrapper
121 $wrapperInstance->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
124 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
128 * Setter for query instance
130 * @param $connectorInstance Our new query instance
133 private final function setQueryConnectorInstance (Connectable $connectorInstance) {
134 $this->queryConnectorInstance = $connectorInstance;
138 * Getter for query instance
140 * @return $connectorInstance Our new query instance
142 public final function getQueryConnectorInstance () {
143 return $this->queryConnectorInstance;
147 * Setter for queue instance
149 * @param $connectorInstance Our new queue instance
152 private final function setQueueConnectorInstance (Connectable $connectorInstance) {
153 $this->queueConnectorInstance = $connectorInstance;
157 * Getter for queue instance
159 * @return $connectorInstance Our new queue instance
161 public final function getQueueConnectorInstance () {
162 return $this->queueConnectorInstance;
166 * Getter for boot IP/port combination
168 * @return $bootIpPort The IP/port combination of the boot node
170 protected final function getBootIpPort () {
171 return $this->bootIpPort;
175 * Checks whether the given IP address matches one of the bootstrapping nodes
177 * @param $remoteAddr IP address to checkout against our bootstrapping list
178 * @return $isFound Whether the IP is found
180 protected function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
181 // By default nothing is found
184 // Run through all configured IPs
185 foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
186 // Split it up in IP/port
187 $ipPortArray = explode(':', $ipPort);
190 if ($ipPortArray[0] == $remoteAddr) {
194 // Remember the port number
195 $this->bootIpPort = $ipPort;
198 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
200 // Stop further searching
202 } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
204 * IP matches listen address. At this point we really don't care
205 * if we can really listen on that address
209 // Remember the port number
210 $this->bootIpPort = $ipPort;
213 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
215 // Stop further searching
225 * Outputs the console teaser. This should only be executed on startup or
226 * full restarts. This method generates some space around the teaser.
230 public function outputConsoleTeaser () {
231 // Get the app instance (for shortening our code)
232 $app = $this->getApplicationInstance();
235 self::createDebugInstance(__CLASS__)->debugOutput(' ');
236 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
237 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team');
238 self::createDebugInstance(__CLASS__)->debugOutput(' ');
239 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
240 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
241 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
242 self::createDebugInstance(__CLASS__)->debugOutput(' ');
246 * Generic method to acquire a hub-id. On first run this generates a new one
247 * based on many pseudo-random data. On any later run, unless the id
248 * got not removed from database, it will be restored from the database.
250 * @param $requestInstance A Requestable class
251 * @param $responseInstance A Responseable class
254 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
255 // Get a wrapper instance
256 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
258 // Now get a search criteria instance
259 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
261 // Search for the node number one which is hard-coded the default
262 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
263 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
264 $searchInstance->setLimit(1);
267 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
270 if ($resultInstance->next()) {
271 // Save the result instance in this class
272 $this->setResultInstance($resultInstance);
274 // Get the node id from result and set it
275 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
278 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
280 // Get an RNG instance (Random Number Generator)
281 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
283 // Generate a pseudo-random string
284 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
286 // Get a crypto instance
287 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
289 // Hash and encrypt the string so we become a node id (also documented as "hub id")
290 $this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
292 // Register the node id with our wrapper
293 $wrapperInstance->registerNodeId($this, $this->getRequestInstance());
296 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
301 * Generates a session id which will be sent to the other hubs and peers
305 public function bootstrapGenerateSessionId () {
306 // Now get a search criteria instance
307 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
309 // Search for the node number one which is hard-coded the default
310 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
311 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
312 $searchInstance->setLimit(1);
314 // Get an RNG instance
315 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
317 // Generate a pseudo-random string
318 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
320 // Get a crypto instance
321 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
323 // Hash and encrypt the string so we become a "node id" aka Hub-Id
324 $this->setSessionId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
326 // Get a wrapper instance
327 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
329 // Register the node id with our wrapper
330 $wrapperInstance->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
333 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
335 // Change the state because the node has auired a hub id
336 $this->getStateInstance()->nodeGeneratedSessionId();
340 * Generate a private key for en-/decryption
344 public function bootstrapGeneratePrivateKey () {
345 // Get a wrapper instance
346 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
348 // Now get a search criteria instance
349 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
351 // Search for the node number one which is hard-coded the default
352 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
353 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
354 $searchInstance->setLimit(1);
357 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
360 if ($resultInstance->next()) {
361 // Save the result instance in this class
362 $this->setResultInstance($resultInstance);
364 // Is the element set?
365 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
367 * Auto-generate the private key for e.g. out-dated database
368 * "tables". This allows a smooth update for the underlaying
371 $this->generatePrivateKeyAndHash($searchInstance);
373 // Get the node id from result and set it
374 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
375 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
378 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
382 * Generate it in a private method (no confusion with 'private
383 * method access' and 'private key' here! ;-)).
385 $this->generatePrivateKeyAndHash($searchInstance);
390 * Initializes queues which every node needs
394 protected function initGenericQueues () {
396 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: START');
398 // Set the query connector instance
399 $this->setQueryConnectorInstance(ObjectFactory::createObjectByConfiguredName('query_connector_class', array($this)));
402 $this->getQueryConnectorInstance()->doTestQuery();
404 // Set the queue connector instance
405 $this->setQueueConnectorInstance(ObjectFactory::createObjectByConfiguredName('queue_connector_class', array($this)));
408 $this->getQueueConnectorInstance()->doTestQueue();
411 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
415 * Adds hub data elements to a given dataset instance
417 * @param $criteriaInstance An instance of a storeable criteria
418 * @param $requestInstance An instance of a Requestable class
421 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance) {
422 // Add node number and type
423 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
424 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
427 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
429 // Add the session id if acquired
430 if ($this->getSessionId() != '') {
431 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
434 // Add the private key if acquired
435 if ($this->getPrivateKey() != '') {
436 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
437 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
442 * Updates a given field with new value
444 * @param $fieldName Field to update
445 * @param $fieldValue New value to store
447 * @throws DatabaseUpdateSupportException If this class does not support database updates
448 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
450 public function updateDatabaseField ($fieldName, $fieldValue) {
452 $this->partialStub('Unfinished!');
455 // Get a critieria instance
456 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
458 // Add search criteria
459 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
460 $searchInstance->setLimit(1);
462 // Now get another criteria
463 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
465 // Add criteria entry which we shall update
466 $updateInstance->addCriteria($fieldName, $fieldValue);
468 // Add the search criteria for searching for the right entry
469 $updateInstance->setSearchInstance($searchInstance);
471 // Set wrapper class name
472 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
474 // Remember the update in database result
475 $this->getResultInstance()->add2UpdateQueue($updateInstance);
479 * Announces this hub to the upper (bootstrap or list) hubs. After this is
480 * successfully done the given task is unregistered from the handler. This
481 * might look a bit overloaded here but the announcement phase isn't a
482 * simple "Hello there" message, it may later on also contain more
483 * informations like the object list.
485 * @param $taskInstance The task instance running this announcement
487 * @throws NodeAlreadyAnnouncedException If this hub is already announced
488 * @todo Change the first if() block to check for a specific state
490 public function announceSelfToUpperNodes (Taskable $taskInstance) {
491 // Is this hub node announced?
492 if ($this->hubIsAnnounced === true) {
493 // Already announced!
494 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
498 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
500 // Get a helper instance
501 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class');
503 // Load the announcement descriptor
504 $helperInstance->loadDescriptorXml();
506 // Compile all variables
507 $helperInstance->getTemplateInstance()->compileConfigInVariables();
509 // "Publish" the descriptor by sending it to the bootstrap/list nodes
510 $helperInstance->sendPackage($this);
512 // Change the state, this should be the last line except debug output
513 $this->getStateInstance()->nodeAnnouncedToUpperHubs();
516 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
520 * Does a self-connect attempt on the public IP address. This should make
521 * it sure, we are reachable from outside world. For this kind of package we
522 * don't need that overload we have in the announcement phase.
524 * @param $taskInstance The task instance running this announcement
527 public function doSelfConnection (Taskable $taskInstance) {
529 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
531 // Get a helper instance
532 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this));
534 // Load the descriptor (XML) file
535 $helperInstance->loadDescriptorXml();
537 // Compile all variables
538 $helperInstance->getTemplateInstance()->compileConfigInVariables();
540 // And send the package away
541 $helperInstance->sendPackage($this);
544 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: FINISHED');
548 * Activates the hub by doing some final preparation and setting
549 * $hubIsActive to true
551 * @param $requestInstance A Requestable class
552 * @param $responseInstance A Responseable class
555 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
556 // Checks whether a listener is still active and shuts it down if one
557 // is still listening.
558 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
559 // Shutdown them down before they can hurt anything
560 $this->shutdownListenerPool();
563 // Get the controller here
564 $controllerInstance = Registry::getRegistry()->getInstance('controller');
566 // Run all filters for the hub activation
567 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
569 // ----------------------- Last step from here ------------------------
570 // Activate the hub. This is ALWAYS the last step in this method
571 $this->getStateInstance()->nodeIsActivated();
572 // ---------------------- Last step until here ------------------------
576 * Initializes the listener pool (class)
580 public function initializeListenerPool () {
582 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: START');
584 // Get a new pool instance
585 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
587 // Get an instance of the low-level listener
588 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
590 // Setup address and port
591 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
594 * All nodes can now use the same configuration entry because it can be
595 * customized in config-local.php.
597 $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
599 // Initialize the listener
600 $listenerInstance->initListener();
602 // Get a decorator class
603 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance));
605 // Add this listener to the pool
606 $this->getListenerPoolInstance()->addListener($decoratorInstance);
608 // Get a decorator class
609 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
611 // Add this listener to the pool
612 $this->getListenerPoolInstance()->addListener($decoratorInstance);
614 // Get an instance of the low-level listener
615 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
617 // Setup address and port
618 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
621 * All nodes can now use the same configuration entry because it can be
622 * customized in config-local.php.
624 $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
626 // Initialize the listener
627 $listenerInstance->initListener();
629 // Get a decorator class
630 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance));
632 // Add this listener to the pool
633 $this->getListenerPoolInstance()->addListener($decoratorInstance);
635 // Get a decorator class
636 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
638 // Add this listener to the pool
639 $this->getListenerPoolInstance()->addListener($decoratorInstance);
642 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: FINISHED.');
646 * Restores a previously stored node list from database
650 public function bootstrapRestoreNodeList () {
652 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: START');
654 // Get a wrapper instance
655 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
657 // Now get a search criteria instance
658 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
660 // Search for the node number zero which is hard-coded the default
661 // @TODO Add some criteria, e.g. if the node is active or so
662 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
663 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
664 //$searchInstance->setLimit(1);
667 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
670 if ($resultInstance->next()) {
671 $this->partialStub('Do something for restoring the list.');
673 //self::createDebugInstance(__CLASS__)->debugOutput('HUB: ');
675 // No previously saved node list found!
676 self::createDebugInstance(__CLASS__)->debugOutput('HUB: No previously saved node list found. This is fine.');
680 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: FINISHED.');
684 * Getter for isActive attribute
686 * @return $isActive Whether the hub is active
688 public final function isNodeActive () {
689 return $this->isActive;
693 * Enables (default) or disables isActive flag
695 * @param $isActive Whether the hub is active
698 public final function enableIsActive ($isActive = true) {
699 $this->isActive = (bool) $isActive;
703 * Checks whether this node accepts announcements
705 * @return $acceptAnnouncements Whether this node accepts announcements
707 public final function isAcceptingAnnouncements () {
708 // Check it (this node must be active and not shutdown!)
709 $acceptAnnouncements = (($this->acceptAnnouncements === true) && ($this->isNodeActive()));
712 return $acceptAnnouncements;
716 * Checks whether this node has attempted to announce itself
718 * @return $hasAnnounced Whether this node has attempted to announce itself
719 * @todo Add checking if this node has been announced to the sender node
721 public function ifNodeHasAnnounced () {
722 // Simply check the state of this node
723 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncedState);
726 return $hasAnnounced;
730 * Enables whether this node accepts announcements
732 * @param $acceptAnnouncements Whether this node accepts announcements (default: true)
735 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = true) {
736 $this->acceptAnnouncements = $acceptAnnouncements;
741 * "Getter" for address:port combination
743 * @param $handlerInstance An instance of a Networkable class
744 * @return $addressPort A address:port combination for this node
746 public final function getAddressPort (Networkable $handlerInstance) {
747 // Construct config entry
748 $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port';
751 $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry);
758 * Updates/refreshes node data (e.g. status).
761 * @todo Find more to do here
763 public function updateNodeData () {
764 // Set some dummy configuration entries, e.g. node_status
765 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
769 * Handles message answer by given data array
771 * @param $messageData A valid answer message data array
772 * @param $packageInstance An instance of a Receivable class
774 * @todo Handle thrown exception
776 public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
777 // Construct configuration entry for handling class' name
778 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]) . '_handler_class';
780 // Try to get a class
781 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
784 $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
788 * "Getter" for an array of all accepted object types
790 * @return $objectList Array of all accepted object types
792 public function getListFromAcceptedObjectTypes () {
793 // Get registry instance
794 $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
797 $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);