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 // Get a crypto instance
81 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
84 $this->setCryptoInstance($cryptoInstance);
86 // Init state which sets the state to 'init'
91 * Initializes the node's state which sets it to 'init'
95 private function initState() {
97 * Get the state factory and create the initial state, we don't need
98 * the state instance here
100 NodeStateFactory::createNodeStateInstanceByName('init', $this);
104 * Generates a random string from various data inluding UUID if PECL
105 * extension uuid is installed.
107 * @param $length Length of the random part
108 * @return $randomString Random string
109 * @todo Make this code more generic and move it to CryptoHelper or
111 protected function generateRamdomString ($length) {
112 // Get an RNG instance
113 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
115 // Generate a pseudo-random string
116 $randomString = $rngInstance->randomString($length) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
118 // Add UUID for even more entropy for the hasher
119 $randomString .= $this->getCryptoInstance()->createUuid();
122 return $randomString;
126 * Generates a private key and hashes it (for speeding up things)
128 * @param $searchInstance An instance of a LocalSearchCriteria class
131 private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
132 // Generate a pseudo-random string
133 $randomString = $this->generateRandomString(255);
135 // Hash and encrypt the string so we become a node id (also documented as "hub id")
136 $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString));
137 $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey()));
139 // Get a wrapper instance
140 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
142 // Register the node id with our wrapper
143 $wrapperInstance->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
146 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
150 * Setter for query instance
152 * @param $connectorInstance Our new query instance
155 private final function setQueryConnectorInstance (Connectable $connectorInstance) {
156 $this->queryConnectorInstance = $connectorInstance;
160 * Getter for query instance
162 * @return $connectorInstance Our new query instance
164 public final function getQueryConnectorInstance () {
165 return $this->queryConnectorInstance;
169 * Setter for queue instance
171 * @param $connectorInstance Our new queue instance
174 private final function setQueueConnectorInstance (Connectable $connectorInstance) {
175 $this->queueConnectorInstance = $connectorInstance;
179 * Getter for queue instance
181 * @return $connectorInstance Our new queue instance
183 public final function getQueueConnectorInstance () {
184 return $this->queueConnectorInstance;
188 * Getter for boot IP/port combination
190 * @return $bootIpPort The IP/port combination of the boot node
192 protected final function getBootIpPort () {
193 return $this->bootIpPort;
197 * Checks whether the given IP address matches one of the bootstrapping nodes
199 * @param $remoteAddr IP address to checkout against our bootstrapping list
200 * @return $isFound Whether the IP is found
202 protected function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
203 // By default nothing is found
206 // Run through all configured IPs
207 foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
208 // Split it up in IP/port
209 $ipPortArray = explode(':', $ipPort);
212 if ($ipPortArray[0] == $remoteAddr) {
216 // Remember the port number
217 $this->bootIpPort = $ipPort;
220 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
222 // Stop further searching
224 } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
226 * IP matches listen address. At this point we really don't care
227 * if we can really listen on that address
231 // Remember the port number
232 $this->bootIpPort = $ipPort;
235 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
237 // Stop further searching
247 * Outputs the console teaser. This should only be executed on startup or
248 * full restarts. This method generates some space around the teaser.
252 public function outputConsoleTeaser () {
253 // Get the app instance (for shortening our code)
254 $app = $this->getApplicationInstance();
257 self::createDebugInstance(__CLASS__)->debugOutput(' ');
258 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
259 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team');
260 self::createDebugInstance(__CLASS__)->debugOutput(' ');
261 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
262 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
263 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
264 self::createDebugInstance(__CLASS__)->debugOutput(' ');
268 * Generic method to acquire a hub-id. On first run this generates a new one
269 * based on many pseudo-random data. On any later run, unless the id
270 * got not removed from database, it will be restored from the database.
272 * @param $requestInstance A Requestable class
273 * @param $responseInstance A Responseable class
276 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
277 // Get a wrapper instance
278 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
280 // Now get a search criteria instance
281 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
283 // Search for the node number one which is hard-coded the default
284 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
285 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
286 $searchInstance->setLimit(1);
289 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
292 if ($resultInstance->next()) {
293 // Save the result instance in this class
294 $this->setResultInstance($resultInstance);
296 // Get the node id from result and set it
297 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
300 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
302 // Generate a pseudo-random string
303 $randomString = $this->generateRandomString(255);
305 // Hash and encrypt the string so we become a node id (also documented as "hub id")
306 $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
308 // Register the node id with our wrapper
309 $wrapperInstance->registerNodeId($this, $this->getRequestInstance());
312 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
317 * Generates a session id which will be sent to the other hubs and peers
321 public function bootstrapGenerateSessionId () {
322 // Now get a search criteria instance
323 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
325 // Search for the node number one which is hard-coded the default
326 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
327 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
328 $searchInstance->setLimit(1);
330 // Get a random string
331 $randomString = $this->generateRamdomString(255);
333 // Hash and encrypt the string so we become a "node id" aka Hub-Id
334 $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
336 // Get a wrapper instance
337 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
339 // Register the node id with our wrapper
340 $wrapperInstance->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
343 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
345 // Change the state because the node has auired a hub id
346 $this->getStateInstance()->nodeGeneratedSessionId();
350 * Generate a private key for en-/decryption
354 public function bootstrapGeneratePrivateKey () {
355 // Get a wrapper instance
356 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
358 // Now get a search criteria instance
359 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
361 // Search for the node number one which is hard-coded the default
362 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
363 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
364 $searchInstance->setLimit(1);
367 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
370 if ($resultInstance->next()) {
371 // Save the result instance in this class
372 $this->setResultInstance($resultInstance);
374 // Is the element set?
375 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
377 * Auto-generate the private key for e.g. out-dated database
378 * "tables". This allows a smooth update for the underlaying
381 $this->generatePrivateKeyAndHash($searchInstance);
383 // Get the node id from result and set it
384 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
385 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
388 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
392 * Generate it in a private method (no confusion with 'private
393 * method access' and 'private key' here! ;-)).
395 $this->generatePrivateKeyAndHash($searchInstance);
400 * Initializes queues which every node needs
404 protected function initGenericQueues () {
406 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: START');
408 // Set the query connector instance
409 $this->setQueryConnectorInstance(ObjectFactory::createObjectByConfiguredName('query_connector_class', array($this)));
412 $this->getQueryConnectorInstance()->doTestQuery();
414 // Set the queue connector instance
415 $this->setQueueConnectorInstance(ObjectFactory::createObjectByConfiguredName('queue_connector_class', array($this)));
418 $this->getQueueConnectorInstance()->doTestQueue();
421 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Initialize queues: FINISHED');
425 * Adds hub data elements to a given dataset instance
427 * @param $criteriaInstance An instance of a storeable criteria
428 * @param $requestInstance An instance of a Requestable class
431 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance) {
432 // Add node number and type
433 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
434 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_TYPE, $requestInstance->getRequestElement('mode'));
437 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
439 // Add the session id if acquired
440 if ($this->getSessionId() != '') {
441 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
444 // Add the private key if acquired
445 if ($this->getPrivateKey() != '') {
446 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
447 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
452 * Updates a given field with new value
454 * @param $fieldName Field to update
455 * @param $fieldValue New value to store
457 * @throws DatabaseUpdateSupportException If this class does not support database updates
458 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
460 public function updateDatabaseField ($fieldName, $fieldValue) {
462 $this->partialStub('Unfinished!');
465 // Get a critieria instance
466 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
468 // Add search criteria
469 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
470 $searchInstance->setLimit(1);
472 // Now get another criteria
473 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
475 // Add criteria entry which we shall update
476 $updateInstance->addCriteria($fieldName, $fieldValue);
478 // Add the search criteria for searching for the right entry
479 $updateInstance->setSearchInstance($searchInstance);
481 // Set wrapper class name
482 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
484 // Remember the update in database result
485 $this->getResultInstance()->add2UpdateQueue($updateInstance);
489 * Announces this hub to the upper (bootstrap or list) hubs. After this is
490 * successfully done the given task is unregistered from the handler. This
491 * might look a bit overloaded here but the announcement phase isn't a
492 * simple "Hello there" message, it may later on also contain more
493 * informations like the object list.
495 * @param $taskInstance The task instance running this announcement
497 * @throws NodeAlreadyAnnouncedException If this hub is already announced
498 * @todo Change the first if() block to check for a specific state
500 public function announceSelfToUpperNodes (Taskable $taskInstance) {
501 // Is this hub node announced?
502 if ($this->hubIsAnnounced === true) {
503 // Already announced!
504 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
508 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
510 // Get a helper instance
511 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class');
513 // Load the announcement descriptor
514 $helperInstance->loadDescriptorXml($this);
516 // Compile all variables
517 $helperInstance->getTemplateInstance()->compileConfigInVariables();
519 // "Publish" the descriptor by sending it to the bootstrap/list nodes
520 $helperInstance->sendPackage($this);
522 // Change the state, this should be the last line except debug output
523 $this->getStateInstance()->nodeAnnouncedToUpperHubs();
526 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
530 * Does a self-connect attempt on the public IP address. This should make
531 * it sure, we are reachable from outside world. For this kind of package we
532 * don't need that overload we have in the announcement phase.
534 * @param $taskInstance The task instance running this announcement
537 public function doSelfConnection (Taskable $taskInstance) {
539 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
541 // Get a helper instance
542 $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this));
544 // Load the descriptor (XML) file
545 $helperInstance->loadDescriptorXml($this);
547 // Compile all variables
548 $helperInstance->getTemplateInstance()->compileConfigInVariables();
550 // And send the package away
551 $helperInstance->sendPackage($this);
554 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Self Connection: FINISHED');
558 * Activates the hub by doing some final preparation and setting
559 * $hubIsActive to true
561 * @param $requestInstance A Requestable class
562 * @param $responseInstance A Responseable class
565 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
566 // Checks whether a listener is still active and shuts it down if one
567 // is still listening.
568 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
569 // Shutdown them down before they can hurt anything
570 $this->shutdownListenerPool();
573 // Get the controller here
574 $controllerInstance = Registry::getRegistry()->getInstance('controller');
576 // Run all filters for the hub activation
577 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
579 // ----------------------- Last step from here ------------------------
580 // Activate the hub. This is ALWAYS the last step in this method
581 $this->getStateInstance()->nodeIsActivated();
582 // ---------------------- Last step until here ------------------------
586 * Initializes the listener pool (class)
590 public function initializeListenerPool () {
592 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: START');
594 // Get a new pool instance
595 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
597 // Get an instance of the low-level listener
598 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
600 // Setup address and port
601 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
604 * All nodes can now use the same configuration entry because it can be
605 * customized in config-local.php.
607 $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
609 // Initialize the listener
610 $listenerInstance->initListener();
612 // Get a decorator class
613 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_tcp_listener_class', array($listenerInstance));
615 // Add this listener to the pool
616 $this->getListenerPoolInstance()->addListener($decoratorInstance);
618 // Get a decorator class
619 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
621 // Add this listener to the pool
622 $this->getListenerPoolInstance()->addListener($decoratorInstance);
624 // Get an instance of the low-level listener
625 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
627 // Setup address and port
628 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
631 * All nodes can now use the same configuration entry because it can be
632 * customized in config-local.php.
634 $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
636 // Initialize the listener
637 $listenerInstance->initListener();
639 // Get a decorator class
640 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('hub_udp_listener_class', array($listenerInstance));
642 // Add this listener to the pool
643 $this->getListenerPoolInstance()->addListener($decoratorInstance);
645 // Get a decorator class
646 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
648 // Add this listener to the pool
649 $this->getListenerPoolInstance()->addListener($decoratorInstance);
652 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Initialize listener: FINISHED.');
656 * Restores a previously stored node list from database
660 public function bootstrapRestoreNodeList () {
662 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: START');
664 // Get a wrapper instance
665 $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
667 // Now get a search criteria instance
668 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
670 // Search for the node number zero which is hard-coded the default
671 // @TODO Add some criteria, e.g. if the node is active or so
672 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_NR, 1);
673 //$searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_TYPE, $this->getRequestInstance()->getRequestElement('mode'));
674 //$searchInstance->setLimit(1);
677 $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
680 if ($resultInstance->next()) {
681 $this->partialStub('Do something for restoring the list.');
683 //self::createDebugInstance(__CLASS__)->debugOutput('HUB: ');
685 // No previously saved node list found!
686 self::createDebugInstance(__CLASS__)->debugOutput('HUB: No previously saved node list found. This is fine.');
690 self::createDebugInstance(__CLASS__)->debugOutput('HUB: Restore node list: FINISHED.');
694 * Getter for isActive attribute
696 * @return $isActive Whether the hub is active
698 public final function isNodeActive () {
699 return $this->isActive;
703 * Enables (default) or disables isActive flag
705 * @param $isActive Whether the hub is active
708 public final function enableIsActive ($isActive = true) {
709 $this->isActive = (bool) $isActive;
713 * Checks whether this node accepts announcements
715 * @return $acceptAnnouncements Whether this node accepts announcements
717 public final function isAcceptingAnnouncements () {
718 // Check it (this node must be active and not shutdown!)
719 $acceptAnnouncements = (($this->acceptAnnouncements === true) && ($this->isNodeActive()));
722 return $acceptAnnouncements;
726 * Checks whether this node has attempted to announce itself
728 * @return $hasAnnounced Whether this node has attempted to announce itself
729 * @todo Add checking if this node has been announced to the sender node
731 public function ifNodeHasAnnounced () {
732 // Simply check the state of this node
733 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncedState);
736 return $hasAnnounced;
740 * Enables whether this node accepts announcements
742 * @param $acceptAnnouncements Whether this node accepts announcements (default: true)
745 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = true) {
746 $this->acceptAnnouncements = $acceptAnnouncements;
750 * Checks wether this node is accepting node-list requests
752 * @return $acceptsRequest Wether this node accepts node-list requests
754 public function isAcceptingNodeListRequests () {
756 * Only 'regular' nodes does not accept such requests, checking
757 * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
758 * added then the next check will be true.
760 $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
763 return $acceptsRequest;
767 * "Getter" for address:port combination
769 * @param $handlerInstance An instance of a Networkable class
770 * @return $addressPort A address:port combination for this node
772 public final function getAddressPort (Networkable $handlerInstance) {
773 // Construct config entry
774 $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port';
777 $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry);
784 * Updates/refreshes node data (e.g. status).
787 * @todo Find more to do here
789 public function updateNodeData () {
790 // Set some dummy configuration entries, e.g. node_status
791 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
795 * Handles message answer by given data array
797 * @param $messageData A valid answer message data array
798 * @param $packageInstance An instance of a Receivable class
800 * @todo Handle thrown exception
802 public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
803 // Construct configuration entry for handling class' name
804 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_ANSWER_STATUS]) . '_handler_class';
806 // Try to get a class
807 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
810 $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
814 * "Getter" for an array of all accepted object types
816 * @return $objectList Array of all accepted object types
818 public function getListFromAcceptedObjectTypes () {
819 // Get registry instance
820 $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
823 $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);