3 * A general hub node class
5 * @author Roland Haeder <webmaster@shipsimu.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.shipsimu.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, AddableCriteria {
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 bootstrap 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 * Whether this node accepts DHT bootstrap requests (default: FALSE)
73 private $acceptDhtBootstrap = FALSE;
76 * Protected constructor
78 * @param $className Name of the class
81 protected function __construct ($className) {
82 // Call parent constructor
83 parent::__construct($className);
85 // Get a wrapper instance
86 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_info_db_wrapper_class');
89 $this->setWrapperInstance($wrapperInstance);
91 // Get a crypto instance
92 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
95 $this->setCryptoInstance($cryptoInstance);
97 // Init state which sets the state to 'init'
102 * Initializes the node's state which sets it to 'init'
106 private function initState() {
108 * Get the state factory and create the initial state, we don't need
109 * the state instance here
111 NodeStateFactory::createNodeStateInstanceByName('init', $this);
115 * Generates a random string from various data inluding UUID if PECL
116 * extension uuid is installed.
118 * @param $length Length of the random part
119 * @return $randomString Random string
120 * @todo Make this code more generic and move it to CryptoHelper or
122 protected function generateRamdomString ($length) {
123 // Get an RNG instance
124 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
126 // Generate a pseudo-random string
127 $randomString = $rngInstance->randomString($length) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
129 // Add UUID for even more entropy for the hasher
130 $randomString .= $this->getCryptoInstance()->createUuid();
133 return $randomString;
137 * Generates a private key and hashes it (for speeding up things)
139 * @param $searchInstance An instance of a LocalSearchCriteria class
142 private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
143 // Get an RNG instance
144 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
146 // Generate a pseudo-random string
147 $randomString = $rngInstance->randomString(255);
149 // Hash and encrypt the string so we become a node id (also documented as "hub id")
150 $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString));
151 $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey()));
153 // Register the node id with our wrapper
154 $this->getWrapperInstance()->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
157 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
161 * Setter for query instance
163 * @param $connectorInstance Our new query instance
166 private final function setQueryConnectorInstance (Connectable $connectorInstance) {
167 $this->queryConnectorInstance = $connectorInstance;
171 * Getter for query instance
173 * @return $connectorInstance Our new query instance
175 public final function getQueryConnectorInstance () {
176 return $this->queryConnectorInstance;
180 * Setter for queue instance
182 * @param $connectorInstance Our new queue instance
185 private final function setQueueConnectorInstance (Connectable $connectorInstance) {
186 $this->queueConnectorInstance = $connectorInstance;
190 * Getter for queue instance
192 * @return $connectorInstance Our new queue instance
194 public final function getQueueConnectorInstance () {
195 return $this->queueConnectorInstance;
199 * Getter for boot IP/port combination
201 * @return $bootIpPort The IP/port combination of the boot node
203 protected final function getBootIpPort () {
204 return $this->bootIpPort;
208 * Checks whether the given IP address matches one of the bootstrap nodes
210 * @param $remoteAddr IP address to checkout against our bootstrapping list
211 * @return $isFound Whether the IP is found
213 protected function ifAddressMatchesBootstrapNodes ($remoteAddr) {
214 // By default nothing is found
217 // Run through all configured IPs
218 foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
219 // Split it up in IP/port
220 $ipPortArray = explode(':', $ipPort);
223 if ($ipPortArray[0] == $remoteAddr) {
227 // Remember the port number
228 $this->bootIpPort = $ipPort;
231 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
233 // Stop further searching
235 } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
237 * IP matches listen address. At this point we really don't care
238 * if we can really listen on that address
242 // Remember the port number
243 $this->bootIpPort = $ipPort;
246 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
248 // Stop further searching
258 * Outputs the console teaser. This should only be executed on startup or
259 * full restarts. This method generates some space around the teaser.
263 public function outputConsoleTeaser () {
264 // Get the app instance (for shortening our code)
265 $app = $this->getApplicationInstance();
268 self::createDebugInstance(__CLASS__)->debugOutput(' ');
269 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
270 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team');
271 self::createDebugInstance(__CLASS__)->debugOutput(' ');
272 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
273 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
274 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
275 self::createDebugInstance(__CLASS__)->debugOutput(' ');
279 * Generic method to acquire a hub-id. On first run this generates a new one
280 * based on many pseudo-random data. On any later run, unless the id
281 * got not removed from database, it will be restored from the database.
283 * @param $requestInstance A Requestable class
284 * @param $responseInstance A Responseable class
287 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
288 // Is there a node id?
289 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
290 // Get the node id from result and set it
291 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
294 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
296 // Get an RNG instance
297 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
299 // Generate a pseudo-random string
300 $randomString = $rngInstance->randomString(255);
302 // Hash and encrypt the string so we become a node id (also documented as "hub id")
303 $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
305 // Register the node id with our wrapper
306 $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance());
309 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
314 * Generates a session id which will be sent to the other hubs and peers
318 public function bootstrapGenerateSessionId () {
319 // Now get a search criteria instance
320 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
322 // Search for the node number one which is hard-coded the default
323 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
324 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $this->getRequestInstance()->getRequestElement('mode'));
325 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID , $this->getNodeId());
326 $searchInstance->setLimit(1);
328 // Remember it for later usage
329 $this->setSearchInstance($searchInstance);
331 // Get a random string
332 $randomString = $this->generateRamdomString(255);
334 // Hash and encrypt the string so we become a "node id" aka Hub-Id
335 $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
337 // Register the node id with our wrapper
338 $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
341 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
343 // Change the state because the node has auired a hub id
344 $this->getStateInstance()->nodeGeneratedSessionId();
348 * Generate a private key for en-/decryption
352 public function bootstrapGeneratePrivateKey () {
354 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
355 // Is the element set?
356 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
358 * Auto-generate the private key for e.g. out-dated database
359 * "tables". This allows a smooth update for the underlaying
362 $this->generatePrivateKeyAndHash($this->getSearchInstance());
364 // Get the node id from result and set it
365 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
366 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
369 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
373 * Generate it in a private method (no confusion with 'private
374 * method access' and 'private key' here! ;-)).
376 $this->generatePrivateKeyAndHash($this->getSearchInstance());
381 * Adds hub data elements to a given dataset instance
383 * @param $criteriaInstance An instance of a storeable criteria
384 * @param $requestInstance An instance of a Requestable class
387 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
388 // Make sure request instance is set as it is not optional
389 assert($requestInstance instanceof Requestable);
391 // Add node number and type
392 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
393 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $requestInstance->getRequestElement('mode'));
396 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
398 // Add the session id if acquired
399 if ($this->getSessionId() != '') {
400 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
403 // Add the private key if acquired
404 if ($this->getPrivateKey() != '') {
405 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
406 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
411 * Updates a given field with new value
413 * @param $fieldName Field to update
414 * @param $fieldValue New value to store
416 * @throws DatabaseUpdateSupportException If this class does not support database updates
417 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
419 public function updateDatabaseField ($fieldName, $fieldValue) {
421 $this->partialStub('Unfinished!');
424 // Get a critieria instance
425 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
427 // Add search criteria
428 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
429 $searchInstance->setLimit(1);
431 // Now get another criteria
432 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
434 // Add criteria entry which we shall update
435 $updateInstance->addCriteria($fieldName, $fieldValue);
437 // Add the search criteria for searching for the right entry
438 $updateInstance->setSearchInstance($searchInstance);
440 // Set wrapper class name
441 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
443 // Remember the update in database result
444 $this->getResultInstance()->add2UpdateQueue($updateInstance);
448 * Announces this hub to the upper (bootstrap or list) hubs. After this is
449 * successfully done the given task is unregistered from the handler. This
450 * might look a bit overloaded here but the announcement phase isn't a
451 * simple "Hello there" message, it may later on also contain more
452 * informations like the object list.
454 * @param $taskInstance The task instance running this announcement
456 * @throws NodeAlreadyAnnouncedException If this hub is already announced
457 * @todo Change the first if() block to check for a specific state
459 public function announceToUpperNodes (Taskable $taskInstance) {
460 // Is this hub node announced?
461 if ($this->hubIsAnnounced === TRUE) {
462 // Already announced!
463 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
467 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
469 // Get a helper instance
470 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_helper_class');
472 // Load the announcement descriptor
473 $helperInstance->loadDescriptorXml($this);
475 // Compile all variables
476 $helperInstance->getTemplateInstance()->compileConfigInVariables();
478 // "Publish" the descriptor by sending it to the bootstrap/list nodes
479 $helperInstance->sendPackage($this);
481 // Change the state, this should be the last line except debug output
482 $this->getStateInstance()->nodeAnnouncingToUpperHubs();
485 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
489 * Does a self-connect attempt on the public IP address. This should make
490 * it sure, we are reachable from outside world. For this kind of package we
491 * don't need that overload we have in the announcement phase.
493 * @param $taskInstance The task instance running this announcement
496 public function doSelfConnection (Taskable $taskInstance) {
498 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
500 // Get a helper instance
501 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_self_connect_helper_class', array($this));
503 // Load the descriptor (XML) file
504 $helperInstance->loadDescriptorXml($this);
506 // Compile all variables
507 $helperInstance->getTemplateInstance()->compileConfigInVariables();
509 // And send the package away
510 $helperInstance->sendPackage($this);
513 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: FINISHED');
517 * Activates the hub by doing some final preparation and setting
518 * $hubIsActive to TRUE.
520 * @param $requestInstance A Requestable class
521 * @param $responseInstance A Responseable class
524 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
525 // Checks whether a listener is still active and shuts it down if one
526 // is still listening.
527 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
528 // Shutdown them down before they can hurt anything
529 $this->shutdownListenerPool();
532 // Get the controller here
533 $controllerInstance = Registry::getRegistry()->getInstance('controller');
535 // Run all filters for the hub activation
536 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
538 // ----------------------- Last step from here ------------------------
539 // Activate the hub. This is ALWAYS the last step in this method
540 $this->getStateInstance()->nodeIsActivated();
541 // ---------------------- Last step until here ------------------------
545 * Initializes the listener pool (class)
549 public function initializeListenerPool () {
551 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: START');
553 // Get a new pool instance
554 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
556 // Get an instance of the low-level listener
557 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
559 // Setup address and port
560 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
563 * All nodes can now use the same configuration entry because it can be
564 * customized in config-local.php.
566 $listenerInstance->setListenPortByConfiguration('node_listen_port');
568 // Initialize the listener
569 $listenerInstance->initListener();
571 // Get a decorator class
572 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_tcp_listener_class', array($listenerInstance));
574 // Add this listener to the pool
575 $this->getListenerPoolInstance()->addListener($decoratorInstance);
577 // Get a decorator class
578 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
580 // Add this listener to the pool
581 $this->getListenerPoolInstance()->addListener($decoratorInstance);
583 // Get an instance of the low-level listener
584 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
586 // Setup address and port
587 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
590 * All nodes can now use the same configuration entry because it can be
591 * customized in config-local.php.
593 $listenerInstance->setListenPortByConfiguration('node_listen_port');
595 // Initialize the listener
596 $listenerInstance->initListener();
598 // Get a decorator class
599 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_udp_listener_class', array($listenerInstance));
601 // Add this listener to the pool
602 $this->getListenerPoolInstance()->addListener($decoratorInstance);
604 // Get a decorator class
605 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
607 // Add this listener to the pool
608 $this->getListenerPoolInstance()->addListener($decoratorInstance);
611 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: FINISHED.');
615 * Getter for isActive attribute
617 * @return $isActive Whether the hub is active
619 public final function isNodeActive () {
620 return $this->isActive;
624 * Enables (default) or disables isActive flag
626 * @param $isActive Whether the hub is active
629 public final function enableIsActive ($isActive = TRUE) {
630 $this->isActive = (bool) $isActive;
634 * Checks whether this node accepts announcements
636 * @return $acceptAnnouncements Whether this node accepts announcements
638 public final function isAcceptingAnnouncements () {
639 // Check it (this node must be active and not shutdown!)
640 $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive()));
643 return $acceptAnnouncements;
647 * Checks whether this node accepts DHT bootstrap requests
649 * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests
651 public final function isAcceptingDhtBootstrap () {
652 // Check it (this node must be active and not shutdown!)
653 $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive()));
656 return $acceptDhtBootstrap;
660 * Checks whether this node has attempted to announce itself
662 * @return $hasAnnounced Whether this node has attempted to announce itself
663 * @todo Add checking if this node has been announced to the sender node
665 public function ifNodeHasAnnounced () {
667 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnounced(): state=' . $this->getStateInstance()->getStateName());
669 // Simply check the state of this node
670 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncedState);
673 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnounced(): hasAnnounced=' . intval($hasAnnounced));
676 return $hasAnnounced;
680 * Checks whether this node has attempted to announce itself and completed it
682 * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it
683 * @todo Add checking if this node has been announced to the sender node
685 public function ifNodeHasAnnouncementCompleted () {
687 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): state=' . $this->getStateInstance()->getStateName());
689 // Simply check the state of this node
690 $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState);
693 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted));
696 return $hasAnnouncementCompleted;
700 * Enables whether this node accepts announcements
702 * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE)
705 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = TRUE) {
706 $this->acceptAnnouncements = $acceptAnnouncements;
710 * Enables whether this node accepts DHT bootstrap requests
712 * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE)
715 public final function enableAcceptDhtBootstrap ($acceptDhtBootstrap = TRUE) {
716 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
717 $this->acceptDhtBootstrap = $acceptDhtBootstrap;
721 * Checks wether this node is accepting node-list requests
723 * @return $acceptsRequest Wether this node accepts node-list requests
725 public function isAcceptingNodeListRequests () {
727 * Only 'regular' nodes does not accept such requests, checking
728 * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
729 * added then the next check will be TRUE.
731 $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
734 return $acceptsRequest;
738 * "Getter" for address:port combination
740 * @return $addressPort A address:port combination for this node
742 public final function getAddressPort () {
744 $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
751 * "Getter" for address:port array
753 * @return $addressPortArray An array of a address:port combination for this node
755 public final function getAddressPortArray () {
757 $addressPortArray = explode(':', $this->getAddressPort());
760 return $addressPortArray;
764 * Updates/refreshes node data (e.g. status).
767 * @todo Find more to do here
769 public function updateNodeData () {
770 // Set some dummy configuration entries, e.g. node_status
771 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
775 * Handles message answer by given data array
777 * @param $messageData A valid answer message data array
778 * @param $packageInstance An instance of a Receivable class
780 * @todo Handle thrown exception
782 public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
784 assert(!empty($messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]));
786 // Construct configuration entry for handling class' name
787 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class';
789 // Try to get a class
790 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
793 $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
797 * "Getter" for an array of all accepted object types
799 * @return $objectList Array of all accepted object types
801 public function getListFromAcceptedObjectTypes () {
802 // Get registry instance
803 $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
806 $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
813 * Adds all required elements from given array into data set instance
815 * @param $dataSetInstance An instance of a StoreableCriteria class
816 * @param $nodeData An array with valid node data
819 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) {
820 // Add all data the array provides
821 foreach (NodeDistributedHashTableDatabaseWrapper::getAllElements() as $element) {
822 // Is the element there?
823 if (isset($nodeData[$element])) {
825 $dataSetInstance->addCriteria($element, $nodeData[$element]);
827 // Output warning message
828 /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in nodeData array.');