$recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance(), $packageData);
} catch (FrameworkException $e) {
// Could not find class, what ever failed
- $this->debugInstance($e->getMessage());
+ $this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage()));
}
}
}
use Hub\Network\Package\NetworkPackage;
// Import framework stuff
+use CoreFramework\Generic\NullPointerException;
use CoreFramework\Registry\Registerable;
use CoreFramework\Registry\Registry;
use CoreFramework\Socket\InvalidSocketException;
// Determine protocol instance
$protocolInstance = ProtocolDiscovery::determineProtocolByPackageData($packageData);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
+
// Is it valid?
assert($protocolInstance instanceof HandleableProtocol);
// Get the listener instance
$listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('listenerInstance=' . $listenerInstance . ',packageData=' . print_r($packageData, TRUE));
+
// If there is no listener who wants to have that package, we simply drop it here
if (is_null($listenerInstance)) {
// Abort with no resource
throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
} // END - if
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
-
/*
* Now we have the listener instance, we can determine the right
* resource to continue. The first step is to get the attached pool
$socketInstance = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData, $connectionType);
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: socketInstance[]=%s', gettype($socketInstance)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-DISCOVERY: socketInstance[]=%s', gettype($socketInstance)));
// Is it FALSE, the recipient isn't known to us and we have no connection to it
- if (($socketInstance instanceof StorableSocket) || (!$socketInstance->isValidSocket()) || ($socketInstance->getLastSocketErrorCode() > 0)) {
+ if (!($socketInstance instanceof StorableSocket) || ($socketInstance->isValidSocket()) || ($socketInstance->getLastSocketErrorCode() > 0)) {
// Try to create a new socket resource
try {
// Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
// Get a socket resource from our factory (if succeeded)
$socketInstance = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance);
// Return the instance
return $%%%Instance;
}
-}
-// [EOF]
-?>
+}
// Return the instance
return $discoveryInstance;
}
-}
-// [EOF]
-?>
+}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Factory\Network\Locator;
+
+// Import framework stuff
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Registry\Registry;
+
+/**
+ * A factory class for LocateableNode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 UniversalNodeLocatorFactory extends ObjectFactory {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Returns a singleton (registry-based) LocateableNode instance
+ *
+ * @param $unl UNL address
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public static final function createUnlInstanceFromString ($unl) {
+ // If there is no handler?
+ if (Registry::getRegistry()->instanceExists('unl_' . $unl)) {
+ // Get handler from registry
+ $unlInstance = Registry::getRegistry()->getInstance('unl_' . $unl);
+ } else {
+ // Get the handler instance
+ $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class');
+
+ // Parse UNL string
+ $unlInstance->parseStringAsUnl($unl);
+
+ // Add it to the registry
+ Registry::getRegistry()->addInstance('unl_' . $unl, $unlInstance);
+ }
+
+ // Return the instance
+ return $unlInstance;
+ }
+
+ /**
+ * Creates a UNL instance from given array
+ *
+ * @param $unlData Array with valid UNL data
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public static final function createUnlInstanceFromArray (array $unlData) {
+ // No "caching" for now
+ $unlInstance = self::createObjectByConfiguredName('universal_node_locator_class', array($unlData));
+
+ // Return it
+ return $unlInstance;
+ }
+
+}
// Now output the teaser
$proxyInstance->outputConsoleTeaser();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$proxyInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$chatInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$crawlerInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$cruncherInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$minerInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
// Do some extra bootstrapping steps
$nodeInstance->doBootstrapping();
}
-}
-// [EOF]
-?>
+}
*/
$nodeInstance->bootstrapAcquireNodeId($requestInstance, $responseInstance);
}
-}
-// [EOF]
-?>
+}
*/
$nodeInstance->bootstrapGenerateSessionId();
}
-}
-// [EOF]
-?>
+}
// Now do something
$nodeInstance->initializeListenerPool();
}
-}
-// [EOF]
-?>
+}
// Now output the teaser
$chatInstance->outputConsoleTeaser();
}
-}
-// [EOF]
-?>
+}
// Now do something
$this->partialStub('Please implement this step.');
}
-}
-// [EOF]
-?>
+}
// Now output the teaser
$crawlerInstance->outputConsoleTeaser();
}
-}
-// [EOF]
-?>
+}
$this->debugBackTrace(': cruncher mode ' . $cruncherMode . ' is invalid.');
}
}
-}
-// [EOF]
-?>
+}
// Now output the teaser
$cruncherInstance->outputConsoleTeaser();
}
-}
-// [EOF]
-?>
+}
$this->debugBackTrace(': miner mode ' . $minerMode . ' is invalid.');
}
}
-}
-// [EOF]
-?>
+}
// Debug message
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-INIT-FILTER: Node ' . $nodeMode . ' has been added to registry.');
}
-}
-// [EOF]
-?>
+}
// Now output the teaser
$nodeInstance->outputConsoleTeaser();
}
-}
-// [EOF]
-?>
+}
// Shutdown the apt-proxy. This should be the last line
$proxyInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Shutdown the chat. This should be the last line
$chatInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Shutdown the crawler. This should be the last line
$crawlerInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Shutdown the cruncher. This should be the last line
$cruncherInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Shutdown the miner. This should be the last line
$minerInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Now do something
$this->partialStub('Please implement this step.');
}
-}
-// [EOF]
-?>
+}
// Now do something
$this->partialStub('Please implement this step.');
}
-}
-// [EOF]
-?>
+}
// Shutdown the node. This should be the last line
$nodeInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Shutdown the task manager and all its registered tasks
$handlerInstance->doShutdown();
}
-}
-// [EOF]
-?>
+}
// Is the last exception not NULL?
if ($this->getLastException() instanceof FrameworkException) {
// "Determine" the right status code (may differ from exception to exception)
- $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
+ $this->debugInstance(sprintf('[%s:%d]: lastException=%s,message=%s is unfinished.', __METHOD__, __LINE__, $this->getLastException()->__toString(), $this->getLastException()->getMessage()));
} // END - if
// Return the status code
} else {
// Something really horrible happened
// @TODO Throw an exception here instead of dying
- $this->debugInstance(__METHOD__ . ': ids mismatching! messageData=' . print_r($messageData, TRUE));
+ $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE)));
}
}
return $isValid;
}
- /**
- * Parses the given UNL by splitting it up in its components. The UNL ...
- *
- * protocol://address[:port]
- *
- * ... becomes:
- *
- * array(
- * 'protocol' => 'value',
- * 'address' => 'value',
- * 'extra' => 'port'
- * )
- *
- * The value for 'extra' then must be handled by the overwriting
- * parseUniversalNodeLocator() method of the individual protocol handler as
- * this is protocol-specific.
- *
- * @param $unl Universal Node Locator (UNL) to "parse"
- * @return $unlInstance An instance of a LocateableNode class
- */
- protected function parseUniversalNodeLocator ($unl) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!');
-
- // Make sure the UNL is valid
- assert($this->isValidUniversalNodeLocator($unl));
-
- /*
- * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
- * @TODO If you know why, please fix and explain it to me.
- */
- $unlParts = explode('://', $unl);
-
- // Split again the last part as: address:port
- $unlParts[1] = explode(':', $unlParts[1]);
-
- // Now there is an almost useable array which then can be copied to the "real" array.
- $unlData = array(
- LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
- LocateableNode::UNL_PART_ADDRESS => $unlParts[1][0],
- LocateableNode::UNL_PART_EXTRA => $unlParts[1][1]
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
-
- // Create instance from it
- //$unlInstance = ;
- $this->partialStub('Please rewrite this part.');
-
- // Return instance
- return $unlInstance;
- }
-
- /**
- * Gets an element from universalNodeLocatorData array
- *
- * @param $element Element in universalNodeLocatorData array
- * @return $value Found value
- */
- protected final function getUniversalNodeLocatorDataElement ($element) {
- // Is the element there?
- assert(isset($this->universalNodeLocatorData[$element]));
-
- // Return it
- return $this->universalNodeLocatorData[$element];
- }
-
/**
* Getter for protocol name
*
* @return $address Address part for the final UNL
*/
public function getAddressPart () {
- // Return it
- return $this->getUniversalNodeLocatorDataElement(LocateableNode::UNL_PART_ADDRESS);
+ // Get UNL instance
+ $unlInstance = $this->getUniversalNodeLocatorInstance();
+ die(__METHOD__.':'.print_r($unlInstance, TRUE));
}
/**
namespace Hub\Handler\Protocol\Network\IpV4;
// Import application-specific stuff
+use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
use Hub\Handler\Protocol\BaseProtocolHandler;
use Hub\Locator\Node\LocateableNode;
use Hub\Network\Package\NetworkPackage;
<?php
// Own namespace
-namespace Hub\Helper\Connection\IpV4;
+namespace Hub\Helper\Connection\Network\IpV4;
// Import application-specific stuff
use Hub\Helper\Connection\BaseConnectionHelper;
<?php
// Own namespace
-namespace Hub\Helper\Connection\Tcp;
+namespace Hub\Helper\Connection\Network\IpV4\Tcp;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
use Hub\Factory\Socket\SocketFactory;
use Hub\Helper\Connection\ConnectionHelper;
+use Hub\Helper\Connection\Network\IpV4\BaseIpV4ConnectionHelper;
use Hub\Locator\Node\LocateableNode;
use Hub\Network\Package\NetworkPackage;
use Hub\Tools\HubTools;
// @TODO Rewrite this test for UNLs
if (strpos($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], ':') === FALSE) {
// No ip:port!
- $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.');
+ $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
} // END - if
// "explode" the ip:port, so index 1 will be the port number
//$unlInstance =;
} else {
// It doesn't match, we need to take care of this later
- $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . '!=' . $helperInstance->getConfigInstance()->getConfigEntry('external_address'));
+ $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s!=%s', __METHOD__, __LINE__, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $helperInstance->getConfigInstance()->getConfigEntry('external_address')));
}
}
<?php
// Own namespace
-namespace Hub\Helper\Connection\Udp;
+namespace Hub\Helper\Connection\Network\IpV4\Udp;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Helper\Connection\ConnectionHelper;
+use Hub\Helper\Connection\Network\IpV4\BaseIpV4ConnectionHelper;
/**
* A UDP connection helper class
* @return $iteratorInstance An instance of a Iterator class
*/
public function getListIterator () {
- $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
+ $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__));
}
/**
* @return $iteratorInstance An instance of a Iterator class
*/
public function getListIterator () {
- $this->debugInstance($this->__toString() . ' uses the default iterator. Please call getIterator() instead!');
+ $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__));
}
/**
use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
use Hub\Generic\BaseHubSystem;
+// Import framework stuff
+use CoreFramework\Registry\Registerable;
+
// Import SPL stuff
use \BadMethodCallException;
+use \InvalidArgumentException;
/**
* A class for UNLs (Universal Node Locator)
* 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 BaseHubSystem implements LocateableNode {
+class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Registerable {
/**
* UNL data array
*/
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set regex for UNL-validation
+ $this->setRegularExpression(LocateableNode::UNL_REGEX);
}
/**
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
- */
- private function getUnlData () {
- return $this->unlData;
- }
-
/**
* Getter for external UNL
*
return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
}
+ /**
+ * Some "getter" for UNL port (if supported). If not supported, NULL is
+ * being returned.
+ *
+ * @return $unlPort Port number of UNL
+ */
+ public function getUnlPort () {
+ // Get UNL data
+ $unlData = $this->getUnlData();
+
+ // Default value is NULL
+ $unlPort = NULL;
+
+ // Is the element there?
+ if (isset($unlData[LocateableNode::UNL_PART_EXTRA])) {
+ // Use it
+ $unlPort = $unlData[LocateableNode::UNL_PART_EXTRA];
+ } // END - if
+
+ // Return it
+ return $unlPort;
+ }
+
+ /**
+ * Parses given UNL string as UNL array
+ *
+ * @param $unl UNL string
+ * @return void
+ */
+ public function parseStringAsUnl ($unl) {
+ // Is it basically valid?
+ if (!is_string($unl)) {
+ // Abort here
+ throw new InvalidArgumentException(sprintf('unl[]=%s is not string.', gettype($unl)));
+ } // END - if
+
+ // Parse it
+ $this->parseUniversalNodeLocator($unl);
+ }
+
+ /**
+ * Parses the given UNL by splitting it up in its components. The UNL ...
+ *
+ * protocol://address[:port]
+ *
+ * ... becomes:
+ *
+ * array(
+ * 'protocol' => 'value',
+ * 'address' => 'value',
+ * 'extra' => 'port'
+ * )
+ *
+ * The value for 'extra' then must be handled by the overwriting
+ * parseUniversalNodeLocator() method of the individual protocol handler as
+ * this is protocol-specific.
+ *
+ * @param $unl Universal Node Locator (UNL) to "parse"
+ * @throws InvalidArgumentException If given UNL is not valid
+ */
+ private function parseUniversalNodeLocator ($unl) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ' - CALLED!');
+
+ // Make sure the UNL is valid
+ if (!$this->isValidUniversalNodeLocator($unl)) {
+ // UNL is not valid
+ throw new InvalidArgumentException(sprintf('unl[%s]=%s is not valid.', gettype($unl), $unl));
+ } // END - if
+
+ /*
+ * "Parse" the UNL "generically", sadly this cannot be done by using preg_match() :-(
+ * @TODO If you know why, please fix and explain it to me.
+ */
+ $unlParts = explode('://', $unl);
+
+ // Split again the last part as: address:port
+ $unlParts[1] = explode(':', $unlParts[1]);
+
+ // Now there is an almost useable array which then can be copied to the "real" array.
+ $unlData = array(
+ LocateableNode::UNL_PART_PROTOCOL => $unlParts[0],
+ LocateableNode::UNL_PART_ADDRESS => $unlParts[1][0],
+ LocateableNode::UNL_PART_EXTRA => $unlParts[1][1],
+ );
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unlData=' . print_r($unlData, TRUE) . ' - EXIT!');
+
+ // Call init method
+ $this->initUniversalNodeLocator($unlData);
+ }
+
+ /**
+ * Initializes the UNL instance by givena array. If an entry is found, it
+ * will be copied, otherwise the entry is set empty.
+ *
+ * @param $unlData An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return void
+ */
+ private function initUniversalNodeLocator (array $unlData = array()) {
+ // Init UNL array
+ $this->unlData = array();
+
+ // Copy all found entries
+ foreach (array(
+ LocateableNode::UNL_PART_PROTOCOL,
+ LocateableNode::UNL_PART_ADDRESS,
+ LocateableNode::UNL_PART_EXTRA,
+ 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($unlData[$key])) {
+ // The copy the entry
+ $this->unlData[$key] = $unlData[$key];
+ } // END - if
+ } // END - foreach
+ }
+
+ /**
+ * Getter for UNL data array
+ *
+ * @return $unlData An array with UNL data
+ */
+ private function getUnlData () {
+ return $this->unlData;
+ }
+
+ /**
+ * Validates given UNL very basicly by given regular expression. You
+ * normally don't need/want to overwrite this method as this is a very basic
+ * validation only based on a regex.
+ *
+ * @param $unl Universal Node Locator to validate
+ * @return $isValid Whether the UNL is valid
+ */
+ private final function isValidUniversalNodeLocator ($unl) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': unl=' . $unl . ',regex=' . $regex . ' - CALLED!');
+
+ // Very basic regex check
+ $isValid = (preg_match($this->getRegularExpression(), $unl) === 1);
+
+ // Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
+
}
* @param $list The list identifier we should return
* @return $array The requested array
*/
- protected final function getArrayFromList ($list) {
+ public final function getArrayFromList ($list) {
// Get the array
$array = $this->getPoolEntriesInstance()->getArrayFromList($list);
// Import framework stuff
use CoreFramework\Socket\InvalidSocketException;
+// Import SPL stuff
+use \LogicException;
+
/**
* A default peer pool class
*
* @param $connectionType Type of connection, can be 'incoming', 'outgoing', 'server' or default
* @return $socketInstance An instance of a StorableSocket class
* @throws InvalidConnectionTypeException If the provided connection type is not valid
+ * @throws LogicException If an expected array element is missing
*/
public function getSocketFromPackageData (array $packageData, $connectionType = NULL) {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType));
+
// Default is no socket
$socketInstance = NULL;
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
// Get UNL data
- $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
-
- // Make sure it is a valid Universal Node Locator array (3 elements)
- assert(isset($unlData[LocateableNode::UNL_PART_PROTOCOL]));
- assert(isset($unlData[LocateableNode::UNL_PART_ADDRESS]));
- assert(isset($unlData[LocateableNode::UNL_PART_PORT]));
+ $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . LocateableNode::UNL_PART_ADDRESS . ']=' . $unlData[LocateableNode::UNL_PART_ADDRESS] . ',unlData[' . LocateableNode::UNL_PART_PORT . ']=' . $unlData[LocateableNode::UNL_PART_PORT] . ' ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Checking ' . count($this->getAllSockets()) . ' socket(s),unlInstance.unl=' . $unlInstance->generateUnl() . ' ...');
// Default is all sockets
$sockets = $this->getAllSockets();
- // Is connection type set?
- if ((is_string($connectionType)) && ($this->isValidConnectionType($connectionType))) {
- // Then get a list of this type
- $sockets = $this->getSocketsByConnectionType($connectionType);
- } elseif (is_string($connectionType)) {
- // Is not a valid connection type!
- throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
- }
-
// Get all sockets and check them, skip the server socket
foreach ($sockets as $socketArray) {
- // Is this a server socket?
- if ($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->equals($this->getListenerInstance()->getSocketInstance())) {
- // Skip 'server' sockets (local socket)
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: Skipping server socket ' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource() . ' ...');
+ // Debugging:
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketArray(%d)=%s', count($socketArray), implode(',', $socketArray)));
+ //* DEBUG-DIE: */ die(__METHOD__.':connectionType='.$connectionType.',socketArray='.print_r($socketArray, TRUE));
+
+ // Is connection type set?
+ if (!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) {
+ // Important array element missing
+ throw new LogicException(sprintf('socketArray[%s] is not set.', Poolable::SOCKET_ARRAY_INSTANCE));
+ } elseif (!isset($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE])) {
+ // Important array element missing
+ throw new LogicException(sprintf('socketArray[%s] is not set.', Poolable::SOCKET_ARRAY_CONN_TYPE));
+ } elseif ((!empty($connectionType)) && (!$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->isValidConnectionType($connectionType))) {
+ // Is not a valid connection type!
+ throw new InvalidConnectionTypeException(array($this, $connectionType), self::EXCEPTION_INVALID_CONNECTION_TYPE);
+ } elseif ((!empty($connectionType)) && ($socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] !== $connectionType)) {
+ // Skip unwanted sockets
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: Skipping unwanted socket %s of type %s/%s ...', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE], $connectionType));
continue;
- } // END - if
+ }
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: socketInstance.socketResource=%s,socketInstance.socketProtocol=%s,socketArray[%s]=%s', $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketProtocol(), Poolable::SOCKET_ARRAY_CONN_TYPE, $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
// Init peer address/port
$peerAddress = '0.0.0.0';
$socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->handleSocketError(__METHOD__, __LINE__, explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
} // END - if
- // Get
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s,peerPort=%d,unlInstance.addressPart=%s', $peerAddress, $peerPort, $unlInstance->getAddressPart()));
+
// If the "peer" IP and recipient is same, use it
- if ($peerAddress == $unlData[LocateableNode::UNL_PART_ADDRESS]) {
+ if ($peerAddress == $unlInstance->getAddressPart()) {
// IPs match, so take the socket and quit this loop
$socketInstance = $socketArray[Poolable::SOCKET_ARRAY_INSTANCE];
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('POOL: peerAddress=' . $peerAddress . ' matches with recipient IP address. Taking socket=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('POOL: peerAddress=%s matches with recipient IP address. Taking socketResource=%s,type=%s', $peerAddress, $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]->getSocketResource(), $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE]));
break;
} // END - if
} // END - foreach
if ($wrapperInstance->isTestUnitProduced()) {
// Entries found
// @TODO Unfinished work here
- $this->debugInstance();
+ $this->debugInstance(sprintf('[%s:%d]: stateInstance=%s - Unfinished!', __METHOD__, __LINE__, $stateInstance->__toString()));
// The state must be changed because ...
$stateInstance->someFooStateChange();
$infoInstance->fillWithConnectionHelperInformation($helperInstance);
} else {
// Not supported state!
- $this->debugInstance(': Invalid state found, please report this to the developers with full debug infos.' . PHP_EOL);
+ $this->debugInstance(sprintf('[%s:%d]: Invalid state found, please report this to the developers with full debug infos.', __METHOD__, __LINE__));
}
// Debug message
// Import application-specific stuff
use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
+use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
use Hub\Helper\Node\NodeHelper;
use Hub\Resolver\Protocol\BaseProtocolResolver;
use Hub\Resolver\Protocol\ProtocolResolver;
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));
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromArray($current);
// Return resolved instance
return $unlInstance;
// Import framework stuff
use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\NullPointerException;
use CoreFramework\Registry\Registerable;
/**
// Is this null?
if (is_null($value)) {
// Bah, needs fixing.
- $this->debugInstance('key=' . $key . ' returns NULL');
+ $this->debugInstance(sprintf('[%s:%d]: key=%s returns NULL', __METHOD__, __LINE__, $key));
} // END - if
// Return value
$cfg->setConfigEntry('package_tags_class', 'Hub\Tag\Package\PackageTags');
// CFG: TCP-CONNECTION-HELPER-CLASS
-$cfg->setConfigEntry('tcp_connection_helper_class', 'TcpConnectionHelper');
+$cfg->setConfigEntry('tcp_connection_helper_class', 'Hub\Helper\Connection\Network\IpV4\Tcp\TcpConnectionHelper');
// CFG: UDP-CONNECTION-HELPER-CLASS
-$cfg->setConfigEntry('udp_connection_helper_class', 'UdpConnectionHelper');
+$cfg->setConfigEntry('udp_connection_helper_class', 'Hub\Helper\Connection\Network\IpV4\Udp\UdpConnectionHelper');
// CFG: HUB-COMMUNICATION-PROTOCOL-TYPE
$cfg->setConfigEntry('hub_communication_protocol_type', 'tcp');
*
* @return $result Whether the peer has been identified
*/
- function identifySocketPeer();
+ function identifySocketPeer ();
/**
* Tries to set socket timeout option
*
* @return $result Whether the option has been set
*/
- function setSocketTimeoutOptions();
+ function setSocketTimeoutOptions ();
/**
* Tries to enable out-of-band (OOB) data
*
* @return $result Whether OOB has been enabled
*/
- function enableSocketOutOfBandData();
+ function enableSocketOutOfBandData ();
/**
* Getter for socket procotol field
*/
function getInternalUnl ();
+ /**
+ * Some "getter" for UNL port (if supported). If not supported, NULL is
+ * being returned.
+ *
+ * @return $unlPort Port number of UNL
+ */
+ function getUnlPort ();
+
+ /**
+ * Parses given UNL string as UNL array
+ *
+ * @param $unl UNL string
+ * @return void
+ */
+ function parseStringAsUnl ($unl);
+
}
const SOCKET_ARRAY_INSTANCE = 'instance';
const SOCKET_ARRAY_CONN_TYPE = 'connection_type';
+ /**
+ * Gets the array from specified list
+ *
+ * @param $list The list identifier we should return
+ * @return $array The requested array
+ */
+ function getArrayFromList ($list);
+
/**
* Getter for pool entries instance
*
* @param $socketInstance An instance of a StorableSocket class
* @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
* @return void
- * @throws InvalidSocketException If the given resource is invalid or errorous
* @throws InvalidConnectionTypeException If the provided connection type is not valid
*/
function addPeer (StorableSocket $socketInstance, $connectionType);
/**
- * Getter for array of all socket resource arrays
+ * Getter for array of all socket resources
*
- * @return $sockets An array with all socket arrays
+ * @return $sockets An array with all sockets
*/
function getAllSockets ();
/**
- * Getter for array of all socket resources
+ * Getter for array of all socket arrays
*
- * @return $sockets An array with all sockets
+ * @return $sockets An array with all socket arrays
*/
function getAllSingleSockets ();
*
* @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
* @return $sockets An array with sockets of given type
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
+ * @throws InvalidConnectionTypeException If the found connection type is not valid
*/
function getSocketsByConnectionType ($connectionType);
-Subproject commit ba6776b5d9b04fd6916224c088cabf255643c6d7
+Subproject commit fd5598626e163040b19bf8e153d4898a49038b23
$templateInstance = NULL;
// Get response instance
- $responseInstance = ApplicationHelper::getSelfInstance()->getResponseInstance();
+ $responseInstance = FrameworkBootstrap::getResponseInstance();
// Is the template engine loaded?
if ((class_exists($tpl)) && (is_object($languageInstance))) {