// CFG: DHT-RECIPIENT-DISCOVERY-CLASS
$cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery');
-// CFG: UNIVERSAL-NODE-LOCATOR-DISCOVERY-CLASS
+// CFG: UNL-DISCOVERY-CLASS
$cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery');
+// CFG: UNIVERSAL-NODE-LOCATOR-CLASS
+$cfg->setConfigEntry('universal_node_locator_class', 'UniversalNodeLocator');
+
// CFG: RECIPIENT-LIST-CLASS
$cfg->setConfigEntry('recipient_list_class', 'RecipientList');
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s',
+ $message = sprintf('[%s:%d] This node (%s) is not accepting announcements, but got one from session-id=%s,unl=%s/%s,status=%s,mode=%s',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[1]->__toString(),
$messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID],
$messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS],
$messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS],
- $messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT],
$messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS],
$messageArray[2][XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,ip=%s/%s,listen port=%s,status=%s.',
+ $message = sprintf('[%s:%d] This node (%s) has not attempted to announce itself, but got an answer from session-id=%s,unl=%s/%s,status=%s.',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[1]->__toString(),
$messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID],
$messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS],
$messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS],
- $messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT],
$messageArray[2][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s',
+ $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,unl=%s/%s,status=%s,mode=%s',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[0]->getNodeInstance()->__toString(),
$messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID],
$messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS],
$messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS],
- $messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT],
$messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS],
$messageArray[1][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] Session id %s cannot be verfied. ip=%s/%s,listen port=%s,status=%s.',
+ $message = sprintf('[%s:%d] Session id %s cannot be verfied. unl=%s/%s,status=%s.',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID],
$messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS],
$messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS],
- $messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT],
$messageArray[1][XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS]
);
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] Node already registered: session-id=%s, external-address=%s, listen-port=%s',
+ $message = sprintf('[%s:%d] Node already registered: session-id=%s, external-address=%s',
$messageArray[0]->__toString(),
$this->getLine(),
$msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT],
+ $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
);
// Call parent exception constructor
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] Node not registered/missing: session-id=%s, external-address=%s, listen-port=%s',
+ $message = sprintf('[%s:%d] Node not registered/missing: session-id=%s, external-address=%s',
$messageArray[0]->__toString(),
$this->getLine(),
$msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT],
+ $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
);
// Call parent exception constructor
/**
* "Getter for an array of an instance of a LocateableNode class
*
- * @return $unlArray An array of an instance of a LocateableNode class
+ * @return $unlData An array of an instance of a LocateableNode class
*/
function getUniversalNodeLocatorArray ();
// Then resolve the node instance into an UNL instance
$unlInstance = $resolverInstance->resolveUniversalNodeLocatorFromNodeHelper($nodeInstance);
- die(__METHOD__ . ':unlInstance=' . print_r($unlInstance, TRUE));
+
+ // ... and return it
+ return $unlInstance;
}
/**
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 9060,
BaseXmlAnswerTemplateEngine::ANSWER_STATUS => '',
);
}
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => '',
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => '',
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => '',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 9060,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => ''
);
}
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => '',
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE => '',
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => '',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 9060,
);
}
$this->searchData = array(
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
);
// Set handler name
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT,
);
// Init message-data->configuration translation array
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port',
);
// Init array
$this->searchData = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS
);
}
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT,
BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
);
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT => 'node_listen_port',
);
// Init array
$this->searchData = array(
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
);
}
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
);
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 'node_listen_port',
);
// Init array
$this->searchData = array(
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT
);
}
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE,
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
);
// Init message-data->configuration translation array
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT => 'node_listen_port',
);
// Init array
$this->searchData = array(
XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT
);
}
*/
private function generateExternalUnl () {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Is there cache? (This shortens a lot calls)
if (!isset($GLOBALS[__METHOD__])) {
} // END - if
// Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
return $GLOBALS[__METHOD__];
}
// Run through all configured IPs
foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
- // @TODO Unfinished
- die(__METHOD__ . ':' . print_r($this, TRUE));
- die(__METHOD__ . ': unl=' . $unl . ',remoteAddr=' . $remoteAddr);
-
// Does it match?
if ($unl == $remoteAddr) {
// Found it!
$this->bootUnl = $unl;
// Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl->__toString() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
// Stop further searching
break;
$this->bootUnl = $unl;
// Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl->__toString() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.');
// Stop further searching
break;
* @return $unl Node's own universal node locator
*/
public function detectOwnUniversalNodeLocator () {
- // Get the UNL array back
- $unlArray = $this->getUniversalNodeLocatorArray();
+ // Is "cache" set?
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Get the UNL array back
+ $unlData = $this->getUniversalNodeLocatorArray();
+
+ // There are 2 UNLs, internal and external.
+ if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
+ // Public "external" UNL address
+ $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL];
+ } else {
+ // Non-public "internal" UNL address
+ $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
+ }
+ } // END - if
- // @TODO
- die(__METHOD__ . ':unlArray=' . print_r($unlArray, TRUE));
+ // Return it
+ return $GLOBALS[__METHOD__];
}
/**
*/
public function determineUniversalNodeLocator () {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Determine UNL based on this node:
// 1) Get discovery class
$unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
// 3) Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!');
return $unlInstance;
}
/**
* "Getter" for an array of an instance of a LocateableNode class
*
- * @return $unlArray An array from an instance of a LocateableNode class for this node
+ * @return $unlData An array from an instance of a LocateableNode class for this node
*/
public final function getUniversalNodeLocatorArray () {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Get the Universal Node Locator (UNL) instance
$unlInstance = $this->determineUniversalNodeLocator();
- // @TODO Unfinished
- die(__METHOD__ . ':unlInstance[' . gettype($unlInstance) . ']=' . print_r($unlInstance, TRUE));
+ // ... and the array from it
+ $unlData = $unlInstance->getUnlData();
// Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
- return $unlArray;
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ return $unlData;
}
/**
// Temporary resolve recipient field
die(__METHOD__ . ': UNFINISHED!' . PHP_EOL);
- $unlArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+ $unlData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
// Make sure it is a valid Universal Node Locator array (3 elements)
- assert(count($unlArray) == 3);
+ assert(count($unlData) == 3);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlArray[0]=' . $unlArray[0] . ',unlArray[1]=' . $unlArray[1] . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[0]=' . $unlData[0] . ',unlData[1]=' . $unlData[1] . ' ...');
// Default is all sockets
$sockets = $this->getAllSockets();
// Get
// If the "peer" IP and recipient is same, use it
- if ($peerIp == $unlArray[0]) {
+ if ($peerIp == $unlData[0]) {
// IPs match, so take the socket and quit this loop
$socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];
// @TODO Unfinished
die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE));
assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]));
- assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]));
// Put ip and port both together
- $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+ $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
// Add it to the list
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...');
// Try it on all
foreach ($recipients as $recipient) {
// Try to sole a single recipient
- $unlArray = HubTools::resolveSessionId($recipient);
+ $unlData = HubTools::resolveSessionId($recipient);
// Add it as recipient
- $listInstance->addEntry('unl', $unlArray);
+ $listInstance->addEntry('unl', $unlData);
} // END - foreach
}
}
assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER);
// Get all bootstrap nodes
- foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) {
+ foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) {
// Is maximum reached?
if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
// Debug message
} // END - if
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlArray, TRUE) . ' as recipient.');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
// Add the entry
- $listInstance->addEntry('unl', $unlArray);
+ $listInstance->addEntry('unl', $unlData);
} // END - foreach
}
}
* @todo 0% done
*/
public function resolveUniversalNodeLocatorFromNodeHelper (NodeHelper $nodeInstance) {
- // Get result instance
- $resultInstance = $nodeInstance->getResultInstance();
+ // Get search instance (to lookup database result)
+ $searchInstance = $nodeInstance->getSearchInstance();
- // Make sure the result instance is valid
- assert($resultInstance instanceof SearchableResult);
+ // Make sure the in stance is valid
+ assert($searchInstance instanceof SearchCriteria);
- // Rewind iterator
- $resultInstance->rewind();
+ // Refetch and rewind iterator
+ $resultInstance = $nodeInstance->getWrapperInstance()->doSelectByCriteria($searchInstance);
- // Lookup node's id
- while ($resultInstance->next()) {
- // Get current entry
- $current = $resultInstance->current();
+ // Is the result valid?
+ if ((!$resultInstance->valid()) || (! $resultInstance->next())) {
+ // Node not found in database, this could mean that your database file is damaged.
+ return NULL;
+ } // END - if
- // Do we have found an entry?
- // $nodeInstance->getNodeId()
- die(print_r($current, TRUE));
- } // END - while
+ // Get current entry
+ $current = $resultInstance->current();
+
+ // This should always be the case, if not your database file might be damaged.
+ assert($nodeInstance->getNodeId() == $current[NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID]);
+
+ // Get UNL instance and handle over all data
+ $unlInstance = ObjectFactory::createObjectByConfiguredName('universal_node_locator_class', array($current));
+
+ // Return resolved instance
+ return $unlInstance;
}
/**
const ANNOUNCEMENT_DATA_NODE_MODE = 'node-mode';
const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'external-address';
const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'internal-address';
- const ANNOUNCEMENT_DATA_LISTEN_PORT = 'listen-port';
/**
* Protected constructor
'listener',
self::ANNOUNCEMENT_DATA_NODE_STATUS,
self::ANNOUNCEMENT_DATA_NODE_MODE,
- self::ANNOUNCEMENT_DATA_LISTEN_PORT,
self::ANNOUNCEMENT_DATA_SESSION_ID,
self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
$this->getStackInstance()->pushNamed('node_announcement', 'listener');
}
- /**
- * Starts the TCP/UDP listen port
- *
- * @return void
- */
- protected function startListenPort () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement', self::ANNOUNCEMENT_DATA_LISTEN_PORT);
- }
-
/**
* Starts the session id
*
$this->getStackInstance()->popNamed('node_announcement');
}
- /**
- * Finishes the TCP/UDP listen port
- *
- * @return void
- */
- protected function finishListenPort () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement');
- }
-
/**
* Finishes the listener
*
const ANNOUNCEMENT_DATA_NODE_STATUS = 'my-status';
const ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS = 'my-external-address';
const ANNOUNCEMENT_DATA_INTERNAL_ADDRESS = 'my-internal-address';
- const ANNOUNCEMENT_DATA_LISTEN_PORT = 'my-listen-port';
/**
* Protected constructor
// Data from *this* node
self::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- self::ANNOUNCEMENT_DATA_LISTEN_PORT,
self::ANNOUNCEMENT_DATA_NODE_STATUS,
self::ANNOUNCEMENT_DATA_SESSION_ID,
// Data from other node
$this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS);
}
- /**
- * Starts the my-tcp-port
- *
- * @return void
- */
- protected function startMyListenPort () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_announcement_answer', self::ANNOUNCEMENT_DATA_LISTEN_PORT);
- }
-
/**
* Starts the my-session-id
*
$this->getStackInstance()->popNamed('node_announcement_answer');
}
- /**
- * Finishes the my-tcp-port
- *
- * @return void
- */
- protected function finishMyListenPort () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_announcement_answer');
- }
-
/**
* Finishes the my-internal-address
*
const DHT_BOOTSTRAP_DATA_NODE_STATUS = 'my-status';
const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'my-external-address';
const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'my-internal-address';
- const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'my-listen-port';
const DHT_BOOTSTRAP_DATA_NODE_LIST = 'dht-nodes-list';
/**
// Data from *this* node
self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
self::DHT_BOOTSTRAP_DATA_SESSION_ID,
// Data from other node
$this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS);
}
- /**
- * Starts the my-tcp-port
- *
- * @return void
- */
- protected function startMyListenPort () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('node_dht_bootstrap_answer', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT);
- }
-
/**
* Starts the my-session-id
*
$this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
}
- /**
- * Finishes the my-tcp-port
- *
- * @return void
- */
- protected function finishMyListenPort () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('node_dht_bootstrap_answer');
- }
-
/**
* Finishes the my-internal-address
*
const DHT_BOOTSTRAP_DATA_NODE_MODE = 'node-mode';
const DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS = 'external-address';
const DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS = 'internal-address';
- const DHT_BOOTSTRAP_DATA_LISTEN_PORT = 'listen-port';
/**
* Protected constructor
'listener',
self::DHT_BOOTSTRAP_DATA_NODE_STATUS,
self::DHT_BOOTSTRAP_DATA_NODE_MODE,
- self::DHT_BOOTSTRAP_DATA_LISTEN_PORT,
self::DHT_BOOTSTRAP_DATA_SESSION_ID,
self::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
self::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS
$this->getStackInstance()->pushNamed('dht_bootstrap', 'listener');
}
- /**
- * Starts the TCP/UDP listen port
- *
- * @return void
- */
- protected function startListenPort () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_bootstrap', self::DHT_BOOTSTRAP_DATA_LISTEN_PORT);
- }
-
/**
* Starts the public ip
*
$this->getStackInstance()->popNamed('dht_bootstrap');
}
- /**
- * Finishes the TCP/UDP listen port
- *
- * @return void
- */
- protected function finishListenPort () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_bootstrap');
- }
-
/**
* Finishes the listener
*
const PUBLISH_DATA_NODE_STATUS = 'node-status';
const PUBLISH_DATA_NODE_MODE = 'node-mode';
const PUBLISH_DATA_EXTERNAL_ADDRESS = 'external-address';
- const PUBLISH_DATA_LISTEN_PORT = 'listen-port';
const PUBLISH_DATA_PRIVATE_KEY_HASH = 'private-key-hash';
const PUBLISH_DATA_ACCEPTED_OBJECT_TYPES = 'accepted-object-types';
'listener',
self::PUBLISH_DATA_NODE_STATUS,
self::PUBLISH_DATA_NODE_MODE,
- self::PUBLISH_DATA_LISTEN_PORT,
self::PUBLISH_DATA_PRIVATE_KEY_HASH,
self::PUBLISH_DATA_ACCEPTED_OBJECT_TYPES,
self::PUBLISH_DATA_NODE_ID,
$this->getStackInstance()->pushNamed('dht_publish', 'listener');
}
- /**
- * Starts the TCP/UDP listen port
- *
- * @return void
- */
- protected function startListenPort () {
- // Push the node name on the stacker
- $this->getStackInstance()->pushNamed('dht_publish', self::PUBLISH_DATA_LISTEN_PORT);
- }
-
/**
* Starts accepted object types
*
$this->getStackInstance()->popNamed('dht_publish');
}
- /**
- * Finishes the TCP/UDP listen port
- *
- * @return void
- */
- protected function finishListenPort () {
- // Pop the last entry
- $this->getStackInstance()->popNamed('dht_publish');
- }
-
/**
* Finishes hash from private key
*
$recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
// Is the recipient valid?
- if ((isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) && (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]))) {
+ if (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])) {
// Then use this
- $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+ $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS];
} else {
// Get the instance, this might throw a NPE
$nodeInstance = NodeObjectFactory::createNodeInstance();
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A UniversalNodeLocator
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class UniversalNodeLocator extends BaseFrameworkSystem implements LocateableNode {
+ /**
+ * UNL data array
+ */
+ private $unlData = array();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public final static function createUniversalNodeLocator (array $current = array()) {
+ // Get new instance
+ $unlInstance = new UniversalNodeLocator();
+
+ // Init instance
+ $unlInstance->initUniversalNodeLocator($current);
+
+ // Return the prepared instance
+ return $unlInstance;
+ }
+
+ /**
+ * Initializes the UNL instance by givena array. If an entry is found, it
+ * will be copied, otherwise the entry is set empty.
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return void
+ */
+ private function initUniversalNodeLocator (array $current = array()) {
+ // Init UNL array
+ $this->unlData = array();
+
+ // Copy all found entries
+ foreach (array(
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
+ NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
+ NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
+ // Init entry
+ $this->unlData[$key] = NULL;
+
+ // Is the key found?
+ if (isset($current[$key])) {
+ // The copy the entry
+ $this->unlData[$key] = $current[$key];
+ } // END - if
+ } // END - foreach
+ }
+
+ /**
+ * Getter for UNL data array
+ *
+ * @return $unlData An array with UNL data
+ */
+ public final function getUnlData () {
+ return $this->unlData;
+ }
+}
+
+// [EOF]
+?>
const DB_COLUMN_NODE_ID = 'node_id';
const DB_COLUMN_SESSION_ID = 'session_id';
const DB_COLUMN_EXTERNAL_ADDRESS = 'external_address';
- const DB_COLUMN_LISTEN_PORT = 'listen_port';
const DB_COLUMN_PRIVATE_KEY_HASH = 'private_key_hash';
const DB_COLUMN_NODE_MODE = 'node_mode';
const DB_COLUMN_ACCEPTED_OBJECTS = 'accepted_object_types';
self::DB_COLUMN_NODE_ID,
self::DB_COLUMN_SESSION_ID,
self::DB_COLUMN_EXTERNAL_ADDRESS,
- self::DB_COLUMN_LISTEN_PORT,
self::DB_COLUMN_PRIVATE_KEY_HASH,
self::DB_COLUMN_NODE_MODE,
self::DB_COLUMN_ACCEPTED_OBJECTS,
$dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
// Get Universal Node Locator and "explode" it
- $unl = $nodeInstance->getUniversalNodeLocatorArray();
+ $unlInstance = $nodeInstance->determineUniversalNodeLocator();
// Make sure both is valid
assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
// Add public node data
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode'));
- $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS , $unl[0]);
- $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT , $unl[1]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]);
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
$dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
$nodeInstance = NodeObjectFactory::createNodeInstance();
// Get Universal Node Locator and "explode" it
- $unl = $nodeInstance->getUniversalNodeLocatorArray();
+ $unlData = $nodeInstance->getUniversalNodeLocatorArray();
/*
* Make sure both is not 'invalid' which means that the resolver
* didn't work.
*/
- assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
+ die(__METHOD__ . ':unlData[' . gettype($unlData) . ']=' . print_r($unlData, TRUE) . PHP_EOL);
// Add Universal Node Locator/node id as criteria
$searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]);
- $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $unl[1]);
- $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
- $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
+ $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$searchInstance->setLimit(1);
// Query database and get a result instance back
// Only look for these array elements ("keys")
array(
self::DB_COLUMN_NODE_ID => TRUE,
- self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE,
- self::DB_COLUMN_LISTEN_PORT => TRUE,
+ self::DB_COLUMN_EXTERNAL_ADDRESS => TRUE
)
);
<external-address>{?external_address?}</external-address>
<!-- Private internal address //-->
<internal-address>{?internal_address?}</internal-address>
- <!-- Listener ports for both connections //-->
- <listen-port>{?node_listen_port?}</listen-port>
</listener>
</announcement-data>
</announcement>
//-->
<my-internal-address>{?my_internal_address?}</my-internal-address>
<!--
- This node's TCP/UDP listen port
- //-->
- <my-listen-port>{?my_listen_port?}</my-listen-port>
- <!--
This node's session id
//-->
<my-session-id>{?my_session_id?}</my-session-id>
//-->
<my-internal-address>{?my_internal_address?}</my-internal-address>
<!--
- This node's TCP/UDP listen port
- //-->
- <my-listen-port>{?my_listen_port?}</my-listen-port>
- <!--
This node's session id
//-->
<my-session-id>{?my_session_id?}</my-session-id>
<external-address>{?external_address?}</external-address>
<!-- Private internal address //-->
<internal-address>{?internal_address?}</internal-address>
- <!-- Listener ports for both connections //-->
- <listen-port>{?node_listen_port?}</listen-port>
</listener>
</dht-bootstrap-data>
</dht-bootstrap>
<listener>
<!-- Public external address //-->
<external-address>{?external_address?}</external-address>
- <!-- Listener ports for both connections //-->
- <listen-port>{?listen_port?}</listen-port>
</listener>
</publish-data>
</publish>
-Subproject commit eea9aadff7619b2a5c25972f37b34a1b83d30891
+Subproject commit 7bb55d2b90d5a32710bc0bb220cff5720194a6eb