// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Information\ShareableInfo;
use Hub\Listener\BaseListener;
*/
private $listenerInstance = NULL;
+ /**
+ * A HandleableProtocol instance
+ */
+ private $protocolInstance = NULL;
+
+ /**
+ * Name of used protocol
+ */
+ private $protocolName = 'invalid';
+
/**
* Protected constructor
*
return $this->listenerInstance;
}
+ /**
+ * Setter for HandleableProtocol instance
+ *
+ * @param $protocolInstance An instance of an HandleableProtocol
+ * @return void
+ */
+ public final function setProtocolInstance (HandleableProtocol $protocolInstance) {
+ $this->protocolInstance = $protocolInstance;
+ }
+
+ /**
+ * Getter for HandleableProtocol instance
+ *
+ * @return $protocolInstance An instance of an HandleableProtocol
+ */
+ public final function getProtocolInstance () {
+ return $this->protocolInstance;
+ }
+
+ /**
+ * Getter for protocol name
+ *
+ * @return $protocolName Name of used protocol
+ */
+ public final function getProtocolName () {
+ return $this->protocolName;
+ }
+
+ /**
+ * Setter for protocol name
+ *
+ * @param $protocolName Name of used protocol
+ * @return void
+ */
+ protected final function setProtocolName ($protocolName) {
+ $this->protocolName = $protocolName;
+ }
+
}
// @TODO Add some validation here???
return $protocolType;
}
-}
-// [EOF]
-?>
+}
use Hub\Factory\Node\NodeObjectFactory;
use Hub\Factory\Socket\SocketFactory;
use Hub\Generic\BaseHubSystem;
+use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Helper\Connection\BaseConnectionHelper;
use Hub\Network\Package\NetworkPackage;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Protocol\HandleableProtocol;
// Import framework stuff
use CoreFramework\Factory\ObjectFactory;
namespace Hub\Factory\Socket;
// Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Listener\BaseListener;
use Hub\Network\Package\NetworkPackage;
<?php
+// Own namespace
+namespace Hub\Handler\Protocol\;
+
+// Import appplication-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
+// Import framework stuff
+use CoreFramework\Registry\Registerable;
+
/**
* A ??? protocol handler
*
// Return the prepared instance
return $handlerInstance;
}
-}
-// [EOF]
-?>
+}
namespace Hub\Handler\Protocol;
// Import application-specific sutff
+use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Locator\Node\UniversalNodeLocator;
use Hub\Tools\HubTools;
* 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 {
+class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
/**
- * Whole UNL data array
+ * Whole UNL instance
*/
- private $universalNodeLocatorData = array();
+ private $universalNodeLocatorInstance = NULL;
/**
* Protected constructor
}
/**
- * Setter for UNL data array to satify HandleableProtocol
+ * Setter for UNL instance
*
- * @para $unlData The UNL data array
+ * @para $unlInstance An instance of a LocateableNode class
* @return void
*/
- protected final function setUniversalNodeLocatorData (array $unlData) {
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
// Set new UNL data array
- $this->universalNodeLocatorData = $unlData;
- }
-
- /**
- * Getter for UNL data array to satify HandleableProtocol
- *
- * @return $unlData The UNL data array
- */
- public final function getUniversalNodeLocatorDataArray () {
- // Return UNL data array
- return $this->universalNodeLocatorData;
+ $this->universalNodeLocatorInstance = $unlInstance;
}
/**
}
/**
- * "Getter" for currently saved UNL
+ * Getter for UNL instance
*
- * @return $unl Currently saved Universal Node Locator
+ * @return $unlData An instance of a LocateableNode class
*/
- public final function getCurrentUniversalNodeLocator () {
- // Construct generic UNL
- $unl = sprintf('%s://%s',
- $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
- $this->getAddressPart()
- );
-
- // Return it
- return $unl;
+ public final function getUniversalNodeLocatorInstance () {
+ // Return UNL data array
+ return $this->universalNodeLocatorInstance;
}
/**
// Return result
return $ifMatches;
}
-}
-// [EOF]
-?>
+}
<?php
+// Own namespace
+namespace Hub\Handler\Protocol\;
+
+// Import application-specific stuff
+
+// Import framework stuff
+
/**
* A ??? protocol handler
*
* 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 {
+class ???ProtocolHandler extends BaseIpV4Handler {
/**
* Protected constructor
*
// Return the prepared instance
return $handlerInstance;
}
-}
-// [EOF]
-?>
+}
}
/**
- * Setter for port number to satify HandleableProtocol
+ * Setter for port number
*
* @para $port The port number
* @return void
}
/**
- * Getter for port number to satify HandleableProtocol
+ * Getter for port number
*
* @return $port The port number
*/
// If this doesn't fail, continue validating the IP:port combination
if ($isValid === TRUE) {
// ... and validate IP:port, first "parse" the UNL
- $unlData = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- /*
- * Make sure the extra field 'port' is there. This may look
- * superflious but in case of a rewrite this assert will stop at
- * badly formated arrays.
- */
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+ $unlInstance = $this->parseUniversalNodeLocator($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
// Set whole UNL data array
- $this->setUniversalNodeLocatorData($unlData);
+ $this->setUniversalNodeLocatorInstance($unlInstance);
// Set port
- $this->setPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+ $this->setPort($unlInstance->getUnlPort());
} // END - if
// Return result
// Construct address
$address = sprintf('%s:%s',
parent::getAddressPart(),
- $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PORT)
+ $this->getUniversalNodeLocatorInstance()->getUnlPort()
);
// Return it
return $address;
}
-}
-// [EOF]
-?>
+}
// Own namespace
namespace Hub\Handler\Protocol\Tcp;
+// Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
// Import framework stuff
use CoreFramework\Registry\Registerable;
}
/**
- * Getter for port number to satify HandleableProtocol
+ * Getter for port number to
*
* @return $connectionPort The port number
*/
}
/**
- * Setter for port number to satify HandleableProtocol
+ * Setter for port number
*
* @param $connectionPort The port number
* @return void
// @TODO The whole resolving part should be moved out and made more configurable
// Init recipient data
- $unlData = array();
+ $unlInstance = NULL;
// Try to solve the recipient
try {
// Get protocol handler back from package data
$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[UniversalNodeLocator::UNL_PART_PROTOCOL]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
- assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
+ // Get UNL instance
+ $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance();
// Set handler instance
$helperInstance->setHandlerInstance($handlerInstance);
}
// Set address and maybe port
- $helperInstance->setAddress($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]);
- $helperInstance->setConnectionPort($unlData[UniversalNodeLocator::UNL_PART_PORT]);
+ $helperInstance->setAddress($unlInstance->getUnlAddress());
+ $helperInstance->setConnectionPort($unlInstance->getUnlPort());
// Now connect to it
if (!$helperInstance->connectToPeerByUnlData($unlData)) {
// And return the result
return $accepts;
}
-}
-// [EOF]
-?>
+}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Socket;
+
+// Inport application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
+/**
+ * This exception is thrown when the requested socket is not thrown
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 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 NoSocketRegisteredException extends AbstractSocketException {
+ /**
+ * A Constructor for this exception
+ *
+ * @param $protocolInstance An instance of a HandleableProtocol class
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct (HandleableProtocol $protocolInstance, $code) {
+ // Construct the message
+ $message = sprintf('[%s:] Requested socket is not yet registered.',
+ $protocolInstance->__toString()
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+
+}
<?php
+// Own namespace
+namespace Hub\Discovery\Socket;
+
+// Import application-specific stuff
+use Hub\Handler\Protocol\HandleableProtocol;
+
/**
* An interface for socket discovery
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface HandleableProtocol extends Handleable {
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ */
+ function getUniversalNodeLocatorInstance ();
+
/**
* Getter for port number to satify HandleableProtocol
*
*/
function getProtocolName ();
+ /**
+ * Default implementation for returning address part, may not be suitable
+ * for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
+ *
+ * @return $address Address part for the UNL
+ */
+ function getAddressPart ();
+
/**
* Validates given 'recipient' if it is a valid UNL. This means that the UNL
* can be parsed by the protocol handler.
function doShutdown ();
/**
- * Getter for port number to satify HandleableProtocol
+ * Getter for port number
*
* @return $port The port number
*/
function ifPackageDataIsAcceptedByListener (array $packageData, Listenable $listenerInstance);
}
-
-// [EOF]
-?>
-Subproject commit aa76ddf7f1d5d302f1d752efcd113515ecf152a2
+Subproject commit 8d7422139a55477388fcd6a30a1ce41d83780e5e