namespace Hub\Generic;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Information\ShareableInfo;
use Hub\Listener\BaseListener;
use Hub\Network\Deliver\Deliverable;
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;
+ }
+
+ /**
+ * Handles socket error for given socket resource and peer data. This method
+ * validates $socketResource if it is a valid resource (see is_resource())
+ * but assumes valid data in array $recipientData, except that
+ * count($recipientData) is always 2.
+ *
+ * @param $method Value of __METHOD__ from calling method
+ * @param $line Value of __LINE__ from calling method
+ * @param $socketResource A valid socket resource
+ * @param $socketData A valid socket data array (0 = IP/file name, 1 = port)
+ * @return void
+ * @throws InvalidSocketException If $socketResource is no socket resource
+ * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back
+ * @todo Move all this socket-related stuff into own class, most of it resides in BaseListener
+ */
+ protected final function handleSocketError ($method, $line, $socketResource, array $socketData) {
+ // This method handles only socket resources
+ if (!is_resource($socketResource)) {
+ // No resource, abort here
+ throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
+ // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number
+ //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, true));
+ assert(isset($socketData[0]));
+ assert(isset($socketData[1]));
+
+ // Get error code for first validation (0 is not an error)
+ $errorCode = socket_last_error($socketResource);
+
+ // If the error code is zero, someone called this method without an error
+ if ($errorCode == 0) {
+ // No error detected (or previously cleared outside this method)
+ throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR);
+ } // END - if
+
+ // Get handler (method) name
+ $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
+
+ // Call-back the error handler method
+ call_user_func_array(array($this, $handlerName), array($socketResource, $socketData));
+
+ // Finally clear the error because it has been handled
+ socket_clear_error($socketResource);
+ }
+
/**
* Setter for network package handler instance
*
return $this->listenerInstance;
}
- /**
- * Handles socket error for given socket resource and peer data. This method
- * validates $socketResource if it is a valid resource (see is_resource())
- * but assumes valid data in array $recipientData, except that
- * count($recipientData) is always 2.
- *
- * @param $method Value of __METHOD__ from calling method
- * @param $line Value of __LINE__ from calling method
- * @param $socketResource A valid socket resource
- * @param $socketData A valid socket data array (0 = IP/file name, 1 = port)
- * @return void
- * @throws InvalidSocketException If $socketResource is no socket resource
- * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back
- * @todo Move all this socket-related stuff into own class, most of it resides in BaseListener
- */
- protected final function handleSocketError ($method, $line, $socketResource, array $socketData) {
- // This method handles only socket resources
- if (!is_resource($socketResource)) {
- // No resource, abort here
- throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
- } // END - if
-
- // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number
- //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, true));
- assert(isset($socketData[0]));
- assert(isset($socketData[1]));
-
- // Get error code for first validation (0 is not an error)
- $errorCode = socket_last_error($socketResource);
-
- // If the error code is zero, someone called this method without an error
- if ($errorCode == 0) {
- // No error detected (or previously cleared outside this method)
- throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR);
- } // END - if
-
- // Get handler (method) name
- $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
-
- // Call-back the error handler method
- call_user_func_array(array($this, $handlerName), array($socketResource, $socketData));
-
- // Finally clear the error because it has been handled
- socket_clear_error($socketResource);
- }
-
}
use CoreFramework\Criteria\Storing\StoreableCriteria;
use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Handler\DataSet\HandleableDataSet;
use CoreFramework\Registry\Registerable;
/**
// Import framework stuff
use CoreFramework\Factory\Database\Wrapper\DatabaseWrapperFactory;
use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Handler\DataSet\HandleableDataSet;
use CoreFramework\Registry\Registerable;
/**
// Return filled array
return $recipients;
}
-}
-// [EOF]
-?>
+}
namespace Hub\Handler\Network\Socket\RawData;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
/**
namespace Hub\Handler\Network\RawData\Tcp;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
use Hub\Pool\BasePool;
namespace Hub\Handler\RawData\Udp;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
use Hub\Pool\BasePool;
namespace Hub\Handler\RawData;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
/**
<?php
// Own namespace
-namespace Hub\Handler\Raw;
+namespace Hub\Handler\RawData;
// Import application-specific stuff
use Hub\Network\Package\NetworkPackage;
namespace Hub\Listener;
// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Helper\Connection\BaseConnectionHelper;
use Hub\Network\Package\NetworkPackage;
use Hub\Pool\Peer\PoolablePeer;
} // END - if
// Get the current value
- $currentSocket = $this->getIteratorInstance()->current();
+ $currentSocketData = $this->getIteratorInstance()->current();
// Handle it here, if not main server socket
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
- if (($currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) {
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: currentSocketData=' . $currentSocketData[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
+ if (($currentSocketData[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocketData[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
- $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
+ $this->getHandlerInstance()->processRawDataFromResource($currentSocketData);
} // END - if
// Advance to next entry. This should be the last line.
}
} // END - foreac
}
+
}
// Import hub-specific stuff
use Hub\Generic\BaseHubSystem;
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Network\Package\NetworkPackage;
use Hub\Network\Receive\Receivable;
use Hub\Factory\Dht\DhtObjectFactory;
use Hub\Factory\Node\NodeObjectFactory;
use Hub\Generic\BaseHubSystem;
+use Hub\Handler\RawData\BaseRawDataHandler;
use Hub\Helper\Connection\BaseConnectionHelper;
use Hub\Helper\Connection\ConnectionHelper;
use Hub\Helper\HubHelper;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
// Own namespace
namespace Hub\State\Peer;
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
// Import framework stuff
use CoreFramework\State\Stateable;
<?php
// Own namespace
-namespace Hub\Stream\Input\Raw;
+namespace Hub\Stream\Input\RawData;
// Import hub-specific stuff
use Hub\Generic\BaseHubSystem;
<?php
+// Own namespace
+namespace Hub\Stream\Output\RawData;
+
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
/**
* A RawDataOutputStream class
*
$cfg->setConfigEntry('network_listen_iterator_class', 'NetworkListenIterator');
// CFG: SOCKET-LISTEN-ITERATOR-CLASS
-$cfg->setConfigEntry('socket_listen_iterator_class', 'DefaultIterator');
+$cfg->setConfigEntry('socket_listen_iterator_class', 'CoreFramework\Iterator\DefaultIterator');
// CFG: TCP-RAW-DATA-HANDLER-CLASS
$cfg->setConfigEntry('tcp_raw_data_handler_class', 'TcpRawDataHandler');
$cfg->setConfigEntry('udp_raw_data_handler_class', 'UdpRawDataHandler');
// CFG: SOCKET-RAW-DATA-HANDLER-CLASS
-$cfg->setConfigEntry('socket_raw_data_handler_class', 'SocketRawDataHandler');
+$cfg->setConfigEntry('socket_raw_data_handler_class', 'Hub\Handler\Network\Socket\RawData\SocketRawDataHandler');
// CFG: SHUTDOWN-LISTENER-POOL-VISITOR-CLASS
$cfg->setConfigEntry('shutdown_listener_pool_visitor_class', 'ShutdownListenerPoolVisitor');
$cfg->setConfigEntry('raw_data_stacker_class', 'FiLoStacker');
// CFG: MULTIPLE-MESSAGE-STACKER-CLASS
-$cfg->setConfigEntry('multiple_message_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('multiple_message_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: NODE-ANNOUNCEMENT-ANSWER-TEMPLATE-TYPE
$cfg->setConfigEntry('node_announcement_answer_template_type', 'xml/answer/announcement');
$cfg->setConfigEntry('raw_template_extension', '.xml');
// CFG: PACKAGE-STACKER-CLASS
-$cfg->setConfigEntry('network_package_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('network_package_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: NODE-RAW-DATA-STACKER-CLASS
-$cfg->setConfigEntry('node_raw_data_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('node_raw_data_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: CHUNK-HANDLER-STACKER-CLASS
-$cfg->setConfigEntry('chunk_handler_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('chunk_handler_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: DHT-BOOTSTRAP-STACKER-CLASS
-$cfg->setConfigEntry('dht_bootstrap_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('dht_bootstrap_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: DHT-PUBLISH-STACKER-CLASS
-$cfg->setConfigEntry('dht_publish_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('dht_publish_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: PRODUCER-OUTGOING-QUEUE
-$cfg->setConfigEntry('producer_outgoing_queue', 'FiFoStacker');
+$cfg->setConfigEntry('producer_outgoing_queue', 'CoreFramework\Stacker\FiFoStacker');
// CFG: PRODUCER-INCOMING-QUEUE
-$cfg->setConfigEntry('producer_incoming_queue', 'FiFoStacker');
+$cfg->setConfigEntry('producer_incoming_queue', 'CoreFramework\Stacker\FiFoStacker');
// CFG: STACKER-NODE-ANNOUNCEMENT-MAX-SIZE
$cfg->setConfigEntry('stacker_node_announcement_max_size', 20);
$cfg->setConfigEntry('monitor_pool_iterator_class', 'MonitorPoolIterator');
// CFG: QUERY-ITERATOR-CLASS
-$cfg->setConfigEntry('query_iterator_class', 'DefaultIterator');
+$cfg->setConfigEntry('query_iterator_class', 'CoreFramework\Iterator\DefaultIterator');
// CFG: NODE-PING-ITERATOR-CLASS
$cfg->setConfigEntry('node_ping_iterator_class', 'HubPingIterator');
$cfg->setConfigEntry('miner_default_mode', 'coin');
// CFG: MINER-BUFFER-STACKER-CLASS
-$cfg->setConfigEntry('miner_buffer_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('miner_buffer_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: HUB-CONSOLE-CMD-CRUNCHER-RESOLVER-CLASS
$cfg->setConfigEntry('hub_console_cmd_miner_resolver_class', 'Hub\Resolver\Command\HubConsoleCommandResolver');
$cfg->setConfigEntry('cruncher_default_mode', 'mcrypt');
// CFG: CRUNCHER-BUFFER-STACKER-CLASS
-$cfg->setConfigEntry('cruncher_buffer_stacker_class', 'FiFoStacker');
+$cfg->setConfigEntry('cruncher_buffer_stacker_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: HUB-CONSOLE-CMD-CRUNCHER-RESOLVER-CLASS
$cfg->setConfigEntry('hub_console_cmd_cruncher_resolver_class', 'Hub\Resolver\Command\HubConsoleCommandResolver');
$cfg->setConfigEntry('crawler_node_communicator_task_class', 'CrawlerNodeCommunicatorTask');
// CFG: CRAWLER-URL-LOCAL-START-STACK-CLASS
-$cfg->setConfigEntry('crawler_url_local_start_stack_class', 'FiFoFileStack');
+$cfg->setConfigEntry('crawler_url_local_start_stack_class', 'CoreFramework\Stack\Filesystem\FiFoFileStack');
// CFG: CRAWLER-URL-UPLOADED-LIST-STACK-CLASS
-$cfg->setConfigEntry('crawler_url_uploaded_list_stack_class', 'FiFoFileStack');
+$cfg->setConfigEntry('crawler_url_uploaded_list_stack_class', 'CoreFramework\Stack\Filesystem\FiFoFileStack');
// CFG: CRAWLER-URL-RSS-START-STACK-CLASS
-$cfg->setConfigEntry('crawler_url_rss_start_stack_class', 'FiFoFileStack');
+$cfg->setConfigEntry('crawler_url_rss_start_stack_class', 'CoreFramework\Stack\Filesystem\FiFoFileStack');
// CFG: CRAWLER-URL-FOUND-RSS-STACK-CLASS
-$cfg->setConfigEntry('crawler_url_found_rss_stack_class', 'FiFoFileStack');
+$cfg->setConfigEntry('crawler_url_found_rss_stack_class', 'CoreFramework\Stack\Filesystem\FiFoFileStack');
// CFG: CRAWLER-URL-LOCAL-START-FILE-STACK-INDEX-CLASS
-$cfg->setConfigEntry('crawler_url_local_start_file_stack_index_class', 'FileStackIndex');
+$cfg->setConfigEntry('crawler_url_local_start_file_stack_index_class', 'CoreFramework\Index\Stack\FileStackIndex');
// CFG: CRAWLER-URL-UPLOADED-LIST-FILE-STACK-INDEX-CLASS
-$cfg->setConfigEntry('crawler_url_uploaded_list_file_stack_index_class', 'FileStackIndex');
+$cfg->setConfigEntry('crawler_url_uploaded_list_file_stack_index_class', 'CoreFramework\Index\Stack\FileStackIndex');
// CFG: CRAWLER-URL-RSS-START-FILE-STACK-INDEX-CLASS
-$cfg->setConfigEntry('crawler_url_rss_start_file_stack_index_class', 'FileStackIndex');
+$cfg->setConfigEntry('crawler_url_rss_start_file_stack_index_class', 'CoreFramework\Index\Stack\FileStackIndex');
// CFG: CRAWLER-URL-FOUND-RSS-FILE-STACK-INDEX-CLASS
-$cfg->setConfigEntry('crawler_url_found_rss_file_stack_index_class', 'FileStackIndex');
+$cfg->setConfigEntry('crawler_url_found_rss_file_stack_index_class', 'CoreFramework\Index\Stack\FileStackIndex');
// CFG: CRAWLER-URL-UPLOADED-LIST-URL-SOURCE-STACK-CLASS
-$cfg->setConfigEntry('crawler_uploaded_list_url_source_stack_class', 'FiFoStacker');
+$cfg->setConfigEntry('crawler_uploaded_list_url_source_stack_class', 'CoreFramework\Stacker\FiFoStacker');
// CFG: STACKER-CSV-FILE-MAX-SIZE
$cfg->setConfigEntry('stacker_csv_file_max_size', 10);
<?php
+// Own namespace
+namespace Hub\Handler\Network\PackageCode;
+
+// Import application-specific stuff
+use Hub\Handler\RawData\BaseRawDataHandler;
+
/**
* This exception is thrown when an unexpected package status was detected.
*
// Import framework stuff
use CoreFramework\Criteria\Local\LocalSearchCriteria;
use CoreFramework\Database\Frontend\DatabaseWrapper;
+use CoreFramework\Handler\DataSet\HandleableDataSet;
/**
* An interface for distributed hash tables for nodes
<?php
+// Own namespace
+namespace Hub\Dht\Node;
+
+// Import framework stuff
+use CoreFramework\Handler\DataSet\HandleableDataSet;
+
/**
* An interface for DHTs
*
// Import framework stuff
use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Handler\DataSet\HandleableDataSet;
/**
* A HandleableAnswerStatus interface
<?php
+// Own namespace
+namespace Hub\Handler\RawData\Chunks;
+
+// Import framework stuff
+use CoreFramework\Handler\Handleable;
+
/**
* An interface for chunk handlers
*
// Import application-specific stuff
use Hub\Network\Receive\Receivable;
+// Import framework stuff
+use CoreFramework\Handler\DataSet\HandleableDataSet;
+
/**
* An interface for message handlers
*
// Own namespace
namespace Hub\Network;
+// Import framework stuff
+use CoreFramework\Handler\DataSet\HandleableDataSet;
+
/**
* A Networkable interface
*
* Processes raw data from given resource. This is mostly useful for TCP
* package handling and is implemented in the TcpListener class
*
- * @param $resourceArray A valid socket resource array
+ * @param $socketData A valid socket resource array
* @return void
* @throws InvalidResourceException If the given resource is invalid
*/
- function processRawDataFromResource (array $resourceArray);
+ function processRawDataFromResource (array $socketData);
/**
* Checks whether decoded data is pending for further processing.
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Protocol;
+
+// Import framework stuff
+use CoreFramework\Handler\Handleable;
+
+/**
+ * An interface for protocol handlers
+ *
+ * @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/>.
+ */
+interface HandleableProtocol extends Handleable {
+ /**
+ * Getter for port number to satify HandleableProtocol
+ *
+ * @return $port The port number
+ */
+ function getPort ();
+
+ /**
+ * Getter for protocol name
+ *
+ * @return $protocol Name of used protocol
+ */
+ function getProtocolName ();
+
+ /**
+ * 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
+ */
+ function isValidUniversalNodeLocatorByPackageData (array $packageData);
+
+ /**
+ * If the found UNL (address) matches own external or internal address
+ *
+ * @param $unl UNL to test
+ * @return $ifMatches Whether the found UNL matches own addresss
+ */
+ function isOwnAddress ($unl);
+
+}
-Subproject commit 197d364f62d39e6f731ff62001ac6cafccc0d9cc
+Subproject commit 001f7ff82c38dcd58d652ca8acf272716f3f0f04