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 * IP/port number of bootstrapping node
39 private $bootIpPort = '';
42 * Query connector instance
44 private $queryConnectorInstance = NULL;
47 * Queue connector instance
49 private $queueConnectorInstance = NULL;
52 * Whether this node is anncounced (KEEP ON false!)
55 private $hubIsAnnounced = false;
58 * Whether this hub is active (default: false)
60 private $isActive = false;
63 * Whether this node accepts announcements (default: false)
65 private $acceptAnnouncements = false;
68 * Protected constructor
70 * @param $className Name of the class
73 protected function __construct ($className) {
74 // Call parent constructor
75 parent::__construct($className);
77 // Init state which sets the state to 'init'
82 * Initializes the node's state which sets it to 'init'
86 private function initState() {
88 * Get the state factory and create the initial state, we don't need
89 * the state instance here
91 NodeStateFactory::createNodeStateInstanceByName('init', $this);
95 * Generates a private key and hashes it (for speeding up things)
97 * @param $searchInstance An instance of a LocalSearchCriteria class
100 private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
101 // Get an RNG instance (Random Number Generator)
102 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
104 // Generate a pseudo-random string
105 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
107 // Get a crypto instance
108 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
110 // Hash and encrypt the string so we become a node id (also documented as "hub id")
111 $this->setPrivateKey($cryptoInstance->encryptString($randomString));
112 $this->setPrivateKeyHash($cryptoInstance->hashString($this->getPrivateKey()));
114 // Get a wrapper instance
115 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
117 // Register the node id with our wrapper
118 $wrapperInstance->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
121 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
125 * Setter for query instance
127 * @param $connectorInstance Our new query instance
130 private final function setQueryConnectorInstance (Connectable $connectorInstance) {
131 $this->queryConnectorInstance = $connectorInstance;
135 * Getter for query instance
137 * @return $connectorInstance Our new query instance
139 public final function getQueryConnectorInstance () {
140 return $this->queryConnectorInstance;
144 * Setter for queue instance
146 * @param $connectorInstance Our new queue instance
149 private final function setQueueConnectorInstance (Connectable $connectorInstance) {
150 $this->queueConnectorInstance = $connectorInstance;
154 * Getter for queue instance
156 * @return $connectorInstance Our new queue instance
158 public final function getQueueConnectorInstance () {
159 return $this->queueConnectorInstance;
163 * Getter for boot IP/port combination
165 * @return $bootIpPort The IP/port combination of the boot node
167 protected final function getBootIpPort () {
168 return $this->bootIpPort;
172 * Checks whether the given IP address matches one of the bootstrapping nodes
174 * @param $remoteAddr IP address to checkout against our bootstrapping list
175 * @return $isFound Whether the IP is found
177 protected function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
178 // By default nothing is found
181 // Run through all configured IPs
182 foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
183 // Split it up in IP/port
184 $ipPortArray = explode(':', $ipPort);
187 if ($ipPortArray[0] == $remoteAddr) {
191 // Remember the port number
192 $this->bootIpPort = $ipPort;
195 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
197 // Stop further searching
199 } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
201 * IP matches listen address. At this point we really don't care
202 * if we can really listen on that address
206 // Remember the port number
207 $this->bootIpPort = $ipPort;
210 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
212 // Stop further searching
222 * Outputs the console teaser. This should only be executed on startup or
223 * full restarts. This method generates some space around the teaser.
227 public function outputConsoleTeaser () {
228 // Get the app instance (for shortening our code)
229 $app = $this->getApplicationInstance();
232 self::createDebugInstance(__CLASS__)->debugOutput(' ');
233 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
234 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team');
235 self::createDebugInstance(__CLASS__)->debugOutput(' ');
236 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
237 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
238 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
239 self::createDebugInstance(__CLASS__)->debugOutput(' ');
243 * Generic method to acquire a hub-id. On first run this generates a new one
244 * based on many pseudo-random data. On any later run, unless the id
245 * got not removed from database, it will be restored from the database.
247 * @param $requestInstance A Requestable class
248 * @param $responseInstance A Responseable class
251 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
252 // Get a wrapper instance
253 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
255 // Now get a search criteria instance
256 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
258 // Search for the node number one which is hard-coded the default
259 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
260 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
261 $searchInstance->setLimit(1);
264 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
267 if ($resultInstance->next()) {
268 // Save the result instance in this class
269 $this->setResultInstance($resultInstance);
271 // Get the node id from result and set it
272 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
275 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
277 // Get an RNG instance (Random Number Generator)
278 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
280 // Generate a pseudo-random string
281 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
283 // Get a crypto instance
284 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
286 // Hash and encrypt the string so we become a node id (also documented as "hub id")
287 $this->setNodeId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
289 // Register the node id with our wrapper
290 $wrapperInstance->registerNodeId($this, $this->getRequestInstance());
293 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
298 * Generates a session id which will be sent to the other hubs and peers
302 public function bootstrapGenerateSessionId () {
303 // Now get a search criteria instance
304 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
306 // Search for the node number one which is hard-coded the default
307 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
308 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
309 $searchInstance->setLimit(1);
311 // Get an RNG instance
312 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
314 // Generate a pseudo-random string
315 $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
317 // Get a crypto instance
318 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
320 // Hash and encrypt the string so we become a "node id" aka Hub-Id
321 $this->setSessionId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
323 // Get a wrapper instance
324 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
326 // Register the node id with our wrapper
327 $wrapperInstance->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
330 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
332 // Change the state because the node has auired a hub id
333 $this->getStateInstance()->nodeGeneratedSessionId();
337 * Generate a private key for en-/decryption
341 public function bootstrapGeneratePrivateKey () {
342 // Get a wrapper instance
343 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
345 // Now get a search criteria instance
346 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
348 // Search for the node number one which is hard-coded the default
349 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
350 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
351 $searchInstance->setLimit(1);
354 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
357 if ($resultInstance->next()) {
358 // Save the result instance in this class
359 $this->setResultInstance($resultInstance);
361 // Is the element set?
362 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
364 * Auto-generate the private key for e.g. out-dated database
365 * "tables". This allows a smooth update for the underlaying
368 $this->generatePrivateKeyAndHash($searchInstance);
370 // Get the node id from result and set it
371 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
372 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
375 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
379 * Generate it in a private method (no confusion with 'private
380 * method access' and 'private key' here! ;-)).
382 $this->generatePrivateKeyAndHash($searchInstance);
387 * Initializes queues which every node needs
391 protected function initGenericQueues () {
393 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: START');
395 // Set the query connector instance
396 $this->setQueryConnectorInstance(ObjectFactory::createObjectByConfiguredName('query_connector_class', array($this)));
399 $this->getQueryConnectorInstance()->doTestQuery();
401 // Set the queue connector instance
402 $this->setQueueConnectorInstance(ObjectFactory::createObjectByConfiguredName('queue_connector_class', array($this)));
405 $this->getQueueConnectorInstance()->doTestQueue();
408 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
412 * Adds hub data elements to a given dataset instance
414 * @param $criteriaInstance An instance of a storeable criteria
415 * @param $requestInstance An instance of a Requestable class
418 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance) {
419 // Add node number and type
420 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
421 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
424 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
426 // Add the session id if acquired
427 if ($this->getSessionId() != '') {
428 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
431 // Add the private key if acquired
432 if ($this->getPrivateKey() != '') {
433 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
434 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
439 * Updates a given field with new value
441 * @param $fieldName Field to update
442 * @param $fieldValue New value to store
444 * @throws DatabaseUpdateSupportException If this class does not support database updates
445 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
447 public function updateDatabaseField ($fieldName, $fieldValue) {
449 $this->partialStub('Unfinished!');
452 // Get a critieria instance
453 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
455 // Add search criteria
456 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
457 $searchInstance->setLimit(1);
459 // Now get another criteria
460 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
462 // Add criteria entry which we shall update
463 $updateInstance->addCriteria($fieldName, $fieldValue);
465 // Add the search criteria for searching for the right entry
466 $updateInstance->setSearchInstance($searchInstance);
468 // Set wrapper class name
469 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
471 // Remember the update in database result
472 $this->getResultInstance()->add2UpdateQueue($updateInstance);
476 * Announces this hub to the upper (bootstrap or list) hubs. After this is
477 * successfully done the given task is unregistered from the handler. This
478 * might look a bit overloaded here but the announcement phase isn't a
479 * simple "Hello there" message, it may later on also contain more
480 * informations like the object list.
482 * @param $taskInstance The task instance running this announcement
484 * @throws NodeAlreadyAnnouncedException If this hub is already announced
485 * @todo Change the first if() block to check for a specific state
487 public function announceSelfToUpperNodes (Taskable $taskInstance) {
488 // Is this hub node announced?
489 if ($this->hubIsAnnounced === true) {
490 // Already announced!
491 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
495 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
497 // Get a helper instance
498 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class');
500 // Load the announcement descriptor
501 $helperInstance->loadDescriptorXml();
503 // Compile all variables
504 $helperInstance->getTemplateInstance()->compileConfigInVariables();
506 // "Publish" the descriptor by sending it to the bootstrap/list nodes
507 $helperInstance->sendPackage($this);
509 // Change the state, this should be the last line except debug output
510 $this->getStateInstance()->nodeAnnouncedToUpperHubs();
513 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
517 * Does a self-connect attempt on the public IP address. This should make
518 * it sure, we are reachable from outside world. For this kind of package we
519 * don't need that overload we have in the announcement phase.
521 * @param $taskInstance The task instance running this announcement
524 public function doSelfConnection (Taskable $taskInstance) {
526 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
528 // Get a helper instance
529 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this));
531 // Load the descriptor (XML) file
532 $helperInstance->loadDescriptorXml();
534 // Compile all variables
535 $helperInstance->getTemplateInstance()->compileConfigInVariables();
537 // And send the package away
538 $helperInstance->sendPackage($this);
541 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: FINISHED');
545 * Activates the hub by doing some final preparation and setting
546 * $hubIsActive to true
548 * @param $requestInstance A Requestable class
549 * @param $responseInstance A Responseable class
552 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
553 // Checks whether a listener is still active and shuts it down if one
554 // is still listening.
555 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
556 // Shutdown them down before they can hurt anything
557 $this->shutdownListenerPool();
560 // Get the controller here
561 $controllerInstance = Registry::getRegistry()->getInstance('controller');
563 // Run all filters for the hub activation
564 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
566 // ----------------------- Last step from here ------------------------
567 // Activate the hub. This is ALWAYS the last step in this method
568 $this->getStateInstance()->nodeIsActivated();
569 // ---------------------- Last step until here ------------------------
573 * Initializes the listener pool (class)
577 public function initializeListenerPool () {
579 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: START');
581 // Get a new pool instance
582 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
584 // Get an instance of the low-level listener
585 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
587 // Setup address and port
588 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
591 * All nodes can now use the same configuration entry because it can be
592 * customized in config-local.php.
594 $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
596 // Initialize the listener
597 $listenerInstance->initListener();
599 // Get a decorator class
600 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance));
602 // Add this listener to the pool
603 $this->getListenerPoolInstance()->addListener($decoratorInstance);
605 // Get a decorator class
606 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
608 // Add this listener to the pool
609 $this->getListenerPoolInstance()->addListener($decoratorInstance);
611 // Get an instance of the low-level listener
612 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
614 // Setup address and port
615 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
618 * All nodes can now use the same configuration entry because it can be
619 * customized in config-local.php.
621 $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
623 // Initialize the listener
624 $listenerInstance->initListener();
626 // Get a decorator class
627 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance));
629 // Add this listener to the pool
630 $this->getListenerPoolInstance()->addListener($decoratorInstance);
632 // Get a decorator class
633 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
635 // Add this listener to the pool
636 $this->getListenerPoolInstance()->addListener($decoratorInstance);
639 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: FINISHED.');
643 * Restores a previously stored node list from database
647 public function bootstrapRestoreNodeList () {
649 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: START');
651 // Get a wrapper instance
652 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
654 // Now get a search criteria instance
655 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
657 // Search for the node number zero which is hard-coded the default
658 // @TODO Add some criteria, e.g. if the node is active or so
659 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
660 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
661 //$searchInstance->setLimit(1);
664 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
667 if ($resultInstance->next()) {
668 $this->partialStub('Do something for restoring the list.');
670 //self::createDebugInstance(__CLASS__)->debugOutput('HUB: ');
672 // No previously saved node list found!
673 self::createDebugInstance(__CLASS__)->debugOutput('HUB: No previously saved node list found. This is fine.');
677 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: FINISHED.');
681 * Getter for isActive attribute
683 * @return $isActive Whether the hub is active
685 public final function isNodeActive () {
686 return $this->isActive;
690 * Enables (default) or disables isActive flag
692 * @param $isActive Whether the hub is active
695 public final function enableIsActive ($isActive = true) {
696 $this->isActive = (bool) $isActive;
700 * Checks whether this node accepts announcements
702 * @return $acceptAnnouncements Whether this node accepts announcements
704 public final function isAcceptingAnnouncements () {
705 // Check it (this node must be active and not shutdown!)
706 $acceptAnnouncements = (($this->acceptAnnouncements === true) && ($this->isNodeActive()));
709 return $acceptAnnouncements;
713 * Checks whether this node has attempted to announce itself
715 * @return $hasAnnounced Whether this node has attempted to announce itself
716 * @todo Add checking if this node has been announced to the sender node
718 public function ifNodeHasAnnounced () {
719 // Simply check the state of this node
720 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncedState);
723 return $hasAnnounced;
727 * Enables whether this node accepts announcements
729 * @param $acceptAnnouncements Whether this node accepts announcements (default: true)
732 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = true) {
733 $this->acceptAnnouncements = $acceptAnnouncements;
738 * "Getter" for address:port combination
740 * @param $handlerInstance An instance of a Networkable class
741 * @return $addressPort A address:port combination for this node
743 public final function getAddressPort (Networkable $handlerInstance) {
744 // Construct config entry
745 $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port';
748 $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry);
755 * Updates/refreshes node data (e.g. status).
758 * @todo Find more to do here
760 public function updateNodeData () {
761 // Set some dummy configuration entries, e.g. node_status
762 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
766 * Handles message answer by given data array
768 * @param $messageData A valid answer message data array
770 * @todo Handle thrown exception
772 public function handleAnswerStatusByMessageData (array $messageData) {
773 // Construct configuration entry for handling class' name
774 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]) . '_handler_class';
776 // Try to get a class
777 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
780 $handlerInstance->handleAnswerMessageData($messageData);