3 * A general hub node class
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 * Universal node locator of bootstrap node
42 private $bootUniversalNodeLocator = '';
45 * Whether this node is anncounced (keep on FALSE!)
48 private $hubIsAnnounced = FALSE;
51 * Whether this hub is active (default: FALSE)
53 private $isActive = FALSE;
56 * Whether this node accepts announcements (default: FALSE)
58 private $acceptAnnouncements = FALSE;
61 * Whether this node accepts DHT bootstrap requests (default: FALSE)
63 private $acceptDhtBootstrap = FALSE;
66 * Protected constructor
68 * @param $className Name of the class
71 protected function __construct ($className) {
72 // Call parent constructor
73 parent::__construct($className);
75 // Get a wrapper instance
76 $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_info_db_wrapper_class');
79 $this->setWrapperInstance($wrapperInstance);
81 // Get a crypto instance
82 $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
85 $this->setCryptoInstance($cryptoInstance);
87 // Init state which sets the state to 'init'
92 * Initializes the node's state which sets it to 'init'
96 private function initState() {
97 // Get the state factory and create the initial state.
98 NodeStateFactory::createNodeStateInstanceByName('init', $this);
102 * Generates a random string from various data inluding UUID if PECL
103 * extension uuid is installed.
105 * @param $length Length of the random part
106 * @return $randomString Random string
107 * @todo Make this code more generic and move it to CryptoHelper or
109 protected function generateRamdomString ($length) {
110 // Get an RNG instance
111 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
113 // Generate a pseudo-random string
114 $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode');
116 // Add UUID for even more entropy for the hasher
117 $randomString .= $this->getCryptoInstance()->createUuid();
120 return $randomString;
124 * Generates a private key and hashes it (for speeding up things)
126 * @param $searchInstance An instance of a LocalSearchCriteria class
129 private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) {
130 // Get an RNG instance
131 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
133 // Generate a pseudo-random string
134 $randomString = $rngInstance->randomString(255);
136 // Hash and encrypt the string so we become a node id (also documented as "hub id")
137 $this->setPrivateKey($this->getCryptoInstance()->encryptString($randomString));
138 $this->setPrivateKeyHash($this->getCryptoInstance()->hashString($this->getPrivateKey()));
140 // Register the node id with our wrapper
141 $this->getWrapperInstance()->registerPrivateKey($this, $this->getRequestInstance(), $searchInstance);
144 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
148 * Getter for boot IP/port combination
150 * @return $bootUniversalNodeLocator The IP/port combination of the boot node
152 protected final function getBootUniversalNodeLocator () {
153 return $this->bootUniversalNodeLocator;
157 * Checks whether the given IP address matches one of the bootstrap nodes
159 * @param $remoteAddr IP address to checkout against our bootstrapping list
160 * @return $isFound Whether the IP is found
162 protected function ifAddressMatchesBootstrapNodes ($remoteAddr) {
163 // By default nothing is found
166 // Run through all configured IPs
167 foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
168 // Get back an array from the UNL
169 $unlArray = HubTools::getArrayFromUniversalNodeLocator($unl);
171 die(__METHOD__ . ':' . print_r($unlArray, TRUE));
174 if ($unlArray[0] == $remoteAddr) {
178 // Remember the port number
179 $this->bootUniversalNodeLocator = $unl;
182 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
184 // Stop further searching
186 } elseif ($unlArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
188 * IP matches listen address. At this point we really don't care
189 * if we can really listen on that address
193 // Remember the port number
194 $this->bootUniversalNodeLocator = $unl;
197 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.');
199 // Stop further searching
209 * Outputs the console teaser. This should only be executed on startup or
210 * full restarts. This method generates some space around the teaser.
214 public function outputConsoleTeaser () {
215 // Get the app instance (for shortening our code)
216 $app = $this->getApplicationInstance();
219 self::createDebugInstance(__CLASS__)->debugOutput(' ');
220 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
221 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2014 Hub Developer Team');
222 self::createDebugInstance(__CLASS__)->debugOutput(' ');
223 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
224 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
225 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
226 self::createDebugInstance(__CLASS__)->debugOutput(' ');
230 * Generic method to acquire a hub-id. On first run this generates a new one
231 * based on many pseudo-random data. On any later run, unless the id
232 * got not removed from database, it will be restored from the database.
234 * @param $requestInstance A Requestable class
235 * @param $responseInstance A Responseable class
238 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
239 // Is there a node id?
240 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
241 // Get the node id from result and set it
242 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
245 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
247 // Get an RNG instance
248 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
250 // Generate a pseudo-random string
251 $randomString = $rngInstance->randomString(255);
253 // Hash and encrypt the string so we become a node id (also documented as "hub id")
254 $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
256 // Register the node id with our wrapper
257 $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance());
260 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
265 * Generates a session id which will be sent to the other hubs and peers
269 public function bootstrapGenerateSessionId () {
270 // Now get a search criteria instance
271 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
273 // Search for the node number one which is hard-coded the default
274 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
275 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $this->getRequestInstance()->getRequestElement('mode'));
276 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID , $this->getNodeId());
277 $searchInstance->setLimit(1);
279 // Remember it for later usage
280 $this->setSearchInstance($searchInstance);
282 // Get a random string
283 $randomString = $this->generateRamdomString(255);
285 // Hash and encrypt the string so we become a "node id" aka Hub-Id
286 $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
288 // Register the node id with our wrapper
289 $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
292 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
294 // Change the state because the node has auired a hub id
295 $this->getStateInstance()->nodeGeneratedSessionId();
299 * Generate a private key for en-/decryption
303 public function bootstrapGeneratePrivateKey () {
305 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
306 // Is the element set?
307 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
309 * Auto-generate the private key for e.g. out-dated database
310 * "tables". This allows a smooth update for the underlaying
313 $this->generatePrivateKeyAndHash($this->getSearchInstance());
315 // Get the node id from result and set it
316 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
317 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
320 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
324 * Generate it in a private method (no confusion with 'private
325 * method access' and 'private key' here! ;-)).
327 $this->generatePrivateKeyAndHash($this->getSearchInstance());
332 * Adds hub data elements to a given dataset instance
334 * @param $criteriaInstance An instance of a storeable criteria
335 * @param $requestInstance An instance of a Requestable class
338 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
339 // Make sure request instance is set as it is not optional
340 assert($requestInstance instanceof Requestable);
342 // Add node number and type
343 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
344 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $requestInstance->getRequestElement('mode'));
347 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
349 // Add the session id if acquired
350 if ($this->getSessionId() != '') {
351 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
354 // Add the private key if acquired
355 if ($this->getPrivateKey() != '') {
356 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
357 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
362 * Updates a given field with new value
364 * @param $fieldName Field to update
365 * @param $fieldValue New value to store
367 * @throws DatabaseUpdateSupportException If this class does not support database updates
368 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
370 public function updateDatabaseField ($fieldName, $fieldValue) {
372 $this->partialStub('Unfinished!');
375 // Get a critieria instance
376 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
378 // Add search criteria
379 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
380 $searchInstance->setLimit(1);
382 // Now get another criteria
383 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
385 // Add criteria entry which we shall update
386 $updateInstance->addCriteria($fieldName, $fieldValue);
388 // Add the search criteria for searching for the right entry
389 $updateInstance->setSearchInstance($searchInstance);
391 // Set wrapper class name
392 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
394 // Remember the update in database result
395 $this->getResultInstance()->add2UpdateQueue($updateInstance);
399 * Announces this hub to the upper (bootstrap or list) hubs. After this is
400 * successfully done the given task is unregistered from the handler. This
401 * might look a bit overloaded here but the announcement phase isn't a
402 * simple "Hello there" message, it may later on also contain more
403 * informations like the object list.
405 * @param $taskInstance The task instance running this announcement
407 * @throws NodeAlreadyAnnouncedException If this hub is already announced
408 * @todo Change the first if() block to check for a specific state
410 public function announceToUpperNodes (Taskable $taskInstance) {
411 // Is this hub node announced?
412 if ($this->hubIsAnnounced === TRUE) {
413 // Already announced!
414 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
418 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
420 // Get a helper instance
421 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_helper_class');
423 // Load the announcement descriptor
424 $helperInstance->loadDescriptorXml($this);
426 // Compile all variables
427 $helperInstance->getTemplateInstance()->compileConfigInVariables();
429 // "Publish" the descriptor by sending it to the bootstrap/list nodes
430 $helperInstance->sendPackage($this);
432 // Change the state, this should be the last line except debug output
433 $this->getStateInstance()->nodeAnnouncingToUpperHubs();
436 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
440 * Does a self-connect attempt on the public IP address. This should make
441 * it sure, we are reachable from outside world. For this kind of package we
442 * don't need that overload we have in the announcement phase.
444 * @param $taskInstance The task instance running this announcement
447 public function doSelfConnection (Taskable $taskInstance) {
449 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
451 // Get a helper instance
452 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_self_connect_helper_class', array($this));
454 // Load the descriptor (XML) file
455 $helperInstance->loadDescriptorXml($this);
457 // Compile all variables
458 $helperInstance->getTemplateInstance()->compileConfigInVariables();
460 // And send the package away
461 $helperInstance->sendPackage($this);
464 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: FINISHED');
468 * Activates the hub by doing some final preparation and setting
469 * $hubIsActive to TRUE.
471 * @param $requestInstance A Requestable class
472 * @param $responseInstance A Responseable class
475 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
476 // Checks whether a listener is still active and shuts it down if one
477 // is still listening.
478 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
479 // Shutdown them down before they can hurt anything
480 $this->shutdownListenerPool();
483 // Get the controller here
484 $controllerInstance = Registry::getRegistry()->getInstance('controller');
486 // Run all filters for the hub activation
487 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
489 // ----------------------- Last step from here ------------------------
490 // Activate the hub. This is ALWAYS the last step in this method
491 $this->getStateInstance()->nodeIsActivated();
492 // ---------------------- Last step until here ------------------------
496 * Initializes the listener pool (class)
500 public function initializeListenerPool () {
502 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: START');
504 // Get a new pool instance
505 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
507 // Get an instance of the low-level listener
508 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
510 // Setup address and port
511 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
514 * All nodes can now use the same configuration entry because it can be
515 * customized in config-local.php.
517 $listenerInstance->setListenPortByConfiguration('node_listen_port');
519 // Initialize the listener
520 $listenerInstance->initListener();
522 // Get a decorator class
523 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_tcp_listener_class', array($listenerInstance));
525 // Add this listener to the pool
526 $this->getListenerPoolInstance()->addListener($decoratorInstance);
528 // Get a decorator class
529 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
531 // Add this listener to the pool
532 $this->getListenerPoolInstance()->addListener($decoratorInstance);
534 // Get an instance of the low-level listener
535 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
537 // Setup address and port
538 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
541 * All nodes can now use the same configuration entry because it can be
542 * customized in config-local.php.
544 $listenerInstance->setListenPortByConfiguration('node_listen_port');
546 // Initialize the listener
547 $listenerInstance->initListener();
549 // Get a decorator class
550 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_udp_listener_class', array($listenerInstance));
552 // Add this listener to the pool
553 $this->getListenerPoolInstance()->addListener($decoratorInstance);
555 // Get a decorator class
556 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
558 // Add this listener to the pool
559 $this->getListenerPoolInstance()->addListener($decoratorInstance);
562 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: FINISHED.');
566 * Getter for isActive attribute
568 * @return $isActive Whether the hub is active
570 public final function isNodeActive () {
571 return $this->isActive;
575 * Enables (default) or disables isActive flag
577 * @param $isActive Whether the hub is active
580 public final function enableIsActive ($isActive = TRUE) {
581 $this->isActive = (bool) $isActive;
585 * Checks whether this node accepts announcements
587 * @return $acceptAnnouncements Whether this node accepts announcements
589 public final function isAcceptingAnnouncements () {
590 // Check it (this node must be active and not shutdown!)
591 $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive()));
594 return $acceptAnnouncements;
598 * Checks whether this node accepts DHT bootstrap requests
600 * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests
602 public final function isAcceptingDhtBootstrap () {
603 // Check it (this node must be active and not shutdown!)
604 $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive()));
607 return $acceptDhtBootstrap;
611 * Checks whether this node has attempted to announce itself
613 * @return $hasAnnounced Whether this node has attempted to announce itself
614 * @todo Add checking if this node has been announced to the sender node
616 public function ifNodeIsAnnouncing () {
618 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): state=' . $this->getStateInstance()->getStateName());
620 // Simply check the state of this node
621 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncingState);
624 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): hasAnnounced=' . intval($hasAnnounced));
627 return $hasAnnounced;
631 * Checks whether this node has attempted to announce itself and completed it
633 * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it
634 * @todo Add checking if this node has been announced to the sender node
636 public function ifNodeHasAnnouncementCompleted () {
638 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): state=' . $this->getStateInstance()->getStateName());
640 // Simply check the state of this node
641 $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState);
644 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted));
647 return $hasAnnouncementCompleted;
651 * Enables whether this node accepts announcements
653 * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE)
656 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = TRUE) {
657 $this->acceptAnnouncements = $acceptAnnouncements;
661 * Enables whether this node accepts DHT bootstrap requests
663 * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE)
666 public final function enableAcceptDhtBootstrap ($acceptDhtBootstrap = TRUE) {
667 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
668 $this->acceptDhtBootstrap = $acceptDhtBootstrap;
672 * Checks wether this node is accepting node-list requests
674 * @return $acceptsRequest Wether this node accepts node-list requests
676 public function isAcceptingNodeListRequests () {
678 * Only 'regular' nodes does not accept such requests, checking
679 * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
680 * added then the next check will be TRUE.
682 $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
685 return $acceptsRequest;
689 * Determines the Universal Node Locator
691 * @return $unl A an Universal Node Locator for this node
693 public function determineUniversalNodeLocator () {
694 // Determine UNL based on this node:
695 // 1) Get discovery class
696 $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
699 $unl = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
706 * "Getter" for Universal Node Locator array
708 * @return $unlArray An array of the Universal Node Locator for this node
710 public final function getUniversalNodeLocatorArray () {
711 // Get Universal Node Locator (UNL)
712 $unl = $this->determineUniversalNodeLocator();
715 die(__METHOD__ . ':' . print_r($unl, TRUE));
722 * Updates/refreshes node data (e.g. status).
725 * @todo Find more to do here
727 public function updateNodeData () {
728 // Set some dummy configuration entries, e.g. node_status
729 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
733 * Handles message answer by given data array
735 * @param $messageData A valid answer message data array
736 * @param $packageInstance An instance of a Receivable class
738 * @todo Handle thrown exception
740 public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
742 assert(!empty($messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]));
744 // Construct configuration entry for handling class' name
745 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class';
747 // Try to get a class
748 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
751 $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
755 * "Getter" for an array of all accepted object types
757 * @return $objectList Array of all accepted object types
759 public function getListFromAcceptedObjectTypes () {
760 // Get registry instance
761 $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
764 $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
771 * Adds all required elements from given array into data set instance
773 * @param $dataSetInstance An instance of a StoreableCriteria class
774 * @param $nodeData An array with valid node data
777 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) {
778 // Add all data the array provides
779 foreach (NodeDistributedHashTableDatabaseWrapper::getAllElements() as $element) {
780 // Is the element there?
781 if (isset($nodeData[$element])) {
783 $dataSetInstance->addCriteria($element, $nodeData[$element]);
785 // Output warning message
786 /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in nodeData array.');