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 $bootUnlInstance = '';
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 $bootUnlInstance The IP/port combination of the boot node
152 protected final function getBootUniversalNodeLocator () {
153 return $this->bootUnlInstance;
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 $unlArray) {
169 die(__METHOD__ . ':' . print_r($unlArray, TRUE));
172 if ($unlArray[0] == $remoteAddr) {
176 // Remember the UNL array
177 $this->bootUnlInstance = $unlArray;
180 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unlArray->__toString() . '.');
182 // Stop further searching
184 } elseif ($unlArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
186 * IP matches listen address. At this point we really don't care
187 * if we can really listen on that address
191 // Remember the port number
192 $this->bootUnlInstance = $unlArray;
195 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unlArray->__toString() . '.');
197 // Stop further searching
207 * Outputs the console teaser. This should only be executed on startup or
208 * full restarts. This method generates some space around the teaser.
212 public function outputConsoleTeaser () {
213 // Get the app instance (for shortening our code)
214 $app = $this->getApplicationInstance();
217 self::createDebugInstance(__CLASS__)->debugOutput(' ');
218 self::createDebugInstance(__CLASS__)->debugOutput($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
219 self::createDebugInstance(__CLASS__)->debugOutput('Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2014 Hub Developer Team');
220 self::createDebugInstance(__CLASS__)->debugOutput(' ');
221 self::createDebugInstance(__CLASS__)->debugOutput('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
222 self::createDebugInstance(__CLASS__)->debugOutput('This is free software, and you are welcome to redistribute it under certain');
223 self::createDebugInstance(__CLASS__)->debugOutput('conditions; see docs/COPYING for details.');
224 self::createDebugInstance(__CLASS__)->debugOutput(' ');
228 * Generic method to acquire a hub-id. On first run this generates a new one
229 * based on many pseudo-random data. On any later run, unless the id
230 * got not removed from database, it will be restored from the database.
232 * @param $requestInstance A Requestable class
233 * @param $responseInstance A Responseable class
236 public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) {
237 // Is there a node id?
238 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
239 // Get the node id from result and set it
240 $this->setNodeId($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID));
243 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found node-id: ' . $this->getNodeId() . '');
245 // Get an RNG instance
246 $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
248 // Generate a pseudo-random string
249 $randomString = $rngInstance->randomString(255);
251 // Hash and encrypt the string so we become a node id (also documented as "hub id")
252 $this->setNodeId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
254 // Register the node id with our wrapper
255 $this->getWrapperInstance()->registerNodeId($this, $this->getRequestInstance());
258 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new node-id: ' . $this->getNodeId() . '');
263 * Generates a session id which will be sent to the other hubs and peers
267 public function bootstrapGenerateSessionId () {
268 // Now get a search criteria instance
269 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
271 // Search for the node number one which is hard-coded the default
272 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
273 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $this->getRequestInstance()->getRequestElement('mode'));
274 $searchInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID , $this->getNodeId());
275 $searchInstance->setLimit(1);
277 // Remember it for later usage
278 $this->setSearchInstance($searchInstance);
280 // Get a random string
281 $randomString = $this->generateRamdomString(255);
283 // Hash and encrypt the string so we become a "node id" aka Hub-Id
284 $this->setSessionId($this->getCryptoInstance()->hashString($this->getCryptoInstance()->encryptString($randomString)));
286 // Register the node id with our wrapper
287 $this->getWrapperInstance()->registerSessionId($this, $this->getRequestInstance(), $searchInstance);
290 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
292 // Change the state because the node has auired a hub id
293 $this->getStateInstance()->nodeGeneratedSessionId();
297 * Generate a private key for en-/decryption
301 public function bootstrapGeneratePrivateKey () {
303 if ($this->getWrapperInstance()->ifNodeDataIsFound($this)) {
304 // Is the element set?
305 if (is_null($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY))) {
307 * Auto-generate the private key for e.g. out-dated database
308 * "tables". This allows a smooth update for the underlaying
311 $this->generatePrivateKeyAndHash($this->getSearchInstance());
313 // Get the node id from result and set it
314 $this->setPrivateKey(base64_decode($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY)));
315 $this->setPrivateKeyHash($this->getField(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH));
318 self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Re-using found private key hash: ' . $this->getPrivateKeyHash() . '');
322 * Generate it in a private method (no confusion with 'private
323 * method access' and 'private key' here! ;-)).
325 $this->generatePrivateKeyAndHash($this->getSearchInstance());
330 * Adds hub data elements to a given dataset instance
332 * @param $criteriaInstance An instance of a storeable criteria
333 * @param $requestInstance An instance of a Requestable class
336 public function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance = NULL) {
337 // Make sure request instance is set as it is not optional
338 assert($requestInstance instanceof Requestable);
340 // Add node number and type
341 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_NR , 1);
342 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE, $requestInstance->getRequestElement('mode'));
345 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID, $this->getNodeId());
347 // Add the session id if acquired
348 if ($this->getSessionId() != '') {
349 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID, $this->getSessionId());
352 // Add the private key if acquired
353 if ($this->getPrivateKey() != '') {
354 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY, base64_encode($this->getPrivateKey()));
355 $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH, $this->getPrivateKeyHash());
360 * Updates a given field with new value
362 * @param $fieldName Field to update
363 * @param $fieldValue New value to store
365 * @throws DatabaseUpdateSupportException If this class does not support database updates
366 * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
368 public function updateDatabaseField ($fieldName, $fieldValue) {
370 $this->partialStub('Unfinished!');
373 // Get a critieria instance
374 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
376 // Add search criteria
377 $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
378 $searchInstance->setLimit(1);
380 // Now get another criteria
381 $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
383 // Add criteria entry which we shall update
384 $updateInstance->addCriteria($fieldName, $fieldValue);
386 // Add the search criteria for searching for the right entry
387 $updateInstance->setSearchInstance($searchInstance);
389 // Set wrapper class name
390 $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
392 // Remember the update in database result
393 $this->getResultInstance()->add2UpdateQueue($updateInstance);
397 * Announces this hub to the upper (bootstrap or list) hubs. After this is
398 * successfully done the given task is unregistered from the handler. This
399 * might look a bit overloaded here but the announcement phase isn't a
400 * simple "Hello there" message, it may later on also contain more
401 * informations like the object list.
403 * @param $taskInstance The task instance running this announcement
405 * @throws NodeAlreadyAnnouncedException If this hub is already announced
406 * @todo Change the first if() block to check for a specific state
408 public function announceToUpperNodes (Taskable $taskInstance) {
409 // Is this hub node announced?
410 if ($this->hubIsAnnounced === TRUE) {
411 // Already announced!
412 throw new NodeAlreadyAnnouncedException($this, self::EXCEPTION_HUB_ALREADY_ANNOUNCED);
416 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
418 // Get a helper instance
419 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_helper_class');
421 // Load the announcement descriptor
422 $helperInstance->loadDescriptorXml($this);
424 // Compile all variables
425 $helperInstance->getTemplateInstance()->compileConfigInVariables();
427 // "Publish" the descriptor by sending it to the bootstrap/list nodes
428 $helperInstance->sendPackage($this);
430 // Change the state, this should be the last line except debug output
431 $this->getStateInstance()->nodeAnnouncingToUpperHubs();
434 self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
438 * Does a self-connect attempt on the public IP address. This should make
439 * it sure, we are reachable from outside world. For this kind of package we
440 * don't need that overload we have in the announcement phase.
442 * @param $taskInstance The task instance running this announcement
445 public function doSelfConnection (Taskable $taskInstance) {
447 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
449 // Get a helper instance
450 $helperInstance = ObjectFactory::createObjectByConfiguredName('node_self_connect_helper_class', array($this));
452 // Load the descriptor (XML) file
453 $helperInstance->loadDescriptorXml($this);
455 // Compile all variables
456 $helperInstance->getTemplateInstance()->compileConfigInVariables();
458 // And send the package away
459 $helperInstance->sendPackage($this);
462 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Self Connection: FINISHED');
466 * Activates the hub by doing some final preparation and setting
467 * $hubIsActive to TRUE.
469 * @param $requestInstance A Requestable class
470 * @param $responseInstance A Responseable class
473 public function activateNode (Requestable $requestInstance, Responseable $responseInstance) {
474 // Checks whether a listener is still active and shuts it down if one
475 // is still listening.
476 if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) {
477 // Shutdown them down before they can hurt anything
478 $this->shutdownListenerPool();
481 // Get the controller here
482 $controllerInstance = Registry::getRegistry()->getInstance('controller');
484 // Run all filters for the hub activation
485 $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
487 // ----------------------- Last step from here ------------------------
488 // Activate the hub. This is ALWAYS the last step in this method
489 $this->getStateInstance()->nodeIsActivated();
490 // ---------------------- Last step until here ------------------------
494 * Initializes the listener pool (class)
498 public function initializeListenerPool () {
500 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: START');
502 // Get a new pool instance
503 $this->setListenerPoolInstance(ObjectFactory::createObjectByConfiguredName('listener_pool_class', array($this)));
505 // Get an instance of the low-level listener
506 $listenerInstance = ObjectFactory::createObjectByConfiguredName('tcp_listener_class', array($this));
508 // Setup address and port
509 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
512 * All nodes can now use the same configuration entry because it can be
513 * customized in config-local.php.
515 $listenerInstance->setListenPortByConfiguration('node_listen_port');
517 // Initialize the listener
518 $listenerInstance->initListener();
520 // Get a decorator class
521 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_tcp_listener_class', array($listenerInstance));
523 // Add this listener to the pool
524 $this->getListenerPoolInstance()->addListener($decoratorInstance);
526 // Get a decorator class
527 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
529 // Add this listener to the pool
530 $this->getListenerPoolInstance()->addListener($decoratorInstance);
532 // Get an instance of the low-level listener
533 $listenerInstance = ObjectFactory::createObjectByConfiguredName('udp_listener_class', array($this));
535 // Setup address and port
536 $listenerInstance->setListenAddressByConfiguration('node_listen_addr');
539 * All nodes can now use the same configuration entry because it can be
540 * customized in config-local.php.
542 $listenerInstance->setListenPortByConfiguration('node_listen_port');
544 // Initialize the listener
545 $listenerInstance->initListener();
547 // Get a decorator class
548 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('node_udp_listener_class', array($listenerInstance));
550 // Add this listener to the pool
551 $this->getListenerPoolInstance()->addListener($decoratorInstance);
553 // Get a decorator class
554 $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
556 // Add this listener to the pool
557 $this->getListenerPoolInstance()->addListener($decoratorInstance);
560 self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Initialize listener: FINISHED.');
564 * Getter for isActive attribute
566 * @return $isActive Whether the hub is active
568 public final function isNodeActive () {
569 return $this->isActive;
573 * Enables (default) or disables isActive flag
575 * @param $isActive Whether the hub is active
578 public final function enableIsActive ($isActive = TRUE) {
579 $this->isActive = (bool) $isActive;
583 * Checks whether this node accepts announcements
585 * @return $acceptAnnouncements Whether this node accepts announcements
587 public final function isAcceptingAnnouncements () {
588 // Check it (this node must be active and not shutdown!)
589 $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive()));
592 return $acceptAnnouncements;
596 * Checks whether this node accepts DHT bootstrap requests
598 * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests
600 public final function isAcceptingDhtBootstrap () {
601 // Check it (this node must be active and not shutdown!)
602 $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive()));
605 return $acceptDhtBootstrap;
609 * Checks whether this node has attempted to announce itself
611 * @return $hasAnnounced Whether this node has attempted to announce itself
612 * @todo Add checking if this node has been announced to the sender node
614 public function ifNodeIsAnnouncing () {
616 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): state=' . $this->getStateInstance()->getStateName());
618 // Simply check the state of this node
619 $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncingState);
622 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeIsAnnouncing(): hasAnnounced=' . intval($hasAnnounced));
625 return $hasAnnounced;
629 * Checks whether this node has attempted to announce itself and completed it
631 * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it
632 * @todo Add checking if this node has been announced to the sender node
634 public function ifNodeHasAnnouncementCompleted () {
636 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): state=' . $this->getStateInstance()->getStateName());
638 // Simply check the state of this node
639 $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState);
642 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: ifNodeHasAnnouncementCompleted(): hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted));
645 return $hasAnnouncementCompleted;
649 * Enables whether this node accepts announcements
651 * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE)
654 protected final function enableAcceptingAnnouncements ($acceptAnnouncements = TRUE) {
655 $this->acceptAnnouncements = $acceptAnnouncements;
659 * Enables whether this node accepts DHT bootstrap requests
661 * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE)
664 public final function enableAcceptDhtBootstrap ($acceptDhtBootstrap = TRUE) {
665 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
666 $this->acceptDhtBootstrap = $acceptDhtBootstrap;
670 * Checks wether this node is accepting node-list requests
672 * @return $acceptsRequest Wether this node accepts node-list requests
674 public function isAcceptingNodeListRequests () {
676 * Only 'regular' nodes does not accept such requests, checking
677 * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be
678 * added then the next check will be TRUE.
680 $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR));
683 return $acceptsRequest;
687 * Determines an instance of a LocateableNode class
689 * @return $unlInstance An instance of a LocateableNode class for this node
691 public function determineUniversalNodeLocator () {
692 // Determine UNL based on this node:
693 // 1) Get discovery class
694 $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
697 $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
704 * "Getter" for an array of an instance of a LocateableNode class
706 * @return $unlArray An array from an instance of a LocateableNode class for this node
708 public final function getUniversalNodeLocatorArray () {
709 // Get the Universal Node Locator (UNL) instance
710 $unlInstance = $this->determineUniversalNodeLocator();
713 die(__METHOD__ . ':unlInstance[' . gettype($unlInstance) . ']=' . print_r($unlInstance, TRUE));
720 * Updates/refreshes node data (e.g. status).
723 * @todo Find more to do here
725 public function updateNodeData () {
726 // Set some dummy configuration entries, e.g. node_status
727 $this->getConfigInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName());
731 * Handles message answer by given data array
733 * @param $messageData A valid answer message data array
734 * @param $packageInstance An instance of a Receivable class
736 * @todo Handle thrown exception
738 public function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance) {
740 assert(!empty($messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]));
742 // Construct configuration entry for handling class' name
743 $classConfigEntry = strtolower($messageData[NetworkPackage::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class';
745 // Try to get a class
746 $handlerInstance = ObjectFactory::createObjectByConfiguredName($classConfigEntry);
749 $handlerInstance->handleAnswerMessageData($messageData, $packageInstance);
753 * "Getter" for an array of all accepted object types
755 * @return $objectList Array of all accepted object types
757 public function getListFromAcceptedObjectTypes () {
758 // Get registry instance
759 $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
762 $objectList = $objectRegistryInstance->getEntries(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME);
769 * Adds all required elements from given array into data set instance
771 * @param $dataSetInstance An instance of a StoreableCriteria class
772 * @param $nodeData An array with valid node data
775 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) {
776 // Add all data the array provides
777 foreach (NodeDistributedHashTableDatabaseWrapper::getAllElements() as $element) {
778 // Is the element there?
779 if (isset($nodeData[$element])) {
781 $dataSetInstance->addCriteria($element, $nodeData[$element]);
783 // Output warning message
784 /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: addArrayToDataSet(): Element ' . $element . ' not found in nodeData array.');