]> git.mxchange.org Git - hub.git/blob - application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
Also add session id.
[hub.git] / application / hub / main / wrapper / node / class_NodeDistributedHashTableDatabaseWrapper.php
1 <?php
2 /**
3  * A database wrapper for distributed hash tables
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
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
10  *
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.
15  *
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.
20  *
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/>.
23  */
24 class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implements NodeDhtWrapper, Registerable {
25         /**
26          * "Cached" results for dabase for looking for unpublished entries
27          */
28         private $unpublishedEntriesInstance = NULL;
29
30         // Constants for database table names
31         const DB_TABLE_NODE_DHT = 'node_dht';
32
33         // Constants for database column names
34         const DB_COLUMN_NODE_ID            = 'node_id';
35         const DB_COLUMN_SESSION_ID         = 'session_id';
36         const DB_COLUMN_EXTERNAL_IP        = 'external_ip';
37         const DB_COLUMN_LISTEN_PORT        = 'listen_port';
38         const DB_COLUMN_PRIVATE_KEY_HASH   = 'private_key_hash';
39         const DB_COLUMN_NODE_MODE          = 'node_mode';
40         const DB_COLUMN_ACCEPTED_OBJECTS   = 'accepted_object_types';
41         const DB_COLUMN_NODE_LIST          = 'node_list';
42         const DB_COLUMN_PUBLICATION_STATUS = 'publication_status';
43         const DB_COLUMN_ANSWER_STATUS      = 'answer_status';
44         const DB_COLUMN_ACCEPT_BOOTSTRAP   = 'accept_bootstrap';
45
46         // Publication status'
47         const PUBLICATION_STATUS_PENDING = 'PENDING';
48
49         // Exception codes
50         const EXCEPTION_NODE_ALREADY_REGISTERED = 0x800;
51         const EXCEPTION_NODE_NOT_REGISTERED     = 0x801;
52
53         /**
54          * Protected constructor
55          *
56          * @return      void
57          */
58         protected function __construct () {
59                 // Call parent constructor
60                 parent::__construct(__CLASS__);
61         }
62
63         /**
64          * Creates an instance of this database wrapper by a provided user class
65          *
66          * @return      $wrapperInstance        An instance of the created wrapper class
67          */
68         public static final function createNodeDistributedHashTableDatabaseWrapper () {
69                 // Get a new instance
70                 $wrapperInstance = new NodeDistributedHashTableDatabaseWrapper();
71
72                 // Set (primary!) table name
73                 $wrapperInstance->setTableName(self::DB_TABLE_NODE_DHT);
74
75                 // Return the instance
76                 return $wrapperInstance;
77         }
78
79         /**
80          * Static getter for an array of all DHT database entries
81          *
82          * @return      $elements       All elements for the DHT dabase
83          */
84         public static final function getAllElements () {
85                 // Create array and ...
86                 $elements = array(
87                         self::DB_COLUMN_NODE_ID,
88                         self::DB_COLUMN_SESSION_ID,
89                         self::DB_COLUMN_EXTERNAL_IP,
90                         self::DB_COLUMN_LISTEN_PORT,
91                         self::DB_COLUMN_PRIVATE_KEY_HASH,
92                         self::DB_COLUMN_NODE_MODE,
93                         self::DB_COLUMN_ACCEPTED_OBJECTS,
94                         self::DB_COLUMN_NODE_LIST
95                 );
96
97                 // ... return it
98                 return $elements;
99         }
100
101         /**
102          * Prepares a search instance for given node data
103          *
104          * @param       $nodeData                       An array with valid node data
105          * @return      $searchInstance         An instance of a SearchCriteria class
106          */
107         private function prepareSearchInstance (array $nodeData) {
108                 // Assert on array elements
109                 assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
110
111                 // Get instance
112                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
113
114                 // Search for node id and limit it to one entry
115                 $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
116                 $searchInstance->setLimit(1);
117
118                 // Return it
119                 return $searchInstance;
120         }
121
122         /**
123          * Getter for result instance for unpublished entries
124          *
125          * @return      $unpublishedEntriesInstance             Result instance
126          */
127         public final function getUnpublishedEntriesInstance () {
128                 return $this->unpublishedEntriesInstance;
129         }
130
131         /**
132          * Prepares a "local" instance of a StoreableCriteria class with all node
133          * data for insert/update queries. This data set contains data from *this*
134          * (local) node.
135          *
136          * @return      $dataSetInstance        An instance of a StoreableCriteria class
137          */
138         private function prepareLocalDataSetInstance () {
139                 // Get node/request instances
140                 $nodeInstance = NodeObjectFactory::createNodeInstance();
141                 $requestInstance = ApplicationHelper::getSelfInstance()->getRequestInstance();
142
143                 // Get a dataset instance
144                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
145
146                 // Set the primary key
147                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
148
149                 // Get ip:port combination and "explode" it
150                 $ipPort = $nodeInstance->getAddressPortArray();
151
152                 // Make sure both is valid
153                 assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
154
155                 // Get an array of all accepted object types
156                 $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
157
158                 // Make sure this is an array
159                 assert(is_array($objectList));
160
161                 // Add public node data
162                 $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE       , $requestInstance->getRequestElement('mode'));
163                 $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP     , $ipPort[0]);
164                 $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT     , $ipPort[1]);
165                 $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID         , $nodeInstance->getNodeId());
166                 $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID      , $nodeInstance->getSessionId());
167                 $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
168                 $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
169                 $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap()));
170
171                 // Return it
172                 return $dataSetInstance;
173         }
174
175         /**
176          * Checks whether the local (*this*) node is registered in the DHT by
177          * checking if the external ip/port is found.
178          *
179          * @return      $isRegistered   Whether *this* node is registered in the DHT
180          */
181         public function isLocalNodeRegistered () {
182                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
183
184                 // Get a search criteria instance
185                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
186
187                 // Get node instance
188                 $nodeInstance = NodeObjectFactory::createNodeInstance();
189
190                 // Get ip:port combination and "explode" it
191                 $ipPort = $nodeInstance->getAddressPortArray();
192
193                 /*
194                  * Make sure both is not 'invalid' which means that the resolver
195                  * didn't work.
196                  */
197                 assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
198
199                 // Add ip:port/node id as criteria
200                 $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]);
201                 $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]);
202                 $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID    , $nodeInstance->getNodeId());
203                 $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
204                 $searchInstance->setLimit(1);
205
206                 // Query database and get a result instance back
207                 $resultInstance = $this->doSelectByCriteria($searchInstance);
208
209                 // Cache result of if there is an entry, valid() will tell us if an entry is there
210                 $isRegistered = $resultInstance->valid();
211
212                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
213
214                 // Return result
215                 return $isRegistered;
216         }
217
218         /**
219          * Registeres the local (*this*) node with its data in the DHT.
220          *
221          * @return      void
222          */
223         public function registerLocalNode () {
224                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
225
226                 // Assert to make sure this method is called with no record in DB (the actual backend of the DHT)
227                 assert(!$this->isLocalNodeRegistered());
228
229                 // Get prepared data set instance
230                 $dataSetInstance = $this->prepareLocalDataSetInstance();
231
232                 // "Insert" this dataset instance completely into the database
233                 $this->queryInsertDataSet($dataSetInstance);
234
235                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
236         }
237
238         /**
239          * Updates local (*this*) node's data in DHT, this is but not limited to the
240          * session id, ip number (and/or hostname) and port number.
241          *
242          * @return      void
243          */
244         public function updateLocalNode () {
245                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
246
247                 // Assert to make sure this method is called with one record in DB (the actual backend of the DHT)
248                 assert($this->isLocalNodeRegistered());
249
250                 // Get node instance
251                 $nodeInstance = NodeObjectFactory::createNodeInstance();
252
253                 // Get search criteria
254                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
255
256                 // Search for node id and limit it to one entry
257                 $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeInstance->getNodeId());
258                 $searchInstance->setLimit(1);
259
260                 // Get a prepared dataset instance
261                 $dataSetInstance = $this->prepareLocalDataSetInstance();
262
263                 // Set search instance
264                 $dataSetInstance->setSearchInstance($searchInstance);
265
266                 // Update DHT database record
267                 $this->queryUpdateDataSet($dataSetInstance);
268
269                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
270         }
271
272         /**
273          * Finds a node locally by given session id
274          *
275          * @param       $sessionId      Session id to lookup
276          * @return      $nodeData       Node data array
277          */
278         public function findNodeLocalBySessionId ($sessionId) {
279                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!');
280
281                 // Get search criteria
282                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
283
284                 // Search for session id and limit it to one entry
285                 $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $sessionId);
286                 $searchInstance->setLimit(1);
287
288                 // Query database and get a result instance back
289                 $resultInstance = $this->doSelectByCriteria($searchInstance);
290
291                 // Return result instance
292                 return $resultInstance;
293         }
294
295         /**
296          * Registeres a node by given message data.
297          *
298          * @param       $messageData            An array of all message data
299          * @param       $handlerInstance        An instance of a Handleable class
300          * @return      void
301          */
302         public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance) {
303                 // Get a data set instance
304                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
305
306                 // Set primary key (session id)
307                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
308
309                 // Add all array elements
310                 $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
311
312                 // Remove 'node_list'
313                 $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
314
315                 // Run the "INSERT" query
316                 $this->queryInsertDataSet($dataSetInstance);
317         }
318
319         /**
320          * Updates an existing entry in node list
321          *
322          * @param       $messageData            An array of all message data
323          * @param       $handlerInstance        An instance of a Handleable class
324          * @param       $searchInstance         An instance of LocalSearchCriteria class
325          * @return      void
326          */
327         public function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance) {
328                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
329
330                 // Get a data set instance
331                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
332
333                 // Add search instance
334                 $dataSetInstance->setSearchInstance($searchInstance);
335
336                 // Set primary key (session id)
337                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
338
339                 // Add all array elements
340                 $handlerInstance->addArrayToDataSet($dataSetInstance, $messageData);
341
342                 // Remove 'node_list'
343                 $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
344
345                 // Run the "UPDATE" query
346                 $this->queryUpdateDataSet($dataSetInstance);
347
348                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
349         }
350
351         /**
352          * Determines whether the given node data is already inserted in the DHT
353          *
354          * @param       $nodeData               An array with valid node data
355          * @return      $isRegistered   Whether the given node data is already inserted
356          */
357         public function isNodeRegistered (array $nodeData) {
358                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
359
360                 // Assert on array elements
361                 assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
362
363                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]);
364
365                 // Get search criteria
366                 $searchInstance = $this->prepareSearchInstance($nodeData);
367
368                 // Query database and get a result instance back
369                 $resultInstance = $this->doSelectByCriteria(
370                         // Search instance
371                         $searchInstance,
372                         // Only look for these array elements ("keys")
373                         array(
374                                 self::DB_COLUMN_NODE_ID     => TRUE,
375                                 self::DB_COLUMN_EXTERNAL_IP => TRUE,
376                                 self::DB_COLUMN_LISTEN_PORT => TRUE,
377                         )
378                 );
379
380                 // Check if there is an entry
381                 $isRegistered = $resultInstance->valid();
382
383                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
384
385                 // Return registration status
386                 return $isRegistered;
387         }
388
389         /**
390          * Registers a node with given data in the DHT. If the node is already
391          * registered this method shall throw an exception.
392          *
393          * @param       $nodeData       An array with valid node data
394          * @return      void
395          * @throws      NodeAlreadyRegisteredException  If the node is already registered
396          */
397         public function registerNode (array $nodeData) {
398                 // Assert on array elements
399                 assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
400
401                 // Is the node registered?
402                 if ($this->isNodeRegistered($nodeData)) {
403                         // Throw an exception
404                         throw new NodeAlreadyRegisteredException(array($this, $nodeData), self::EXCEPTION_NODE_ALREADY_REGISTERED);
405                 } // END - if
406
407                 // @TODO Unimplemented part
408                 $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
409         }
410
411         /**
412          * Updates a node's entry in the DHT with given data. This will enrich or
413          * just update already exsiting data. If the node is not found this method
414          * shall throw an exception.
415          *
416          * @param       $nodeData       An array with valid node data
417          * @return      void
418          * @throws      NodeDataMissingException        If the node's data is missing
419          */
420         public function updateNode (array $nodeData) {
421                 // Assert on array elements
422                 assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
423
424                 // Debug message
425                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...');
426
427                 // Is the node registered?
428                 if (!$this->isNodeRegistered($nodeData)) {
429                         // No, then throw an exception
430                         throw new NodeDataMissingException(array($this, $nodeData), self::EXCEPTION_NODE_NOT_REGISTERED);
431                 } // END - if
432
433                 // Get a search instance
434                 $searchInstance = $this->prepareSearchInstance($nodeData);
435
436                 // Get a data set instance
437                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
438
439                 // Add search instance
440                 $dataSetInstance->setSearchInstance($searchInstance);
441
442                 // Set primary key (session id)
443                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_SESSION_ID);
444
445                 // Get node instance
446                 $nodeInstance = NodeObjectFactory::createNodeInstance();
447
448                 // Debug message
449                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE));
450
451                 // Add all array elements
452                 $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
453
454                 // Remove 'node_list'
455                 $dataSetInstance->unsetCriteria(self::DB_COLUMN_NODE_LIST);
456
457                 // Run the "UPDATE" query
458                 $this->queryUpdateDataSet($dataSetInstance);
459         }
460
461         /**
462          * Checks whether there are unpublished entries
463          *
464          * @return      $hasUnpublished         Whether there are unpublished entries
465          * @todo        Add minimum/maximum age limitations
466          */
467         public function hasUnpublishedEntries () {
468                 // Get search instance
469                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
470
471                 // Add exclusion key which is the publish status
472                 $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_PUBLICATION_STATUS, NodeDistributedHashTableDatabaseWrapper::PUBLICATION_STATUS_PENDING);
473
474                 // Remember search instance
475                 $this->setSearchInstance($searchInstance);
476
477                 // Run the query
478                 $this->unpublishedEntriesInstance = $this->doSelectByCriteria($searchInstance);
479
480                 // Check pending entries
481                 $hasUnpublished = $this->unpublishedEntriesInstance->valid();
482
483                 // Return it
484                 return $hasUnpublished;
485         }
486
487         /**
488          * Initializes publication of DHT entries. This does only prepare
489          * publication. The next step is to pickup such prepared entries and publish
490          * them by uploading to other (recently appeared) DHT members.
491          *
492          * @return      void
493          * @todo        Add timestamp to dataset instance
494          */
495         public function initEntryPublication () {
496                 /*
497                  * Make sure that hasUnpublishedEntries() has been called first by
498                  * asserting on the "cached" object instance. This "caching" saves some
499                  * needless queries as this method shall be called immediately after
500                  * hasUnpublishedEntries() returns TRUE.
501                  */
502                 assert($this->unpublishedEntriesInstance instanceof SearchableResult);
503
504                 // Result is still okay?
505                 assert($this->unpublishedEntriesInstance->valid());
506
507                 // Remove 'publication_status'
508                 $this->getSearchInstance()->unsetCriteria(self::DB_COLUMN_PUBLICATION_STATUS);
509
510                 // Make sure all entries are marked as pending, first get a dataset instance.
511                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
512
513                 // Add search instance
514                 $dataSetInstance->setSearchInstance($this->getSearchInstance());
515
516                 // Set primary key (node id)
517                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
518
519                 // Add criteria (that should be set)
520                 $dataSetInstance->addCriteria(self::DB_COLUMN_PUBLICATION_STATUS, self::PUBLICATION_STATUS_PENDING);
521
522                 // Run the "UPDATE" query
523                 $this->queryUpdateDataSet($dataSetInstance);
524         }
525
526         /**
527          * Removes non-public data from given array.
528          *
529          * @param       $data   An array with possible non-public data that needs to be removed.
530          * @return      $data   A cleaned up array with only public data.
531          */
532         public function removeNonPublicDataFromArray(array $data) {
533                 // Currently call only inner method
534                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Calling parent::removeNonPublicDataFromArray(data) ...');
535                 $data = parent::removeNonPublicDataFromArray($data);
536                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: data[]=' . gettype($data));
537
538                 // Return cleaned data
539                 return $data;
540         }
541
542         /**
543          * Find recipients for given package data and exclude the sender
544          *
545          * @param       $packageData    An array of valid package data
546          * @return      $recipients             An indexed array with DHT recipients
547          */
548         public function getResultFromExcludedSender (array $packageData) {
549                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
550
551                 // Assert on required array field
552                 assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
553
554                 // Get max recipients
555                 $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
556
557                 // First creata a search instance
558                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
559
560                 // Then exclude 'sender' field as the sender is the current (*this*) node
561                 $searchInstance->addExcludeCriteria(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID, $packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
562
563                 // Set limit to maximum DHT recipients
564                 $searchInstance->setLimit($maxRecipients);
565
566                 // Get a result instance back from DHT database wrapper.
567                 $resultInstance = $this->doSelectByCriteria($searchInstance);
568
569                 /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
570
571                 // Return result instance
572                 return $resultInstance;
573         }
574
575         /**
576          * Find recopients by given key/value pair. First look for the key and if it
577          * matches, compare the value.
578          *
579          * @param       $key                    Key to look for
580          * @param       $value                  Value to compare if key matches
581          * @return      $recipients             An indexed array with DHT recipients
582          */
583         public function getResultFromKeyValue ($key, $value) {
584                 // Get max recipients
585                 $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
586
587                 // First creata a search instance
588                 $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
589
590                 // Find the key/value pair
591                 $searchInstance->addCriteria($key, $value);
592
593                 // Get a result instance back from DHT database wrapper.
594                 $resultInstance = $this->doSelectByCriteria($searchInstance);
595
596                 // Return result instance
597                 return $resultInstance;
598         }
599
600         /**
601          * Enable DHT bootstrap request acceptance for local node
602          *
603          * @return      void
604          */
605         public function enableAcceptDhtBootstrap () {
606                 // Debug message
607                 /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
608
609                 // Is the node already registered?
610                 if ($this->isLocalNodeRegistered()) {
611                         // Just update our record
612                         $this->updateLocalNode();
613                 } else {
614                         // Register it
615                         $this->registerLocalNode();
616                 }
617         }
618 }
619
620 // [EOF]
621 ?>