*
* @return $listenerInstance A Listenable instance
*/
- protected final function getListenerInstance () {
+ public final function getListenerInstance () {
return $this->listenerInstance;
}
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Container;
+
+// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Generic\HubInterface;
+use Hub\Information\ShareableInfo;
+use Hub\Listener\Listenable;
+use Hub\Locator\Node\LocateableNode;
+use Hub\Pool\Poolable;
+
+// Import framework stuff
+use CoreFramework\Container\BaseContainer;
+
+/**
+ * A general hub container
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher 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 BaseHubContainer extends BaseContainer implements HubInterface {
+ /**
+ * Listener instance
+ */
+ private $listenerInstance = NULL;
+
+ /**
+ * Listener pool instance
+ */
+ private $listenerPoolInstance = NULL;
+
+ /**
+ * Info instance
+ */
+ private $infoInstance = NULL;
+
+ /**
+ * A StorableSocket instance
+ */
+ private $socketInstance = NULL;
+
+ /**
+ * An instance of a LocateableNode class
+ */
+ private $universalNodeLocatorInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Checks whether start/end marker are set
+ *
+ * @param $data Data to be checked
+ * @return $isset Whether start/end marker are set
+ */
+ public final function ifStartEndMarkersSet ($data) {
+ // Determine it
+ $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+ // ... and return it
+ return $isset;
+ }
+
+ /**
+ * Setter for listener pool instance
+ *
+ * @param $listenerPoolInstance The new listener pool instance
+ * @return void
+ */
+ protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) {
+ $this->listenerPoolInstance = $listenerPoolInstance;
+ }
+
+ /**
+ * Getter for listener pool instance
+ *
+ * @return $listenerPoolInstance Our current listener pool instance
+ */
+ public final function getListenerPoolInstance () {
+ return $this->listenerPoolInstance;
+ }
+
+ /**
+ * Setter for info instance
+ *
+ * @param $infoInstance A ShareableInfo instance
+ * @return void
+ */
+ protected final function setInfoInstance (ShareableInfo $infoInstance) {
+ $this->infoInstance = $infoInstance;
+ }
+
+ /**
+ * Getter for info instance
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final function getInfoInstance () {
+ return $this->infoInstance;
+ }
+
+ /**
+ * Setter for socket instance
+ *
+ * @param $socketInstance A StorableSocket instance
+ * @return void
+ */
+ public final function setSocketInstance (StorableSocket $socketInstance) {
+ $this->socketInstance = $socketInstance;
+ }
+
+ /**
+ * Getter for socket instance
+ *
+ * @return $socketInstance An instance of a StorableSocket class
+ */
+ public final function getSocketInstance () {
+ return $this->socketInstance;
+ }
+
+ /**
+ * Setter for UNL instance
+ *
+ * @para $unlInstance An instance of a LocateableNode class
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ // Set new UNL data array
+ $this->universalNodeLocatorInstance = $unlInstance;
+ }
+
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ */
+ public final function getUniversalNodeLocatorInstance () {
+ // Return UNL data array
+ return $this->universalNodeLocatorInstance;
+ }
+
+ /**
+ * Setter for node id
+ *
+ * @param $nodeId The new node id
+ * @return void
+ */
+ protected final function setNodeId ($nodeId) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for node id
+ *
+ * @return $nodeId Current node id
+ */
+ public final function getNodeId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key
+ *
+ * @param $privateKey The new private key
+ * @return void
+ */
+ protected final function setPrivateKey ($privateKey) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key
+ *
+ * @return $privateKey Current private key
+ */
+ public final function getPrivateKey () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key hash
+ *
+ * @param $privateKeyHash The new private key hash
+ * @return void
+ */
+ protected final function setPrivateKeyHash ($privateKeyHash) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key hash
+ *
+ * @return $privateKeyHash Current private key hash
+ */
+ public final function getPrivateKeyHash () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for session id
+ *
+ * @return $sessionId Current session id
+ */
+ public final function getSessionId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * 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
+ */
+ public final function getListenerInstance () {
+ return $this->listenerInstance;
+ }
+
+}
namespace Hub\Container\Socket;
// Import application-specific stuff
+use Hub\Container\BaseHubContainer;
use Hub\Handler\Network\RawData\BaseRawDataHandler;
use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory;
use Hub\Factory\Socket\SocketFactory;
use Hub\Helper\Connection\BaseConnectionHelper;
+use Hub\Helper\Connection\ConnectionHelper;
use Hub\Information\ShareableInfo;
use Hub\Listener\BaseListener;
use Hub\Listener\Listenable;
use Hub\Network\Package\NetworkPackage;
// Import framework stuff
-use CoreFramework\Container\BaseContainer;
use CoreFramework\Factory\ObjectFactory;
use CoreFramework\Registry\Registerable;
use CoreFramework\Socket\InvalidSocketException;
* 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 SocketContainer extends BaseContainer implements StorableSocket, Visitable, Registerable {
+class SocketContainer extends BaseHubContainer implements StorableSocket, Visitable, Registerable {
/**
* Socket protocol:
* - 'tcp' for TCP/IPv4 connections
* @param $socketResource A valid socket resource
* @param $socketProtocol Socket protocol
* @param $packageData Raw package data
- * @param $infoInstance An instance of a ShareableInfo class
* @return $socketInstance An instance of this Container class
*/
- public static final function createSocketContainer ($socketResource, $socketProtocol, array $packageData, ShareableInfo $infoInstance = NULL) {
+ public static final function createSocketContainer ($socketResource, $socketProtocol, array $packageData) {
// Trace message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageData()=%d,infoInstance[]=%s - CALLED!', $socketResource, $socketProtocol, count($packageData), gettype($infoInstance)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s,packageData()=%d - CALLED!', $socketResource, $socketProtocol, count($packageData)));
/* DEBUG-PRINT: */ printf('[%s:%d]: packageData=%s', __METHOD__, __LINE__, print_r($packageData, TRUE));
// Get a new instance
unset($packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
unset($packageData[NetworkPackage::PACKAGE_DATA_HASH]);
- // Is the info instance set?
- if ($infoInstance instanceof ShareableInfo) {
- // Get listener/helper from info class
- $listenerInstance = $infoInstance->getListenerInstance();
- $helperInstance = $infoInstance->getHelperInstance();
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance));
-
- // Is there a listener instance set?
- if ($listenerInstance instanceof Listenable) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
-
- // Set it here for later usage
- $socketInstance->setListenerInstance($listenerInstance);
- } elseif ($helperInstance instanceof ConnectionHelper) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting helperInstance=' . $helperInstance->__toString() . ' ...');
-
- // Set it here for later usage
- $socketInstance->setHelperInstance($helperInstance);
- }
- } // END - if
-
// Set the resource ...
$socketInstance->setSocketResource($socketResource);
*
* @return $recipient Recipient array element
* @throws LogicException If 'recipient' array element is not found
+ * @throws InvalidSocketException If socket is invalid
*/
public function getSocketRecipient () {
+ // Should be valid socket
+ if (!$this->isValidSocket()) {
+ // Throw exception
+ throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
// Get package data
$packageData = $this->getPackageData();
return $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
}
+ /**
+ * Getter for socket recipient's address part
+ *
+ * @return $recipientAddress Recipient's address part
+ * @throws InvalidSocketException If socket is invalid
+ */
+ public function getSocketRecipientAddress () {
+ // Should be valid socket
+ if (!$this->isValidSocket()) {
+ // Throw exception
+ throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Get recipient
+ $recipient = $this->getSocketRecipient();
+
+ // Generate UNL instance for it
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
+
+ // Get address part
+ $recipientAddress = $unlInstance->getUnlAddress();
+
+ // Return it
+ return $recipientAddress;
+ }
+
+ /**
+ * Getter for socket recipient's port part
+ *
+ * @return $recipientPort Recipient's port part
+ * @throws InvalidSocketException If socket is invalid
+ */
+ public function getSocketRecipientPort () {
+ // Should be valid socket
+ if (!$this->isValidSocket()) {
+ // Throw exception
+ throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Get recipient
+ $recipient = $this->getSocketRecipient();
+
+ // Generate UNL instance for it
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($recipient);
+
+ // Get port part
+ $recipientPort = $unlInstance->getUnlPort();
+
+ // Return it
+ return $recipientPort;
+
+ }
+
/**
* Validates stored stocket
*
return $errorMessage;
}
+ /**
+ * Translates last socket error code into a human-readable form
+ *
+ * @return $codeName Code name to used e.g. with some_$codeName_socket_error_class or so
+ */
+ public function translateLastSocketErrorCodeToName () {
+ // Get last error code
+ $errorCode = $this->getLastSocketErrorCode();
+
+ // Call "translate" method
+ $codeName = $this->translateSocketErrorCodeToName($errorCode);
+
+ // Return it
+ return $codeName;
+ }
+
/**
* Tries to bind the socket.
*
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!');
}
+ /**
+ * Registers whether helper or listener instance found in given info
+ * instance with this socket container.
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @return void
+ */
+ public function registerInfoInstance (ShareableInfo $infoInstance) {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Calling infoInstance->getListenerInstance() ...', strtoupper($this->getSocketProtocol())));
+
+ // Get listener/helper from info class
+ $listenerInstance = $infoInstance->getListenerInstance();
+ $helperInstance = $infoInstance->getHelperInstance();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
+
+ // Is there a listener instance set?
+ if ($listenerInstance instanceof Listenable) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting listenerInstance=' . $listenerInstance->__toString() . ' ...');
+
+ // Set it here for later usage
+ $this->setListenerInstance($listenerInstance);
+ } elseif ($helperInstance instanceof ConnectionHelper) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Setting helperInstance=' . $helperInstance->__toString() . ' ...');
+
+ // Set it here for later usage
+ $this->setHelperInstance($helperInstance);
+ }
+ }
+
/**
* Handles socket error for given socket resource and peer data. This method
* validates socket resource stored in given container if it is a valid
use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
/**
- * A database wrapper for cruncher work/test units
+ * A general hub database wrapper
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements HubInterface {
+ /**
+ * Listener instance
+ */
+ private $listenerInstance = NULL;
/**
* Listener pool instance
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
+ /**
+ * 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
+ */
+ public final function getListenerInstance () {
+ return $this->listenerInstance;
+ }
+
}
$peerPort = '0';
// Get peer name
- if (!@socket_getpeername($socketInstance, $peerAddress, $peerPort)) {
+ if (!$socketInstance->getSocketPeerName($peerAddress, $peerPort)) {
// Get last error
- $lastError = socket_last_error($socketInstance);
+ $lastError = $socketInstance->getLastSocketErrorCode();
// ... and cleartext message from it and put both into criteria
$dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $lastError);
*
* @param $socketInstance An instance of a StorableSocket class
* @return void
- * @throws InvalidSocketException If the socket resource was invalid
* @todo Unfinished area, please rewrite!
*/
- public function purgeOldEntriesBysocketInstance (StorableSocket $socketInstance) {
- // Get peer name
- if (!@socket_getpeername($socketInstance, $peerAddress, $peerPort)) {
- // Get last error
- $lastError = socket_last_error($socketInstance);
-
- // Doesn't work!
- throw new InvalidSocketException(array($this, $socketInstance, $lastError, socket_strerror($lastError)), self::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DATABASE-WRAPPER: peerAddress=' . $peerAddress . ',peerPort=' . $peerPort . ' - UNFINISHED!');
+ public function purgeOldEntriesBySocketInstance (StorableSocket $socketInstance) {
+ $this->partialStub('Please finish this method.');
}
/**
// Return it
return $isSamePeerState;
}
-}
-// [EOF]
-?>
+}
namespace Hub\Factory\State\Peer;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Helper\Connection\ConnectionHelper;
// Import framework stuff
*
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageData Raw package data
- * @param $socketResource A valid socket resource
+ * @param $socketInstance A valid socket resource
* @param $errorCode The last error code
* @return $stateInstance A Stateable class instance
*/
- public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, array $packageData, $socketResource, $errorCode) {
+ public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, array $packageData, StorableSocket $socketInstance, $errorCode) {
// Init state instance, this is better coding practice
$stateInstance = NULL;
*/
try {
// Purge old entries
- $tableInstance->purgeOldEntriesBySocketResource($socketResource);
+ $tableInstance->purgeOldEntriesBySocketInstance($socketInstance);
} catch (InvalidSocketException $e) {
// Just log all errors
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] Purging of old entries failed. Message from exception: ' . $e->getMessage());
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY[' . __LINE__ . ':] errorCode=' . $errorCode);
// Register the new peer with its session id
- $tableInstance->registerPeerByPackageData($packageData, $socketResource);
+ $tableInstance->registerPeerByPackageData($packageData, $socketInstance);
/*
* It is a new peer so create the state instance based on error
use Hub\Handler\Network\RawData\BaseRawDataHandler;
use Hub\Generic\HubInterface;
use Hub\Information\ShareableInfo;
+use Hub\Listener\Listenable;
use Hub\Locator\Node\LocateableNode;
use Hub\Pool\Poolable;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseHubHandler extends BaseHandler implements Handleable, HubInterface {
+ /**
+ * Listener instance
+ */
+ private $listenerInstance = NULL;
+
/**
* Listener pool instance
*/
throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
}
+ /**
+ * 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
+ */
+ public function getListenerInstance () {
+ return $this->listenerInstance;
+ }
+
}
// Fill the generic array with several data from the listener:
$this->setProtocolName($helperInstance->getSocketInstance()->getSocketProtocol());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $helperInstance->getSocketInstance()->getRecipientAddress());
- $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT , $helperInstance->getSocketInstance()->getRecipientPort());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $helperInstance->getSocketInstance()->getSocketRecipientAddress());
+ $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT , $helperInstance->getSocketInstance()->getSocketRecipientPort());
// Set helper here
$this->setHelperInstance($helperInstance);
* @return $listenAddress The address this listener should listen on
*/
public final function getListenAddress () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LISTENER-DECORATOR: Calling this->getListenerInstance()->getListenAddress() ...');
return $this->getListenerInstance()->getListenAddress();
}
* @return $listenPort The port this listener should listen on
*/
public final function getListenPort () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('LISTENER-DECORATOR: Calling this->getListenerInstance()->getListenPort() ...');
return $this->getListenerInstance()->getListenPort();
}
*
* @return $listenerInstance A Listenable instance
*/
- protected final function getListenerInstance () {
+ public final function getListenerInstance () {
return $this->listenerInstance;
}
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance() ...');
+
// Handle generic TCP package
$this->getListenerInstance()->doListen();
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CLIENT-TCP-LISTENER: Calling this->getListenerInstance() ...');
+
// Handle generic TCP package
$this->getListenerInstance()->doListen();
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TCP-LISTENER: Calling this->getListenerInstance() ...');
+
// Handle generic TCP package
$this->getListenerInstance()->doListen();
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CLIENT-UDP-LISTENER: Calling this->getListenerInstance() ...');
+
// Handle generic UDP packages first
$this->getListenerInstance()->doListen();
* @return void
*/
public function doListen () {
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-UDP-LISTENER: Calling this->getListenerInstance() ...');
+
// Handle generic UDP package first
$this->getListenerInstance()->doListen();
$peerAddress = '0.0.0.0';
$peerPort = '0';
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DEFAULT-PEER-POOL: Calling this->getListenerInstance() ...');
+
// The socket resource should not match server socket
if (!$this->getListenerInstance()->getSocketInstance()->equals($socketInstance)) {
// Try to determine the peer's IP number
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Information\Connection\ConnectionInfoFactory;
+use Hub\Helper\Connection\ConnectionHelper;
use Hub\Information\ShareableInfo;
use Hub\Listener\BaseListener;
use Hub\Listener\Listenable;
// We have a sub-registry, the socket key and the socket, now we need to put all together
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - adding socket container instance ...');
$registryInstance->addInstance($socketKey, $socketInstance);
+
+ // Also register all instances from info instance in socket
+ $socketInstance->registerInfoInstance($infoInstance);
}
/**
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
// This is always a SubRegistry instance
- foreach ($registryInstance->getInstanceRegistry() as $subKey => $containerInstance) {
+ foreach ($registryInstance->getInstanceRegistry() as $subKey => $socketInstance) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',containerInstance=' . $containerInstance->__toString());
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',socketInstance=' . $socketInstance->__toString());
// Is this a StorableSocket instance and is the address the same?
- if (($containerInstance instanceof StorableSocket) && ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) {
+ if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]))) {
// Debug die
- //* DEBUG-DIE: */ die(__METHOD__ . ': containerInstance=' . print_r($containerInstance, TRUE));
+ //* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE));
+
+ // Trace message
+ /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: Calling socketInstance->getListenerInstance() ...');
// Get listener and helper instances
- $listenerInstance = $containerInstance->getListenerInstance();
- $helperInstance = $containerInstance->getHelperInstance();
+ $listenerInstance = $socketInstance->getListenerInstance();
+ $helperInstance = $socketInstance->getHelperInstance();
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
$infoInstance->fillWithConnectionHelperInformation($helperInstance);
} else {
// Not supported state!
- $this->debugInstance(sprintf('[%s:%d]: Invalid state found, please report this to the developers with full debug infos.', __METHOD__, __LINE__));
+ $this->debugInstance(sprintf('[%s:%d]: Invalid script-state found, please report this to the developers with full debug infos. socketInstance=%s', __METHOD__, __LINE__, print_r($socketInstance, TRUE)));
}
// Debug message
} // END - if
// Translate the error code to an own name
- $errorName = $socketInstance->translateSocketLastErrorCodeToName();
+ $errorName = $socketInstance->translateLastSocketErrorCodeToName();
// Create a state instance based on $errorCode. This factory does the hard work for us
$stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketInstance, $errorName);
*/
function getUniversalNodeLocatorInstance ();
+ /**
+ * Getter for listener instance
+ *
+ * @return $listenerInstance A Listenable instance
+ */
+ function getListenerInstance ();
+
}
// Own namespace
namespace Hub\Container\Socket;
+// Import application-related stuff
+use Hub\Information\ShareableInfo;
+
// Inport frameworks stuff
use CoreFramework\Generic\FrameworkInterface;
*
* @return $recipient Recipient array element
* @throws LogicException If 'recipient' array element is not found
+ * @throws InvalidSocketException If stored socket is invalid
*/
function getSocketRecipient ();
+ /**
+ * Getter for socket recipient's address part
+ *
+ * @return $recipientAddress Recipient's address part
+ * @throws InvalidSocketException If stored socket is invalid
+ */
+ function getSocketRecipientAddress ();
+
+ /**
+ * Getter for socket recipient's port part
+ *
+ * @return $recipientPort Recipient's port part
+ * @throws InvalidSocketException If stored socket is invalid
+ */
+ function getSocketRecipientPort ();
+
/**
* Checks whether the given Universal Node Locator matches with the one from package data
*
*/
function getLastSocketErrorMessage ();
+ /**
+ * Translates last socket error code into a human-readable form
+ *
+ * @return $codeName Code name to used e.g. with some_$codeName_socket_error_class or so
+ */
+ function translateLastSocketErrorCodeToName ();
+
/**
* Handles socket error for given socket resource and peer data. This method
* validates socket resource stored in given container if it is a valid
*/
function clearLastSocketError ();
+ /**
+ * Registers whether helper or listener instance found in given info
+ * instance with this socket container.
+ *
+ * @param $infoInstance An instance of a ShareableInfo class
+ * @return void
+ */
+ function registerInfoInstance (ShareableInfo $infoInstance);
+
}
// Own namespace
namespace Hub\Helper;
+// Import application-specific stuff
+use Hub\Generic\HubInterface;
+
// Import framework stuff
use CoreFramework\Helper\Helper;
* 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 HubHelper extends Helper {
+interface HubHelper extends Helper, HubInterface {
/**
* Tries to determine the used protocol for this package (this helper is helping to send out)
*
* @param $socketInstance An instance of a StorableSocket class
* @return void
*/
- function purgeOldEntriesBysocketInstance (StorableSocket $socketInstance);
+ function purgeOldEntriesBySocketInstance (StorableSocket $socketInstance);
/**
* Checks whether a given peer state (in helper instance) is same as stored
-Subproject commit e9e5242797adec674d25da4e641965f8d6dcbecd
+Subproject commit dc46df7fb4a0358cb7554c33b6f08d9ff8418c66