--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown when a protocol handler cannot validate given package data's recipient (UNL).
+ *
+ * @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 InvalidUnlException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (array $messageArray, $code) {
+ // Construct the message
+ $message = sprintf('[%s:%d] The protocol handler %s cannot validate recipient %s.',
+ $messageArray[0]->__toString(),
+ $this->getLine(),
+ $messageArray[1]->__toString(),
+ $messageArray[2][NetworkPackage::PACKAGE_DATA_RECIPIENT]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
$message = sprintf('[%s:%d] Node already registered: session-id=%s, external-address=%s',
$messageArray[0]->__toString(),
$this->getLine(),
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
+ $messageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
+ $messageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
);
// Call parent exception constructor
$message = sprintf('[%s:%d] Node not registered/missing: session-id=%s, external-address=%s',
$messageArray[0]->__toString(),
$this->getLine(),
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
- $msssageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
+ $messageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_SESSION_ID],
+ $messageArray[1][NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS]
);
// Call parent exception constructor
const EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED = 0x908;
const EXCEPTION_MULTIPLE_MESSAGE_SENT = 0x909;
const EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED = 0x90a;
+ const EXCEPTION_INVALID_UNL = 0x90b;
// Message status codes
const MESSAGE_STATUS_CODE_OKAY = 'OKAY';
* @return $socketResource A valid socket resource or FALSE if an error occured
* @throws NoListGroupException If the procol group is not found in peer list
* @throws NullPointerException If listenerInstance is NULL
+ * @throws InvalidUnlException If the provided UNL cannot be validated by the protocol handler
*/
public function discoverSocket (array $packageData, $connectionType) {
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!');
- // Assert on type
+ // Assert on type and recipient
assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER);
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
- // Determine protocol name
- $protocolName = $this->determineProtocolByPackageData($packageData);
+ // Determine protocol instance
+ $protocolInstance = $this->determineProtocolByPackageData($packageData);
- // Is it the same?
- assert(strtoupper($protocolName) == $packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]);
+ // Is it valid?
+ assert($protocolInstance instanceof HandleableProtocol);
+
+ // Does the UNL validate?
+ if (!$protocolInstance->isValidUniversalNodeLocatorByPackageData($packageData)) {
+ // Not valid, throw exception
+ throw new InvalidUnlException(array($this, $protocolInstance, $packageData), BaseHubSystem::EXCEPTION_INVALID_UNL);
+ } // END - if
+ die(__METHOD__ . ':protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
// Get the listener instance
- $listenerInstance = $this->discoverListenerInstance($protocolName, $packageData);
+ $listenerInstance = $this->discoverListenerInstance($protocolInstance, $packageData);
// If there is no listener who wants to have that package, we simply drop it here
if (is_null($listenerInstance)) {
} // END - if
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolName=' . $protocolName . ',packageData=' . print_r($packageData, TRUE));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('protocolInstance=' . $protocolInstance . ',packageData=' . print_r($packageData, TRUE));
/*
* Now we have the listener instance, we can determine the right
// Try to create a new socket resource
try {
// Possibly noisy debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to establish a ' . strtoupper($protocolInstance) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
// Get a socket resource from our factory (if succeeded)
- $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
+ $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolInstance);
} catch (SocketConnectionException $e) {
// The connection fails of being established, so log it away
self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Caught ' . $e->__toString() . ',message=' . $e->getMessage());
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * 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
+ * @param $regex Regular expression to use for validation without slashes
+ * @return $isValid Whether the UNL is valid
+ */
+ protected final function isValidUniversalNodeLocator ($unl, $regex) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl . ',regex=' . $regex . ' - CALLED!');
+
+ // Very basic regex check
+ $isValid = (preg_match('/^' . $regex . '$/', $unl) === 1);
+
+ // Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
}
// [EOF]
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseIpV4ProtocolHandler extends BaseProtocolHandler {
+ /**
+ * Port number
+ */
+ private $port = 0;
+
+ // Regular expression for validating IP:port UNLs
+ const UNL_REGEX = '([a-z]{1,}):\/\/\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3})';
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * Setter for port number to satify HandleableProtocol
+ *
+ * @para $port The port number
+ * @return void
+ */
+ protected final function setPort ($port) {
+ // Set new port number
+ $this->port = $port;
+ }
+
+ /**
+ * Getter for port number to satify HandleableProtocol
+ *
+ * @return $port The port number
+ */
+ public final function getPort () {
+ // Return port number
+ return $this->port;
+ }
+
+ /**
+ * Validates given 'recipient' if it is a valid UNL. This means that the UNL
+ * can be parsed by the protocol handler.
+ *
+ * @param $packageData Valid raw package data
+ * @return $isValid Whether the UNL can be validated
+ */
+ public function isValidUniversalNodeLocatorByPackageData (array $packageData) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!');
+
+ // Is 'recipient' there?
+ assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+
+ // Is the correct handler choosen?
+ assert(substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($this->getHandlerName())) != $this->getHandlerName());
+
+ // Default is from generic validation
+ $isValid = $this->isValidUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], self::UNL_REGEX);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
+
+ // If this doesn't fail, continue validating the IP:port combination
+ if ($isValid === TRUE) {
+ // Okay, the basic test is passed, so reset the variable
+ $isValid = FALSE;
+
+ // ... and validate IP:port, first "parse" the UNL
+ $unlParts = $this->parseUnl($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Debug die
+ die(__METHOD__ . ':PACKAGE_DATA_RECIPIENT=' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',unlParts=' . print_r($unlParts, TRUE) . PHP_EOL);
+ } // END - if
+
+ // Return result
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
+ return $isValid;
+ }
}
// [EOF]
$packageData = array(
NetworkPackage::PACKAGE_DATA_SENDER => $peerName . ':0',
NetworkPackage::PACKAGE_DATA_RECIPIENT => $this->getSessionId(),
- NetworkPackage::PACKAGE_DATA_PROTOCOL => $this->getProtocolName(),
NetworkPackage::PACKAGE_DATA_STATUS => NetworkPackage::PACKAGE_STATUS_FAKED
);
public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
// Is this package already fragmented?
if (!$this->isPackageProcessed($packageData)) {
- // Remove package status and protocol, the recipient doesn't need this
+ // Remove package status, the recipient doesn't need this
unset($packageData[NetworkPackage::PACKAGE_DATA_STATUS]);
- unset($packageData[NetworkPackage::PACKAGE_DATA_PROTOCOL]);
// First we need to "implode" the array
$rawData = implode(NetworkPackage::PACKAGE_DATA_SEPARATOR, $packageData);
-Subproject commit 08164c824a16cc37eb29ef890ded66f0fbba4354
+Subproject commit a546101674aeccd5fb335ca02e3295bffe21691a
./application/hub/interfaces/wrapper/class_NodeDhtWrapper.php:122: * @todo Add minimum/maximum age limitations
./application/hub/interfaces/wrapper/class_NodeDhtWrapper.php:132: * @todo Add timestamp to dataset instance
./application/hub/main/chains/class_PackageFilterChain.php:54: * @todo This may be slow if a message with a lot tags arrived
-./application/hub/main/class_BaseHubSystem.php:576: // @TODO On some systems it is 134, on some 107?
+./application/hub/main/class_BaseHubSystem.php:577: // @TODO On some systems it is 134, on some 107?
./application/hub/main/commands/console/class_HubConsoleAptProxyCommand.php:107: * @todo Should we add some more filters?
./application/hub/main/commands/console/class_HubConsoleAptProxyCommand.php:58: * @todo Try to create a AptProxyActivationTask or so
./application/hub/main/commands/console/class_HubConsoleChatCommand.php:107: * @todo Should we add some more filters?
./application/hub/main/producer/miner/blocks/class_MinerTestGenesisBlockProducer.php:86: * @todo ~5% done
./application/hub/main/recipient/dht/class_DhtRecipient.php:76: // @TODO Unfinished
./application/hub/main/recipient/self/class_SelfRecipient.php:61: // @TODO Add more checks on data
-./application/hub/main/registry/socket/class_SocketRegistry.php:72: // @TODO Tested again base class, rewrite it to a generic interface!
+./application/hub/main/registry/socket/class_SocketRegistry.php:75: // @TODO Tested again base class, rewrite it to a generic interface!
./application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php:57: * @todo 0% done
./application/hub/main/resolver/state/peer/class_PeerStateResolver.php:59: * @todo ~30% done
./application/hub/main/scanner/crawler/uploaded_list/class_CrawlerUploadedListScanner.php:52: * @todo 0% done