From fc4cfe3514091b56a2f0553556b25fc0937de755 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 29 May 2017 20:13:47 +0200 Subject: [PATCH] Continued: - moved socketInstance +getter/setter to BaseHubSystem - implemented getUnlAddress() - implemented getSocketRecipient() - imported PeerStateFactory - imported OutputStream - imported BaseResolver - other small fixes - added missing namespaces to configuration entries - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.php | 25 ++++ .../socket/class_SocketContainer.php | 113 +++++++++++++----- .../connection/class_BaseConnectionHelper.php | 27 +---- .../ipv4/class_BaseIpV4ConnectionHelper.php | 43 ++----- .../ipv4/tcp/class_TcpConnectionHelper.php | 14 +-- .../info/connection/class_ConnectionInfo.php | 6 +- .../classes/listener/class_BaseListener.php | 24 ---- .../locator/class_UniversalNodeLocator.php | 42 +++++-- .../state/class_BaseStateResolver.php | 1 + .../state/peer/class_PeerStateResolver.php | 1 + .../states/peer/class_BasePeerState.php | 2 +- .../output/class_RawDataOutputStream.php | 1 + application/hub/config.php | 16 +-- .../hub/interfaces/class_HubInterface.php | 16 +++ .../container/socket/class_StorableSocket.php | 26 ++++ .../connections/class_ConnectionHelper.php | 14 --- .../interfaces/listener/class_Listenable.php | 16 --- .../locator/class_LocateableNode.php | 16 ++- core | 2 +- 19 files changed, 229 insertions(+), 176 deletions(-) diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 76e8b27aa..dbad5a778 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -3,6 +3,7 @@ namespace Hub\Generic; // Import application-specific stuff +use Hub\Container\Socket\StorableSocket; use Hub\Handler\Protocol\HandleableProtocol; use Hub\Handler\Network\RawData\BaseRawDataHandler; use Hub\Information\ShareableInfo; @@ -108,6 +109,11 @@ class BaseHubSystem extends BaseFrameworkSystem implements HubInterface { */ private $protocolInstance = NULL; + /** + * A StorableSocket instance + */ + private $socketInstance = NULL; + /** * Name of used protocol */ @@ -391,4 +397,23 @@ class BaseHubSystem extends BaseFrameworkSystem implements HubInterface { $this->protocolName = $protocolName; } + /** + * 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; + } + } diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index f718d9ce9..c4d88636c 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -4,6 +4,7 @@ namespace Hub\Container\Socket; // Import application-specific stuff use Hub\Handler\Network\RawData\BaseRawDataHandler; +use Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Hub\Factory\Socket\SocketFactory; use Hub\Helper\Connection\BaseConnectionHelper; use Hub\Information\ShareableInfo; @@ -26,6 +27,7 @@ use CoreFramework\Visitor\Visitor; // Import SPL stuff use \BadMethodCallException; +use \LogicException; /** * A Socket Container class @@ -291,6 +293,26 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable return $this->socketProtocol; } + /** + * Getter for socket recipient array element + * + * @return $recipient Recipient array element + * @throws LogicException If 'recipient' array element is not found + */ + public function getSocketRecipient () { + // Get package data + $packageData = $this->getPackageData(); + + // Is the element there? + if (!isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) { + // Abort here + throw new LogicException(sprintf('packageData[%s] is not set.', NetworkPackage::PACKAGE_DATA_RECIPIENT)); + } // END - if + + // Return it + return $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]; + } + /** * Validates stored stocket * @@ -436,15 +458,48 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable return $result; } + /** + * Connects to socket recipient (supplied in package data array + * + * @return $result Result from calling socket_connect() + * @throws InvalidSocketException If stored socket is invalid + */ + public function connectToSocketRecipient () { + // Should be valid socket + if (!$this->isValidSocket()) { + // Throw exception + throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET); + } // END - if + + // Get recipient UNL + $unlRecipient = $this->getSocketRecipient(); + + // Create UNL instance from it. This will validate the connection + $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($unlRecipient); + + // Try to connect to it + $result = socket_connect($this->getSocketResource(), $unlInstance->getUnlAddress(), $unlInstance->getUnlPort()); + + // Return result + return $result; + } + /** * Do the shutdown sequence for this connection helper * * @return void * @throws SocketShutdownException If the current socket could not be shut down + * @throws BaseMethodCallException If this method is possibly called twice * @todo We may want to implement a filter for ease notification of other objects like our pool * @todo rewrite this! */ public function doShutdown () { + // Should be valid socket + if (!$this->isValidSocket()) { + // Throw exception + throw new BaseMethodCallException(sprintf('[%s:%d]: Shutdown on invalid socket. Maybe called already?', __METHOD__, __LINE__), self::EXCEPTION_INVALID_SOCKET); + } // END - if + // Debug message self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getSocketResource()); $this->partialStub('Please rewrite this method.'); @@ -611,6 +666,34 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable * @return $result Whether OOB has been enabled */ public function enableSocketOutOfBandData () { + $this->partialStub('Please implement this method.'); + } + + /** + * Clears last socket error + * + * @return void + * @throws InvalidSocketException If stored socket is invalid + * @throws BadMethodCallException If no socket error was reported but method called + */ + public function clearLastSocketError () { + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!'); + + // Should be valid socket + if (!$this->isValidSocket()) { + // Throw exception + throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET); + } elseif ($this->getLastSocketErrorCode() === 0) { + // Nothing to clear + throw new BadMethodCallException(sprintf('Socket "%s" has no error reported, but method is called.', $this->getSocketResource())); + } + + // Clear last error + socket_clear_error($this->getSocketResource()); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!'); } /** @@ -798,8 +881,7 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable /** * Handles socket error 'operation already in progress' which happens in - * method connectToPeerByUnlInstance() on timed out connection - * attempts. + * method connectToPeerBySocketRecipient() on timed-out connection attempts. * * @param $socketData Valid socket data array * @return void @@ -989,31 +1071,4 @@ class SocketContainer extends BaseContainer implements StorableSocket, Visitable return $result; } - /** - * Clears last socket error - * - * @return void - * @throws InvalidSocketException If stored socket is invalid - * @throws BadMethodCallException If no socket error was reported but method called - */ - private function clearLastSocketError () { - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Clearing socket error - CALLED!'); - - // Should be valid socket - if (!$this->isValidSocket()) { - // Throw exception - throw new InvalidSocketException(array($this, $this->getSocketResource()), self::EXCEPTION_INVALID_SOCKET); - } elseif ($this->getLastSocketErrorCode() === 0) { - // Nothing to clear - throw new BadMethodCallException(sprintf('Socket "%s" has no error reported, but method is called.', $this->getSocketResource())); - } - - // Clear last error - socket_clear_error($this->getSocketResource()); - - // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: Error cleared - EXIT!'); - } - } diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 1e3e75054..355c76685 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -5,6 +5,7 @@ namespace Hub\Helper\Connection; // Import application-specific stuff use Hub\Factory\Fragmenter\FragmenterFactory; use Hub\Factory\Network\NetworkPackageFactory; +use Hub\Factory\State\Peer\PeerStateFactory; use Hub\Helper\BaseHubSystemHelper; use Hub\Network\Package\NetworkPackage; @@ -41,11 +42,6 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Reg // Exception codes const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100; - /** - * (IP) Adress used - */ - private $address = 0; - /** * Sent data in bytes */ @@ -113,31 +109,12 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Reg */ public final function __toString () { // Class name representation - $class = self::getConnectionClassName($this->getAddress(), $this->getConnectionPort(), parent::__toString()); + $class = self::getConnectionClassName($this->getSocketInstance(), parent::__toString()); // Return it return $class; } - /** - * Getter for IP address - * - * @return $address The IP address - */ - public final function getAddress () { - return $this->address; - } - - /** - * Setter for IP address - * - * @param $address The IP address - * @return void - */ - protected final function setAddress ($address) { - $this->address = $address; - } - /** * Setter for isInitialized * diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index f40fb6d06..ec16978f6 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -3,6 +3,7 @@ namespace Hub\Helper\Connection\Network\IpV4; // Import application-specific stuff +use Hub\Factory\State\Peer\PeerStateFactory; use Hub\Helper\Connection\BaseConnectionHelper; use Hub\Locator\Node\LocateableNode; @@ -30,11 +31,6 @@ use Hub\Locator\Node\LocateableNode; * along with this program. If not, see . */ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { - /** - * Port number used - */ - private $connectionPort = 0; - /** * Protected constructor * @@ -46,57 +42,34 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { parent::__construct($className); } - /** - * Getter for port number to - * - * @return $connectionPort The port number - */ - public final function getConnectionPort () { - return $this->connectionPort; - } - - /** - * Setter for port number - * - * @param $connectionPort The port number - * @return void - */ - protected final function setConnectionPort ($connectionPort) { - $this->connectionPort = $connectionPort; - } - /** * Attempts to connect to a peer by given IP number and port from an UNL * instance with currently configured timeout. * - * @param $unlInstance An instance of a LocateableNode class * @return $isConnected Whether the connection went fine * @see Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code * @todo Rewrite the while() loop to a iterator to not let the software stay very long here */ - protected function connectToPeerByUnlInstance (LocateableNode $unlInstance) { + protected function connectToPeerBySocketRecipient () { + //* DEBUG-DIE: */ die(__METHOD__.':socketInstance='.print_r($this->getSocketInstance(), TRUE)); + // Only call this if the connection is fully initialized assert($this->isInitialized()); - // Is the UNL data complete? - assert($unlInstance->isValidUnl()); - // "Cache" socket resource and timeout config $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds'); // Debug output - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Trying to connect to ' . $unlInstance->getUnlAddress() . ':' . $unlInstance->getUnlPort() . ' with socketResource[' . gettype($this->getSocketInstance()->getSocketResource()) . ']=' . $this->getSocketInstance()->getSocketResource() . ' ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: Trying to connect to %s with socketResource[%s]=%s ...', $this->getSocketInstance()->getSocketRecipient(), gettype($this->getSocketInstance()->getSocketResource()), $this->getSocketInstance()->getSocketResource())); // Get current time $hasTimedOut = FALSE; $time = time(); - $this->partialStub('Please rewrite this part.'); - return; // Try to connect until it is connected - while ($isConnected = !@socket_connect($this->getSocketInstance(), $unlData[LocateableNode::UNL_PART_ADDRESS], $unlData[LocateableNode::UNL_PART_PORT])) { + while ($isConnected = !$this->getSocketInstance()->connectToSocketRecipient()) { // Get last socket error - $socketError = socket_last_error($this->getSocketInstance()); + $socketError = $this->getSocketInstance()->getLastSocketErrorCode(); // Log error code and status /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: socketError=' . $socketError . ',isConnected=' . intval($isConnected)); @@ -143,7 +116,7 @@ class BaseIpV4ConnectionHelper extends BaseConnectionHelper { $isConnected = TRUE; // Clear error - socket_clear_error($this->getSocketInstance()); + $this->getSocketInstance()->clearLastSocketError(); } // END - if // Is the peer connected? diff --git a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php index 50efbbaa8..7513b416a 100644 --- a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php @@ -114,21 +114,17 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection } } - // Set address and maybe port - $helperInstance->setAddress($unlInstance->getUnlAddress()); - $helperInstance->setConnectionPort($unlInstance->getUnlPort()); - // Now connect to it - if (!$helperInstance->connectToPeerByUnlInstance($unlData)) { + if (!$helperInstance->connectToPeerBySocketRecipient()) { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: helperInstance=' . $helperInstance->__toString() . ',unlData=' . print_r($unlData, TRUE)); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TCP-CONNECTION-HELPER: helperInstance=%s,unlInstance.unlData=%s', $helperInstance->__toString(), print_r($unlInstance->getUnlData(), TRUE))); // Handle socket error - $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, $unlData); + $socketInstance->handleSocketError(__METHOD__, __LINE__, $unlInstance->getUnlData()); } // END - if // Okay, that should be it. Return it... - return $socketResource; + return $socketInstance; } /** @@ -140,7 +136,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection */ public function doShutdown () { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Shutting down connection ... - CALLED!'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-CONNECTION-HELPER: Shutting down connection ... - CALLED!'); $this->partialStub('Please implement this method.'); } diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index 45c048b16..1d6c48b10 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -91,9 +91,9 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(': protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!'); // Fill the generic array with several data from the listener: - $this->setProtocolName($helperInstance->getProtocolName()); - $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS , $helperInstance->getAddress()); - $this->setGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT , $helperInstance->getConnectionPort()); + $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()); // Set helper here $this->setHelperInstance($helperInstance); diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index f367f33cc..a7bf4602b 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -68,11 +68,6 @@ class BaseListener extends BaseHubSystem implements Visitable { */ private $poolInstance = NULL; - /** - * A StorableSocket instance - */ - private $socketInstance = NULL; - /** * Protected constructor * @@ -322,23 +317,4 @@ class BaseListener extends BaseHubSystem implements Visitable { $this->getIteratorInstance()->next(); } - /** - * 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; - } - } diff --git a/application/hub/classes/locator/class_UniversalNodeLocator.php b/application/hub/classes/locator/class_UniversalNodeLocator.php index 1a5ad11aa..b4b51f95e 100644 --- a/application/hub/classes/locator/class_UniversalNodeLocator.php +++ b/application/hub/classes/locator/class_UniversalNodeLocator.php @@ -117,11 +117,33 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL]; } + /** + * Some "getter" for UNL address part. + * + * @return $unlAddress UNL address part + */ + public function getUnlAddress () { + // Get UNL data + $unlData = $this->getUnlData(); + + // Default value is NULL + $unlPort = NULL; + + // Is the element there? + if (isset($unlData[LocateableNode::UNL_PART_ADDRESS])) { + // Use it + $unlPort = $unlData[LocateableNode::UNL_PART_ADDRESS]; + } // END - if + + // Return it + return $unlPort; + } + /** * Some "getter" for UNL port (if supported). If not supported, NULL is * being returned. * - * @return $unlPort Port number of UNL + * @return $unlPort Port number of UNL or NULL */ public function getUnlPort () { // Get UNL data @@ -157,6 +179,15 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi $this->parseUniversalNodeLocator($unl); } + /** + * Getter for UNL data array + * + * @return $unlData An array with UNL data + */ + public final function getUnlData () { + return $this->unlData; + } + /** * Parses the given UNL by splitting it up in its components. The UNL ... * @@ -243,15 +274,6 @@ class UniversalNodeLocator extends BaseHubSystem implements LocateableNode, Regi } // 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 diff --git a/application/hub/classes/resolver/state/class_BaseStateResolver.php b/application/hub/classes/resolver/state/class_BaseStateResolver.php index eaceee675..e6107574c 100644 --- a/application/hub/classes/resolver/state/class_BaseStateResolver.php +++ b/application/hub/classes/resolver/state/class_BaseStateResolver.php @@ -4,6 +4,7 @@ namespace Hub\Resolver\State; // Import framework stuff use CoreFramework\Factory\ObjectFactory; +use CoreFramework\Resolver\BaseResolver; /** * A generic state resolver class diff --git a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php index bf689f637..f526eebf2 100644 --- a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php +++ b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php @@ -4,6 +4,7 @@ namespace Hub\Resolver\State\Peer; // Import application-specific stuff use Hub\Container\Socket\StorableSocket; +use Hub\Factory\State\Peer\PeerStateFactory; use Hub\Helper\Connection\ConnectionHelper; // Import framework stuff diff --git a/application/hub/classes/states/peer/class_BasePeerState.php b/application/hub/classes/states/peer/class_BasePeerState.php index 1113b3493..abfdc3c52 100644 --- a/application/hub/classes/states/peer/class_BasePeerState.php +++ b/application/hub/classes/states/peer/class_BasePeerState.php @@ -1,6 +1,6 @@ setConfigEntry('node_announcement_completed_state_class', 'Hub\State\Node\ /////////////////////////////////////////////////////////////////////////////// // CFG: PEER-INIT-STATE-CLASS -$cfg->setConfigEntry('peer_init_state_class', 'InitPeerState'); +$cfg->setConfigEntry('peer_init_state_class', 'Hub\State\Peer\InitPeerState'); // CFG: PEER-CONNECTED-STATE-CLASS -$cfg->setConfigEntry('peer_connected_state_class', 'ConnectedPeerState'); +$cfg->setConfigEntry('peer_connected_state_class', 'Hub\State\Peer\ConnectedPeerState'); // CFG: PEER-PROBLEM-STATE-CLASS -$cfg->setConfigEntry('peer_problem_state_class', 'ProblemPeerState'); +$cfg->setConfigEntry('peer_problem_state_class', 'Hub\State\Peer;\ProblemPeerState'); // CFG: PEER-CONNECTION-REFUSED-STATE-CLASS -$cfg->setConfigEntry('peer_connection_refused_state_class', 'ConnectionRefusedPeerState'); +$cfg->setConfigEntry('peer_connection_refused_state_class', 'Hub\State\Peer\ConnectionRefusedPeerState'); // CFG: PEER-CONNECTION-TIMED-OUT-STATE-CLASS -$cfg->setConfigEntry('peer_connection_timed_out_state_class', 'ConnectionTimedOutPeerState'); +$cfg->setConfigEntry('peer_connection_timed_out_state_class', 'Hub\State\Peer\ConnectionTimedOutPeerState'); // CFG: PEER-TRANSPORT-ENDPOINT-STATE-CLASS -$cfg->setConfigEntry('peer_transport_endpoint_state_class', 'TransportEndpointGonePeerState'); +$cfg->setConfigEntry('peer_transport_endpoint_state_class', 'Hub\State\Peer\TransportEndpointGonePeerState'); // CFG: PEER-OPERATION-ALREADY-PROGRESS-STATE-CLASS -$cfg->setConfigEntry('peer_operation_already_progress_state_class', 'OperationAlreadyProgressPeerState'); +$cfg->setConfigEntry('peer_operation_already_progress_state_class', 'Hub\State\Peer\OperationAlreadyProgressPeerState'); // CFG: PEER-NO-ROUTE-TO-HOST-STATE-CLASS -$cfg->setConfigEntry('peer_no_route_to_host_state_class', 'NoRouteToHostPeerState'); +$cfg->setConfigEntry('peer_no_route_to_host_state_class', 'Hub\State\Peer\NoRouteToHostPeerState'); /////////////////////////////////////////////////////////////////////////////// // DHT states diff --git a/application/hub/interfaces/class_HubInterface.php b/application/hub/interfaces/class_HubInterface.php index 9ba4ce718..68b7d2147 100644 --- a/application/hub/interfaces/class_HubInterface.php +++ b/application/hub/interfaces/class_HubInterface.php @@ -3,6 +3,7 @@ namespace Hub\Generic; // Import application-specific stuff +use Hub\Container\Socket\StorableSocket; // Inport frameworks stuff use CoreFramework\Generic\FrameworkInterface; @@ -82,4 +83,19 @@ interface HubInterface extends FrameworkInterface { */ function getSessionId (); + /** + * Setter for socket instance + * + * @param $socketInstance A StorableSocket instance + * @return void + */ + function setSocketInstance (StorableSocket $socketInstance); + + /** + * Getter for socket instance + * + * @return $socketInstance An instance of a StorableSocket class + */ + function getSocketInstance (); + } diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index bc02cb2b4..b217b0799 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -145,6 +145,14 @@ interface StorableSocket extends FrameworkInterface { */ function enableSocketOutOfBandData (); + /** + * Connects to socket recipient (supplied in package data array + * + * @return $result Result from calling socket_connect() + * @throws InvalidSocketException If stored socket is invalid + */ + function connectToSocketRecipient (); + /** * Getter for socket procotol field * @@ -152,6 +160,14 @@ interface StorableSocket extends FrameworkInterface { */ function getSocketProtocol (); + /** + * Getter for socket recipient array element + * + * @return $recipient Recipient array element + * @throws LogicException If 'recipient' array element is not found + */ + function getSocketRecipient (); + /** * Checks whether the given Universal Node Locator matches with the one from package data * @@ -227,6 +243,7 @@ interface StorableSocket extends FrameworkInterface { * * @return void * @throws SocketShutdownException If the current socket could not be shut down + * @throws BaseMethodCallException If this method is possibly called twice */ function doShutdown (); @@ -238,4 +255,13 @@ interface StorableSocket extends FrameworkInterface { */ function isValidConnectionType ($connectionType); + /** + * Clears last socket error + * + * @return void + * @throws InvalidSocketException If stored socket is invalid + * @throws BadMethodCallException If no socket error was reported but method called + */ + function clearLastSocketError (); + } diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index a5c805bad..be49b0561 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -47,20 +47,6 @@ interface ConnectionHelper extends HubHelper { */ function doShutdown (); - /** - * Getter for port number - * - * @return $port The port number - */ - function getConnectionPort (); - - /** - * Getter for IP address - * - * @return $address The IP address - */ - function getAddress (); - /** * Static "getter" for this connection class' name * diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index e6470884c..93c4fd0e5 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -3,7 +3,6 @@ namespace Hub\Listener; // Import application-specific stuff -use Hub\Container\Socket\StorableSocket; use Hub\Generic\HubInterface; /** @@ -80,19 +79,4 @@ interface Listenable extends HubInterface { */ function getPoolInstance (); - /** - * Setter for socket instance - * - * @param $socketInstance A StorableSocket instance - * @return void - */ - function setSocketInstance (StorableSocket $socketInstance); - - /** - * Getter for socket instance - * - * @return $socketInstance An instance of a StorableSocket class - */ - function getSocketInstance (); - } diff --git a/application/hub/interfaces/locator/class_LocateableNode.php b/application/hub/interfaces/locator/class_LocateableNode.php index 39a89bd7a..e7eb24c23 100644 --- a/application/hub/interfaces/locator/class_LocateableNode.php +++ b/application/hub/interfaces/locator/class_LocateableNode.php @@ -59,14 +59,28 @@ interface LocateableNode extends HubInterface { */ function getInternalUnl (); + /** + * Some "getter" for UNL address. + * + * @return $unlAddress Address part of UNL + */ + function getUnlAddress (); + /** * Some "getter" for UNL port (if supported). If not supported, NULL is * being returned. * - * @return $unlPort Port number of UNL + * @return $unlPort Port number of UNL or NULL */ function getUnlPort (); + /** + * Getter for UNL data array + * + * @return $unlData An array with UNL data + */ + function getUnlData (); + /** * Parses given UNL string as UNL array * diff --git a/core b/core index fd5598626..e9e524279 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit fd5598626e163040b19bf8e153d4898a49038b23 +Subproject commit e9e5242797adec674d25da4e641965f8d6dcbecd -- 2.39.5