// Is no external address set?
if ($this->getConfigInstance()->getConfigEntry('external_address') == '') {
// Determine external address
- $this->getConfigInstance()->setConfigEntry('external_address', ConsoleTools::determineExternalAddress());
+ $this->getConfigInstance()->setConfigEntry('external_address', HubTools::determineOwnExternalAddress());
} // END - if
// Default response is console
// CFG: UNL-DISCOVERY-CLASS
$cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery');
+// CFG: PROTOCOL-DISCOVERY-CLASS
+$cfg->setConfigEntry('protocol_discovery_class', 'ProtocolDiscovery');
+
+// CFG: TCP-PROTOCOL-HANDLER-CLASS
+$cfg->setConfigEntry('tcp_protocol_handler_class', 'TcpProtocolHandler');
+
// CFG: UNIVERSAL-NODE-LOCATOR-CLASS
$cfg->setConfigEntry('universal_node_locator_class', 'UniversalNodeLocator');
// CFG: PRIVATE-KEY-HASH
$cfg->setConfigEntry('private_key_hash', '');
-// CFG: INTERNAL-ADDRESS
-$cfg->setConfigEntry('internal_address', ConsoleTools::acquireSelfIPAddress());
-
// CFG: EXTERNAL-ADDRESS
$cfg->setConfigEntry('external_address', '');
+// CFG: INTERNAL-ADDRESS
+$cfg->setConfigEntry('internal_address', '');
+
// CFG: ALLOW-PUBLISH-INTERNAL-ADDRESS
$cfg->setConfigEntry('allow_publish_internal_address', 'N');
// the inc/database.php script
require($cfg->getConfigEntry('base_path') . 'inc/database.php');
-// Get's our IP address
-ConsoleTools::acquireSelfIPAddress();
+// Get own internal address
+HubTools::determineOwnInternalAddress();
// [EOF]
?>
--- /dev/null
+<?php
+/**
+ * An interface for !!! discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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/>.
+ */
+interface Discoverable!!! extends Discoverable {
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for protocol discovery
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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/>.
+ */
+interface DiscoverableProtocol extends Discoverable {
+ /**
+ * "Discovers" the protocol type from given raw package data. This is done
+ * by looking at the 'recipient' field and extract the first part from it.
+ *
+ * @param $packageData Raw package data
+ * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
+ */
+ function discoverProtocolByPackageData (array $packageData);
+}
+
+// [EOF]
+?>
function doShutdown ();
/**
- * Getter for port number to satify ProtocolHandler
+ * Getter for port number to satify HandleableProtocol
*
* @return $port The port number
*/
- function getPort ();
+ function getConnectionPort ();
/**
* Getter for IP address
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface HubHelper extends Helper {
+ /**
+ * Tries to determine the used protocol for this package (this helper is helping to send out)
+ *
+ * @return $protocolType Type of protocol to use, usually TCP
+ */
+ function determineProtocolType ();
}
// [EOF]
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-interface Listenable extends ProtocolHandler {
+interface Listenable extends FrameworkInterface {
/**
* Initializes the listener by setting up the required socket server
*
* @return void
*/
function monitorIncomingRawData (Receivable $receiverInstance);
+
+ /**
+ * Getter for listen address
+ *
+ * @return $listenAddress The address this listener should listen on
+ */
+ function getListenAddress ();
+
+ /**
+ * Getter for listen port
+ *
+ * @return $listenPort The port this listener should listen on
+ */
+ function getListenPort ();
+
+ /**
+ * Getter for peer pool instance
+ *
+ * @return $poolInstance The peer pool instance we shall set
+ */
+ function getPoolInstance ();
}
// [EOF]
* Chooses the right protocol from given package data
*
* @param $packageData Raw package data
- * @return $protocolInstance An instance of a ProtocolHandler class
+ * @return $protocolInstance An instance of a HandleableProtocol class
*/
function chooseProtocolFromPackageData (array $packageData);
*/
private $minerInstance = NULL;
- /**
- * Listener instance
- */
- private $listenerInstance = NULL;
-
/**
* A network package handler instance
*/
$this->minerInstance = $minerInstance;
}
- /**
- * Setter for listener instance
- *
- * @param $listenerInstance A Listenable instance
- * @return void
- */
- protected final function setListenerInstance (Listenable $listenerInstance) {
- $this->listenerInstance = $listenerInstance;
- }
-
- /**
- * Getter for listener instance
- *
- * @return $listenerInstance A Listenable instance
- */
- protected final function getListenerInstance () {
- return $this->listenerInstance;
- }
-
/**
* Setter for network package handler instance
*
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Protocol discovery class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Create an instance of this class
+ *
+ * @return $discoveryInstance An instance of this discovery class
+ */
+ public static final function createProtocolDiscovery () {
+ // Get an instance of this class
+ $discoveryInstance = new ProtocolDiscovery();
+
+ // Return the prepared instance
+ return $discoveryInstance;
+ }
+
+ /**
+ * "Discovers" the protocol type from given raw package data. This is done
+ * by looking at the 'recipient' field and extract the first part from it.
+ *
+ * @param $packageData Raw package data
+ * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections
+ */
+ public function discoverProtocolByPackageData (array $packageData) {
+ //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
+
+ /*
+ * "Explode" the 'recipient' array element into a new one, giving at
+ * least two entries: protocol://address
+ */
+ $recipient = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // At least 2 entries must be found
+ assert(count($recipient) >= 2);
+
+ // Now get the first part (protocol type) and make all lower-case
+ $protocolType = strtolower($recipient[0]);
+
+ // Return it
+ // @TODO Add some validation here???
+ return $protocolType;
+ }
+}
+
+// [EOF]
+?>
* 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 BaseRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableRecipient {
+class BaseRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableRecipient {
/**
* Protected constructor
*
* Determines the protoctol name
*
* @param $packageData Valid package data
- * @return $protocolInstance An instance of a ProtocolHandler class
+ * @return $protocolInstance An instance of a HandleableProtocol class
*/
protected function determineProtocolByPackageData (array $packageData) {
// First we need a tags instance
* @throws NullPointerException If listenerInstance is NULL
*/
public function discoverSocket (array $packageData, $connectionType) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!');
+
// Assert on type
assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
}
/**
- * Returns a singleton protocol handler instance from given HubHelper
- * instance. If an instance is found in registry, it will be returned, else
- * a new instance is created and stored in the same registry entry.
+ * Returns a protocol handler based on given protocol type. This is mostly 'tcp'.
*
- * @param $helperInstance An instance of a HubHelper class
+ * @param $protocolType Protocol type to create/return a protocol handler instance for
* @return $handlerInstance A protocol handler instance
*/
- public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
- // Get the protocol type from given helper instance
- die(__METHOD__ . ':' . print_r($helperInstance, TRUE));
-
+ private static function createProtocolHandlerByType ($protocolType) {
// Do we have an instance in the registry?
if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
// Then use this instance
// Return the instance
return $handlerInstance;
}
+
+ /**
+ * Returns a singleton protocol handler instance from given HubHelper
+ * instance. If an instance is found in registry, it will be returned, else
+ * a new instance is created and stored in the same registry entry.
+ *
+ * @param $helperInstance An instance of a HubHelper class
+ * @return $handlerInstance A protocol handler instance
+ */
+ public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
+ // Get the protocol type from given helper instance
+ $protocolType = $helperInstance->determineProtocolType();
+
+ // Call super factory method
+ return self::createProtocolHandlerByType($protocolType);
+ }
+
+ /**
+ * Creates an instance of a protocol handler from given (raw) package data
+ *
+ * @param $packageData An array with raw package data
+ * @return $handlerInstance A protocol handler instance
+ */
+ public static final function createProtocolHandlerFromPackageData (array $packageData) {
+ // Now that there is no direct node instance available, a protocol discovery class is required
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('protocol_discovery_class');
+
+ // "Discover" the protocol type
+ $protocolType = $discoveryInstance->discoverProtocolByPackageData($packageData);
+
+ // Call super factory method
+ return self::createProtocolHandlerByType($protocolType);
+ }
}
// [EOF]
* Creates a valid socket resource from given packae data and protocol
*
* @param $packageData Raw package data
- * @param $protocolInstance An instance of a ProtocolHandler class
+ * @param $protocolInstance An instance of a HandleableProtocol class
* @return $socketResource Socket resource
*/
- public static function createSocketFromPackageData (array $packageData, ProtocolHandler $protocolInstance) {
+ public static function createSocketFromPackageData (array $packageData, HandleableProtocol $protocolInstance) {
// Get an instance
$factoryInstance = new SocketFactory();
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? protocol handler
+ *
+ * @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 ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('|||_protocol');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function create???ProtocolHandler () {
+ // Get new instance
+ $handlerInstance = new ???ProtocolHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general handler for protocols such as TCP, UDP and others.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.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.shipsimu.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 BaseProtocolHandler extends BaseHandler {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Tcp protocol handler (IPv4)
+ *
+ * @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 TcpProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('tcp_protocol');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createTcpProtocolHandler () {
+ // Get new instance
+ $handlerInstance = new TcpProtocolHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+}
+
+// [EOF]
+?>
public final function setPackageTags (array $packageTags) {
$this->packageTags = $packageTags;
}
+
+ /**
+ * Tries to determine the used protocol for this package (this helper is helping to send out)
+ *
+ * @return $protocolType Type of protocol to use, usually TCP
+ * @todo 0% done
+ */
+ public function determineProtocolType () {
+ die(__METHOD__ . ':' . print_r($this, TRUE));
+ // Return it
+ }
}
// [EOF]
*/
const CONNECTION_TYPE_SERVER = 'server';
+ /**
+ * Name of used protocol for this connection
+ */
+ private $connectionType = 'invalid';
+
/**
* Port number used
*/
- private $port = 0;
+ private $connectionPort = 0;
/**
* (IP) Adress used
*/
public final function __toString () {
// Class name representation
- $class = self::getConnectionClassName($this->getAddress(), $this->getPort(), parent::__toString());
+ $class = self::getConnectionClassName($this->getAddress(), $this->getConnectionPort(), parent::__toString());
// Return it
return $class;
}
/**
- * Getter for port number to satify ProtocolHandler
+ * Getter for connection type
+ *
+ * @return $connectionType Name of used protocol in this connection
+ */
+ public final function getConnectionType () {
+ return $this->connectionType;
+ }
+
+ /**
+ * Setter for connection type
+ *
+ * @param $connectionType Name of used protocol in this connection
+ * @return void
+ */
+ protected final function setConnectionType ($connectionType) {
+ $this->connectionType = $connectionType;
+ }
+
+ /**
+ * Getter for port number to satify HandleableProtocol
*
- * @return $port The port number
+ * @return $connectionPort The port number
*/
- public final function getPort () {
- return $this->port;
+ public final function getConnectionPort () {
+ return $this->connectionPort;
}
/**
- * Setter for port number to satify ProtocolHandler
+ * Setter for port number to satify HandleableProtocol
*
- * @param $port The port number
+ * @param $connectionPort The port number
* @return void
*/
- protected final function setPort ($port) {
- $this->port = $port;
+ protected final function setConenctionPort ($connectionPort) {
+ $this->connectionPort = $connectionPort;
}
/**
// Try to solve the recipient
try {
// Resolve any session ids; 0 = IP, 1 = Port
- $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+ $resolved = HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+ die(__METHOD__ . 'resolved=' . print_r($resolved, TRUE));
+
+ $recipientData = explode(':', $resolved);
} catch (NoValidHostnameException $e) {
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage());
// Is the recipient equal as configured IP
if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
- // This connects to shipsimu.org and requests /ip.php which will return our external address
- $recipientData[0] = ConsoleTools::determineExternalAddress();
+ // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address
+ $recipientData[0] = HubTools::determineExternalAddress();
- // Do we have hostname:ip match?
+ // Do we have ip:port match?
+ // @TODO Rewrite this test for UNLs
if (strpos($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], ':') === FALSE) {
- // No hostname:ip!
+ // No ip:port!
$helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.');
} // END - if
- // "explode" the hostname:ip, so index 1 will be the port number
+ // "explode" the ip:port, so index 1 will be the port number
+ // @TODO Rewrite this test for UNLs
$recipientArray = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
// Add the port
// Set address and maybe port
$helperInstance->setAddress($recipientData[0]);
- $helperInstance->setPort($recipientData[1]);
+ $helperInstance->setConnectionPort($recipientData[1]);
// Now connect to it
if (!$helperInstance->connectToPeerByRecipientData($recipientData)) {
*/
public function sendPackage (Distributable $dhtInstance) {
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
/*
* Sanity check: Is the DHT in the approx. state? 'init' for bootstrap
$packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
// Next, feed the content in. The network package class is a pipe-through class.
+ //* DEBUG: */ die(__METHOD__ . ':dhtInstance=' . print_r($dhtInstance, TRUE));
$packageInstance->enqueueRawDataFromTemplate($this);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
}
return $this->listenPort;
}
- /**
- * Getter for port number to satify ProtocolHandler
- *
- * @return $port The port number
- */
- public final function getPort () {
- return $this->getListenPort();
- }
-
/**
* "Setter" to set listen address from configuration entry
*
return $this->getListenerInstance()->getListenPort();
}
- /**
- * Getter for port
- *
- * @return $port The port
- */
- public final function getPort () {
- return $this->getListenerInstance()->getPort();
- }
-
/**
* Accepts the visitor to process the visit "request"
*
* @todo add some more special bootstrap things for this boot node
*/
public function doBootstrapping () {
+ // Get UNL
+ $unl = $this->detectOwnUniversalNodeLocator();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
+
// Now check if the IP address matches one of the bootstrap nodes
- if ($this->ifAddressMatchesBootstrapNodes($this->detectOwnUniversalNodeLocator())) {
+ if ($this->ifAddressMatchesBootstrapNodes($unl)) {
// Get our port from configuration
$ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
}
} else {
// IP does match, but no port
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->detectOwnUniversalNodeLocator() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
}
} else {
// Node does not match any know bootstrap-node
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->detectOwnUniversalNodeLocator() . ' does not match any known bootstrap-nodes.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.');
}
// Enable acceptance of announcements
self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . '');
}
- /**
- * Generates an UNL (Universal Node Locator) for the internal address
- *
- * @return $internalUnl Internal UNL
- */
- private function generateInternalUnl () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is there cache? (This shortens a lot calls)
- if (!isset($GLOBALS[__METHOD__])) {
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
- } // END - if
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
- return $GLOBALS[__METHOD__];
- }
-
- /**
- * Generates an UNL (Universal Node Locator) for the external address
- *
- * @return $externalUnl External UNL
- */
- private function generateExternalUnl () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
-
- // Is there cache? (This shortens a lot calls)
- if (!isset($GLOBALS[__METHOD__])) {
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
- } // END - if
-
- // Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
- return $GLOBALS[__METHOD__];
- }
-
/**
* Generates a random string from various data inluding UUID if PECL
* extension uuid is installed.
$this->bootUnl = $unl;
// Output message
- self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL 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 . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches listen address ' . $unl . '.');
// Stop further searching
break;
} // END - if
// Add own external and internal addresses as UNLs
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, $this->generateInternalUnl());
- $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, $this->generateExternalUnl());
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, HubTools::determineOwnInternalAddress());
+ $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, HubTools::determineOwnExternalAddress());
}
/**
// Get the Universal Node Locator (UNL) instance
$unlInstance = $this->determineUniversalNodeLocator();
+ // Make sure the instance is valid
+ // * DEBUG: */ $this->debugInstance('unlInstance[]=' . gettype($unlInstance));
+ assert($unlInstance instanceof LocateableNode);
+
// ... and the array from it
$unlData = $unlInstance->getUnlData();
*/
const PACKAGE_DATA_SENDER = 'sender';
const PACKAGE_DATA_RECIPIENT = 'recipient';
- const PACKAGE_DATA_PROTOCOL = 'protocol';
const PACKAGE_DATA_CONTENT = 'content';
const PACKAGE_DATA_STATUS = 'status';
const PACKAGE_DATA_SIGNATURE = 'signature';
// Now get an iterator
$iteratorInstance = $discoveryInstance->getIterator();
+ // Make sure the iterator instance is valid
+ assert($iteratorInstance instanceof Iterator);
+
// Rewind back to the beginning
$iteratorInstance->rewind();
$currentRecipient = $iteratorInstance->current();
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]);
// Set the recipient
$packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
$this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient);
// Skip to next entry
$iteratorInstance->next();
* @return void
*/
public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
- // Get protocol instance for recipient
- $protocolInstance = ProtocolHandlerFactory::createProtocolHandlerFromRecipientHelper($helperInstance);
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
// Get the raw content ...
$content = $helperInstance->getTemplateInstance()->getRawTemplateData();
$this->getHashFromContent($content)
);
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...');
+
// Now prepare the temporary array and push it on the 'undeclared' stack
$this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
self::PACKAGE_DATA_SENDER => $this->getSessionId(),
self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
- self::PACKAGE_DATA_PROTOCOL => $protocolInstance->getProtocolName(),
self::PACKAGE_DATA_CONTENT => $packageContent,
self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW,
self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($packageContent, $this->getSessionId())
));
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
}
/**
* @throws NoTargetException If no target can't be determined
*/
public function declareEnqueuedPackage () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
// Make sure this method isn't working if there is no package enqueued
if (!$this->isPackageEnqueued()) {
// This is not fatal but should be avoided
// Declare the raw package data for delivery
$this->declareRawPackageData($packageData);
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
}
/**
* @return void
*/
public function processDeclaredPackage () {
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
// Sanity check if we have packages declared
if (!$this->isPackageDeclared()) {
// This is not fatal but should be avoided
// Mark the package with status failed
$this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED);
}
+
+ // Debug message
+ //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
}
/**
* @return void
*/
public function sendWaitingPackage () {
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
// Sanity check if we have packages waiting for delivery
if (!$this->isPackageWaitingForDelivery()) {
// This is not fatal but should be avoided
// Mark package as failed
$this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED);
}
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
}
/**
* @return void
*/
public function sendEncodedData () {
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!');
+
// Make sure there is pending encoded data
assert($this->isEncodedDataPending());
// Push array back in stack
$this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
+
+ // Debug message
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!');
}
///////////////////////////////////////////////////////////////////////////
return;
} elseif (!$this->getIteratorInstance()->valid()) {
// This producer's iterator has finished its assignment
- self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorinstance=' . $this->getIteratorInstance()->__toString() . '');
+ self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorInstance=' . $this->getIteratorInstance()->__toString() . '');
return;
}
*/
public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient);
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
// "Explode" all recipients
$recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
*/
public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
// Make sure the recipient is valid
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient);
- // @TODO Unfinished
- die(__METHOD__ . 'recipient=:' . print_r($recipient, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient);
+ // @TODO Add more checks on data
assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
- // Determine own port
- $port = $this->getConfigInstance()->getConfigEntry('node_listen_port');
-
// Determine IP or 'external_address' if set
- $ip = HubTools::determineOwnExternalAddress();
+ $unl = HubTools::determineOwnExternalAddress();
// Is it not empty?
- if (!empty($ip)) {
+ if (!empty($unl)) {
// Add it to the list
- $listInstance->addEntry('unl', $ip . ':' . $port);
+ $listInstance->addEntry('unl', $unl);
} // END - if
}
}
// Is maximum reached?
if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
// Then stop adding more
break;
} // END - if
// Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
+ /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Adding node ' . print_r($unlData, TRUE) . ' as recipient.');
// Add the entry
$listInstance->addEntry('unl', $unlData);
/**
* "Getter" to get a string respresentation for a key for the sub-registry
- * in this format: class:protocol:port
+ * in this format: class:type:port
*
* @param $connectionInstance An instance of a ConnectionHelper class
* @return $key A string representation of the socket for the registry
*/
private function getSubRegistryKey (ConnectionHelper $connectionInstance) {
- // Get protocol and port number and add both together
- $key = sprintf("%s:%s:%s",
+ // Get connection type and port number and add both together
+ $key = sprintf('%s:%s:%s',
$connectionInstance->__toString(),
- $connectionInstance->getProtocolName(),
- $connectionInstance->getPort()
+ $connectionInstance->getConnectionType(),
+ $connectionInstance->getConnectionPort()
);
// Return resulting key
/**
* "Getter" to get a string respresentation of the protocol
*
- * @param $connectionInstance An instance of a ConnectionHelper class
- * @return $key A string representation of the protocol for the registry
+ * @param $connectionInstance An instance of a ConnectionHelper class
+ * @return $key A string representation of the protocol for the registry
*/
- private function getRegistryKeyFromProtocol (ConnectionHelper $connectionInstance) {
+ private function getRegistryKeyFromConnection (ConnectionHelper $connectionInstance) {
// Get the key
$key = $connectionInstance->getProtocolName();
* @param $connectionInstance An instance of a ConnectionHelper class
* @return $isRegistered Whether the protocol is registered
*/
- private function isProtocolRegistered (ConnectionHelper $connectionInstance) {
+ private function isConnectionRegistered (ConnectionHelper $connectionInstance) {
// Get the key
- $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+ $key = $this->getRegistryKeyFromConnection($connectionInstance);
// Determine it
$isRegistered = $this->instanceExists($key);
$isRegistered = FALSE;
// First, check for the instance, there can be only once
- if ($this->isProtocolRegistered($connectionInstance)) {
+ if ($this->isConnectionRegistered($connectionInstance)) {
// That one is found so "get" a registry key from it
- $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+ $key = $this->getRegistryKeyFromConnection($connectionInstance);
// Get the registry
$registryInstance = $this->getInstance($key);
} // END - if
// Does the instance exist?
- if (!$this->isProtocolRegistered($connectionInstance)) {
+ if (!$this->isConnectionRegistered($connectionInstance)) {
// No, not found so we create a sub registry (not needed to configure!)
$registryInstance = SubRegistry::createSubRegistry();
// Now we can create the sub-registry for this protocol
- $this->addInstance($this->getRegistryKeyFromProtocol($connectionInstance), $registryInstance);
+ $this->addInstance($this->getRegistryKeyFromConnection($connectionInstance), $registryInstance);
} else {
// Get the sub-registry back
- $registryInstance = $this->getInstance($this->getRegistryKeyFromProtocol($connectionInstance));
+ $registryInstance = $this->getInstance($this->getRegistryKeyFromConnection($connectionInstance));
}
// Get a key for sub-registries
} // END - if
// Now get the key from the protocol
- $key = $this->getRegistryKeyFromProtocol($connectionInstance);
+ $key = $this->getRegistryKeyFromConnection($connectionInstance);
// And get the registry
$registryInstance = $this->getInstance($key);
/**
* "Getter" to get a string respresentation for a key for the sub-registry
- * in this format: class:protocol:port
+ * in this format: class:type:port
*
- * @param $protocolInstance An instance of a ProtocolHandler class
+ * @param $connectionInstance An instance of a Listenable class
* @return $key A string representation of the socket for the registry
*/
- private function getSubRegistryKey (ProtocolHandler $protocolInstance) {
+ private function getSubRegistryKey (Listenable $connectionInstance) {
// Default address is invalid
$address = '*invalid*';
+ $port = 0;
// Which instance is it?
// @TODO Tested again base class, rewrite it to a generic interface!
- if ($protocolInstance instanceof BaseConnectionHelper) {
+ if ($connectionInstance instanceof BaseConnectionHelper) {
// Get address
- $address = $protocolInstance->getAddress();
- } elseif ($protocolInstance instanceof BaseListener) {
+ $address = $connectionInstance->getAddress();
+ $port = $connectionInstance->getConnectionPort();
+ } elseif ($connectionInstance instanceof BaseListener) {
// Get listen address
- $address = $protocolInstance->getListenAddress();
+ $address = $connectionInstance->getListenAddress();
+ $port = $connectionInstance->getListenPort();
} else {
// Not supported!
- $this->debugBackTrace('Unsupported protocolInstance=' . $protocolInstance->__toString() . ' detected. Please fix this!');
+ $this->debugBackTrace('Unsupported connectionInstance=' . $connectionInstance->__toString() . ' detected. Please fix this!');
}
- // Get protocol and port number and add both together
+ // Get connection type and port number and add both together
$key = sprintf('%s:%s:%s:%s',
- $protocolInstance->__toString(),
- $protocolInstance->getProtocolName(),
+ $connectionInstance->__toString(),
+ $connectionInstance->getConnectionType(),
$address,
- $protocolInstance->getPort()
+ $port
);
// Return resulting key
}
/**
- * "Getter" to get a string respresentation of the protocol
+ * "Getter" to get a string respresentation of the listener
*
- * @param $protocolInstance An instance of a ProtocolHandler class
- * @return $key A string representation of the protocol for the registry
+ * @param $listenerInstance An instance of a Listenable class
+ * @return $key A string representation of the listener for the registry
*/
- private function getRegistryKeyFromProtocol (ProtocolHandler $protocolInstance) {
+ private function getRegistryKeyFromListener (Listenable $listenerInstance) {
// Get the key
- $key = $protocolInstance->getProtocolName();
+ $key = $listenerInstance->getConnectionType();
// Return resulting key
return $key;
}
/**
- * Checks whether the given protocol is registered
+ * Checks whether the given listener is registered
*
- * @param $protocolInstance An instance of a ProtocolHandler class
- * @return $isRegistered Whether the protocol is registered
+ * @param $listenerInstance An instance of a Listenable class
+ * @return $isRegistered Whether the listener is registered
*/
- private function isProtocolRegistered (ProtocolHandler $protocolInstance) {
+ private function isListenerRegistered (Listenable $listenerInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!');
// Get the key
- $key = $this->getRegistryKeyFromProtocol($protocolInstance);
+ $key = $this->getRegistryKeyFromListener($listenerInstance);
// Determine it
$isRegistered = $this->instanceExists($key);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return result
return $isRegistered;
* Checks whether given socket resource is registered. If $socketResource is
* FALSE only the instance will be checked.
*
- * @param $protocolInstance An instance of a ProtocolHandler class
+ * @param $listenerInstance An instance of a Listenable class
* @param $socketResource A valid socket resource
* @return $isRegistered Whether the given socket resource is registered
*/
- public function isSocketRegistered (ProtocolHandler $protocolInstance, $socketResource) {
+ public function isSocketRegistered (Listenable $listenerInstance, $socketResource) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
// Default is not registered
$isRegistered = FALSE;
// First, check for the instance, there can be only once
- if ($this->isProtocolRegistered($protocolInstance)) {
+ if ($this->isListenerRegistered($listenerInstance)) {
// That one is found so "get" a registry key from it
- $key = $this->getRegistryKeyFromProtocol($protocolInstance);
+ $key = $this->getRegistryKeyFromListener($listenerInstance);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...');
// Get the registry
$registryInstance = $this->getInstance($key);
// "Get" a key for the socket
- $socketKey = $this->getSubRegistryKey($protocolInstance);
+ $socketKey = $this->getSubRegistryKey($listenerInstance);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...');
// Is it there?
if ($registryInstance->instanceExists($socketKey)) {
} // END - if
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return the result
return $isRegistered;
/**
* Registeres given socket for listener or throws an exception if it is already registered
*
- * @param $protocolInstance An instance of a ProtocolHandler class
+ * @param $listenerInstance An instance of a Listenable class
* @param $socketResource A valid socket resource
* @param $packageData Optional raw package data
* @throws SocketAlreadyRegisteredException If the given socket is already registered
* @return void
*/
- public function registerSocket (ProtocolHandler $protocolInstance, $socketResource, array $packageData = array()) {
+ public function registerSocket (Listenable $listenerInstance, $socketResource, array $packageData = array()) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!');
// Is the socket already registered?
- if ($this->isSocketRegistered($protocolInstance, $socketResource)) {
+ if ($this->isSocketRegistered($listenerInstance, $socketResource)) {
// Throw the exception
- throw new SocketAlreadyRegisteredException(array($protocolInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
+ throw new SocketAlreadyRegisteredException(array($listenerInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
} // END - if
// Does the instance exist?
- if (!$this->isProtocolRegistered($protocolInstance)) {
+ if (!$this->isListenerRegistered($listenerInstance)) {
// No, not found so we create a sub registry (not needed to configure!)
$registryInstance = SubRegistry::createSubRegistry();
- // Now we can create the sub-registry for this protocol
- $this->addInstance($this->getRegistryKeyFromProtocol($protocolInstance), $registryInstance);
+ // Now we can create the sub-registry for this listener
+ $this->addInstance($this->getRegistryKeyFromListener($listenerInstance), $registryInstance);
} else {
// Get the sub-registry back
- $registryInstance = $this->getInstance($this->getRegistryKeyFromProtocol($protocolInstance));
+ $registryInstance = $this->getInstance($this->getRegistryKeyFromListener($listenerInstance));
}
// Get a key for sub-registries
- $socketKey = $this->getSubRegistryKey($protocolInstance);
+ $socketKey = $this->getSubRegistryKey($listenerInstance);
// Get a socket container
- $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $protocolInstance, $packageData));
+ $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $listenerInstance, $packageData));
// We have a sub-registry, the socket key and the socket, now we need to put all together
/* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...');
/**
* Getter for given listener's socket resource
*
- * @param $protocolInstance An instance of a ProtocolHandler class
+ * @param $listenerInstance An instance of a Listenable class
* @return $socketResource A valid socket resource
* @throws NoSocketRegisteredException If the requested socket is not registered
*/
- public function getRegisteredSocketResource (ProtocolHandler $protocolInstance) {
+ public function getRegisteredSocketResource (Listenable $listenerInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!');
// The socket must be registered before we can return it
- if (!$this->isProtocolRegistered($protocolInstance)) {
+ if (!$this->isListenerRegistered($listenerInstance)) {
// Throw the exception
- throw new NoSocketRegisteredException ($protocolInstance, self::SOCKET_NOT_REGISTERED);
+ throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
} // END - if
- // Now get the key from the protocol
- $key = $this->getRegistryKeyFromProtocol($protocolInstance);
+ // Now get the key from the listener
+ $key = $this->getRegistryKeyFromListener($listenerInstance);
// And get the registry
$registryInstance = $this->getInstance($key);
// Get a socket key
- $socketKey = $this->getSubRegistryKey($protocolInstance);
+ $socketKey = $this->getSubRegistryKey($listenerInstance);
// And the final socket resource
$socketResource = $registryInstance->getInstance($socketKey)->getSocketResource();
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!');
// Return the resource
return $socketResource;
* "Getter" for protocol/connection instance from given package data
*
* @param $packageData Raw package data
- * @return $protocolInstance An instance of a ProtocolHandler class
+ * @return $protocolInstance An instance of a HandleableProtocol class
*/
public function getHandlerInstanceFromPackageData (array $packageData) {
// Init protocol instance
* @return $unl Universal node locator
*/
public function resolveUniversalNodeLocatorFromConfigKey ($configKey) {
+ // Get address
+ $address = $this->getConfigInstance()->getConfigEntry($configKey . '_address');
+
+ // Is the address empty?
+ if (empty($address)) {
+ // Okay, then find it
+ switch ($configKey) {
+ case 'external': // External IP
+ $address = ConsoleTools::determineExternalAddress();
+ break;
+
+ case 'internal': // Internal IP
+ $address = ConsoleTools::acquireSelfIPAddress();
+ break;
+ } // END - switch
+ } // END - if
+
// Put all together
$unl = sprintf('%s://%s:%s',
$this->getProtocolName(),
- $this->getConfigInstance()->getConfigEntry($configKey . '_address'),
+ $address,
$this->getConfigInstance()->getConfigEntry('node_listen_port')
);
* @return void
*/
private function extractTagsFromPackageData (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
+
/*
* We take a look at the tags (in most cases only one is needed) so
* first we need the content data splitted up into all it's parts.
* shared over the whole hub-network. So if the "tag" (let's better say
* object type) isn't found in that XML the package won't be distributed.
*
+ * @param $packageData Raw package data
* @return void
* @throws InvalidTagException If a provided tag from the package data is invalid
*/
- private function verifyAllTags () {
+ private function verifyAllTags (array $packageData) {
// Get the registry
$objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
} // END - if
// Now save the last discovered protocol/recipient type
- $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromArray($entry);
+ $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
$this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
} // END - foreach
}
* Chooses the right protocol from given package data
*
* @param $packageData Raw package data
- * @return $lastProtocol An instance of the last used ProtocolHandler class
+ * @return $lastProtocol An instance of the last used HandleableProtocol class
*/
public function chooseProtocolFromPackageData (array $packageData) {
// Extract the tags
$this->extractTagsFromPackageData($packageData);
// Now we need to verify every single tag
- $this->verifyAllTags();
+ $this->verifyAllTags($packageData);
// Return the last (and only) found protocol (e.g. 'tcp' is very usual)
return $this->lastProtocol;
$this->extractTagsFromPackageData($packageData);
// Now we need to verify every single tag
- $this->verifyAllTags();
+ $this->verifyAllTags($packageData);
// Now simply check it out
$accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));
}
/**
- * Handles the template dependency for given node
+ * Handles the template dependency for given XML node
*
- * @param $node The node we should load a dependency template
+ * @param $node The XML node we should load a dependency template
* @param $templateDependency A template to load to satisfy dependencies
* @return void
*/
protected function handleTemplateDependency ($node, $templateDependency) {
- // Check that node is not empty
+ // Check that the XML node is not empty
assert(!empty($node));
// Is the template dependency set?
*/
protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
// Init variable
- die(__METHOD__ . ': Unfinished' . PHP_EOL);
+ die(__METHOD__ . ': UNFINISHED: sessionId=' . $sessionId . PHP_EOL);
$recipientUniversalNodeLocator = 'invalid://invalid:invalid';
// And ask it for Universal Node Locator by given session id
}
/**
- * Determine IP or 'external_address' if set
+ * Determine UNL or 'external_address' if set
*
- * @return $ip The determined external address of this node
+ * @return $unl The determined external UNL of this node
*/
public static function determineOwnExternalAddress () {
// Is the external_address config entry set?
if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address') != '') {
// Use it as external address
- $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address');
+ $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address');
} else {
// Determine own external address by connecting to my (coder) server at 188.138.90.169
- $ip = ConsoleTools::determineExternalAddress();
+ $unl = self::determineExternalUniversalNodeLocator();
}
// Return it
- return $ip;
+ return $unl;
}
/**
- * Determine IP or 'internal_address' if set
+ * Determine UNL or 'internal_address' if set
*
- * @return $ip The determined external address of this node
+ * @return $unl The determined internal UNL of this node
*/
public static function determineOwnInternalAddress () {
// Is the internal_address config entry set?
if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
// Not allowed to publish internal address, so use external
- $ip = self::determineOwnExternalAddress();
+ $unl = self::determineOwnExternalAddress();
} elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address') != '') {
// Use it as internal address
- $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address');
+ $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address');
} else {
// Determine own internal address by connecting to my (coder) server at 188.138.90.169
- $ip = ConsoleTools::acquireSelfIPAddress();
+ $unl = self::determineInternalUniversalNodeLocator();
}
// Return it
- return $ip;
+ return $unl;
+ }
+
+ /**
+ * Determines the UNL (Universal Node Locator) for the internal address
+ *
+ * @return $internalUnl Internal UNL
+ */
+ public static function determineInternalUniversalNodeLocator () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is there cache? (This shortens a lot calls)
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 2) "Determine" it
+ $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal');
+
+ // Make sure it is valid
+ // @TODO Find a better validation than empty()
+ assert(!empty($GLOBALS[__METHOD__]));
+ } // END - if
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+ return $GLOBALS[__METHOD__];
+ }
+
+ /**
+ * Determines the UNL (Universal Node Locator) for the external address
+ *
+ * @return $externalUnl External UNL
+ */
+ public static function determineExternalUniversalNodeLocator () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is there cache? (This shortens a lot calls)
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
+
+ // 2) "Determine" it
+ $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external');
+
+ // Make sure it is valid
+ // @TODO Find a better validation than empty()
+ assert(!empty($GLOBALS[__METHOD__]));
+ } // END - if
+
+ // Return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!');
+ return $GLOBALS[__METHOD__];
}
}
* @return $searchInstance An instance of a SearchCriteria class
*/
private function prepareSearchInstance (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
// Assert on array elements
assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
$searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
$searchInstance->setLimit(1);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
// Return it
return $searchInstance;
}
* @return $dataSetInstance An instance of a StoreableCriteria class
*/
private function prepareLocalDataSetInstance () {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Get node/request instances
$nodeInstance = NodeObjectFactory::createNodeInstance();
// Get Universal Node Locator and "explode" it
$unlInstance = $nodeInstance->determineUniversalNodeLocator();
+ // Get UNL data from it
+ $unlData = $unlInstance->getUnlData();
+
// Make sure both is valid
- assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
+ // @TODO Bad check on UNL, better use a proper validator
+ assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
+ assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] !== 'invalid');
// Get an array of all accepted object types
$objectList = $nodeInstance->getListFromAcceptedObjectTypes();
// 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_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
$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());
$dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
$dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap()));
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
// Return it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
return $dataSetInstance;
}
* @return $isRegistered Whether *this* node is registered in the DHT
*/
public function isLocalNodeRegistered () {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Get a search criteria instance
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Get Universal Node Locator and "explode" it
$unlData = $nodeInstance->getUniversalNodeLocatorArray();
- /*
- * Make sure both is not 'invalid' which means that the resolver
- * didn't work.
- */
- die(__METHOD__ . ':unlData[' . gettype($unlData) . ']=' . print_r($unlData, TRUE) . PHP_EOL);
+ // Make sure the external address is set and not invalid
+ // @TODO Bad check on UNL, better use a proper validator
+ assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
+ assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] != 'invalid');
// Add Universal Node Locator/node id as criteria
- $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]);
+ $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
$searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
$searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$searchInstance->setLimit(1);
// Cache result of if there is an entry, valid() will tell us if an entry is there
$isRegistered = $resultInstance->valid();
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return result
return $isRegistered;
* @return void
*/
public function registerLocalNode () {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Assert to make sure this method is called with no record in DB (the actual backend of the DHT)
assert(!$this->isLocalNodeRegistered());
// "Insert" this dataset instance completely into the database
$this->queryInsertDataSet($dataSetInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @return void
*/
public function updateLocalNode () {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Assert to make sure this method is called with one record in DB (the actual backend of the DHT)
assert($this->isLocalNodeRegistered());
// Update DHT database record
$this->queryUpdateDataSet($dataSetInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @return $nodeData Node data array
*/
public function findNodeLocalBySessionId ($sessionId) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!');
// Get search criteria
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
// Query database and get a result instance back
$resultInstance = $this->doSelectByCriteria($searchInstance);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
+
// Return result instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
return $resultInstance;
}
* @return void
*/
public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!');
// Get a data set instance
$dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
// Run the "INSERT" query
$this->queryInsertDataSet($dataSetInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!');
}
/**
* @return void
*/
public function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Get a data set instance
$dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT));
// Run the "UPDATE" query
$this->queryUpdateDataSet($dataSetInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @return $isRegistered Whether the given node data is already inserted
*/
public function isNodeRegistered (array $nodeData) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Assert on array elements
assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]);
// Get search criteria
$searchInstance = $this->prepareSearchInstance($nodeData);
// Check if there is an entry
$isRegistered = $resultInstance->valid();
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!');
// Return registration status
return $isRegistered;
* @throws NodeAlreadyRegisteredException If the node is already registered
*/
public function registerNode (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
// Assert on array elements
assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
// @TODO Unimplemented part
$this->partialStub('nodeData=' . print_r($nodeData, TRUE));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @throws NodeDataMissingException If the node's data is missing
*/
public function updateNode (array $nodeData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
// Assert on array elements
assert(isset($nodeData[self::DB_COLUMN_NODE_ID]));
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...');
// Is the node registered?
if (!$this->isNodeRegistered($nodeData)) {
$nodeInstance = NodeObjectFactory::createNodeInstance();
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE));
// Add all array elements
$nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData);
// Run the "UPDATE" query
$this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
// Check pending entries
$hasUnpublished = $this->unpublishedEntriesInstance->valid();
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
// Return it
return $hasUnpublished;
}
* @todo Add timestamp to dataset instance
*/
public function initEntryPublication () {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
/*
* Make sure that hasUnpublishedEntries() has been called first by
* asserting on the "cached" object instance. This "caching" saves some
// Run the "UPDATE" query
$this->queryUpdateDataSet($dataSetInstance);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
}
/**
* @return $recipients An indexed array with DHT recipients
*/
public function getResultFromExcludedSender (array $packageData) {
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
// Assert on required array field
assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
// Get a result instance back from DHT database wrapper.
$resultInstance = $this->doSelectByCriteria($searchInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
// Return result instance
return $resultInstance;
* @return $recipients An indexed array with DHT recipients
*/
public function getResultFromKeyValue ($key, $value) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
// Get max recipients
$maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients');
// Get a result instance back from DHT database wrapper.
$resultInstance = $this->doSelectByCriteria($searchInstance);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
+
// Return result instance
return $resultInstance;
}
<object-recipient-limitation>all</object-recipient-limitation>
<object-max-spread>3</object-max-spread>
<object-protocol>unl</object-protocol>
- <object-recipient-type>all</object-recipient-type>
+ <object-recipient-type>hub</object-recipient-type>
</object-list-entry>
<object-list-entry>
<object-name>dht_bootstrap_answer</object-name>
-Subproject commit 7bb55d2b90d5a32710bc0bb220cff5720194a6eb
+Subproject commit 0a30519f2e39747163dd4db464c6c0ca98abdb23