*/
private $socketSelectTimeout = 0;
+ /**
+ * Package data instance
+ */
+ private $packageDataInstance = NULL;
+
/**
* Protected constructor
*
return $socketInstance;
}
+ /**
+ * Setter for package data instance
+ *
+ * @param $packageDataInstance An instance of a DeliverablePackage class
+ * @return void
+ */
+ public function setPackageDataInstance (DeliverablePackage $packageDataInstance) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Setting packageDataInstance=%s', strtoupper($this->getSocketProtocol()), $packageDataInstance));
+ $this->packageDataInstance = $packageDataInstance;
+ }
+
+ /**
+ * Getter for package data instance
+ *
+ * @return $packageDataInstance An instance of a DeliverablePackage class
+ */
+ public function getPackageDataInstance () {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Getting packageDataInstance=%s', strtoupper($this->getSocketProtocol()), $this->packageDataInstance));
+ return $this->packageDataInstance;
+ }
+
/**
* Checks whether the given Universal Node Locator matches with the one from package data
*
/**
* Find recipients for given package data and exclude the sender
*
- * @param $packageData An instance of a DeliverablePackage class
- * @return $recipients An indexed array with DHT recipients
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return $recipients An indexed array with DHT recipients
*/
public function getResultFromExcludedSender (DeliverablePackage $packageInstance) {
// Debug message
/**
* "Getter" for a LocalSearchCriteria from given package data's sender
*
- * @param $packageData Valid raw package data array
+ * @param $packageInstance An instance of a DeliverablePackage class
* @return $searchInstance An instance of a LocalSearchCriteria class
*/
private function getSenderSearchInstanceFromPackageInstance (DeliverablePackage $packageInstance) {
/**
* Checks whether given 'sender' is a new peer
*
- * @param $packageData An instance of a DeliverablePackage class
+ * @param $packageInstance An instance of a DeliverablePackage class
* @param $dataSetInstance An optional instance of a StoreableCriteria class
* @return $isNewPeer Whether 'sender' is a new peer to this peer
*/
public function isSenderNewPeer (DeliverablePackage $packageInstance, StoreableCriteria $dataSetInstance = NULL) {
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: packageData()=' . count($packageData) . ' - CALLED!');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: packageInstance=' . $packageInstance . ' - CALLED!');
// Get a search criteria instance from package data
- $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageData);
+ $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance);
// Is the dataset instance set?
if ($dataSetInstance instanceof StoreableCriteria) {
/**
* Registers a new peer with given package data. We use the session id from it.
*
- * @param $packageData An instance of a DeliverablePackage class
+ * @param $packageInstance An instance of a DeliverablePackage class
* @param $socketResource An instance of a StorableSocket class
* @return void
* @throws PeerAlreadyRegisteredException If a peer is already registered
*/
public function registerPeerByPackageData (DeliverablePackage $packageInstance, StorableSocket $socketInstance) {
// Make sure only new peers can be registered with package data
- if (!$this->isSenderNewPeer($packageData)) {
+ if (!$this->isSenderNewPeer($packageInstance)) {
// Throw an exception because this should normally not happen
- throw new PeerAlreadyRegisteredException(array($this, $packageData), self::EXCEPTION_PEER_ALREADY_REGISTERED);
+ throw new PeerAlreadyRegisteredException(array($this, $packageInstance), self::EXCEPTION_PEER_ALREADY_REGISTERED);
} // END - if
// Generate a dataset instance
/**
* Registers the given peer state and An instance of a DeliverablePackage class
*
- * @param $stateInstance A PeerStateable class instance
- * @param $packageData An instance of a DeliverablePackage class
+ * @param $stateInstance A PeerStateable class instance
+ * @param $packageInstance An instance of a DeliverablePackage class
* @return void
* @throws PeerAlreadyRegisteredException If a peer is already registered
* @todo Unfinished area
$dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $senderData[1]);
// Is this a new peer?
- if ($this->isSenderNewPeer($packageData, $dataSetInstance)) {
+ if ($this->isSenderNewPeer($packageInstance, $dataSetInstance)) {
// "Insert" the data set
$this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE));
} else {
* Checks whether a given peer state (in helper instance) is same as stored
* in database compared with the one from $helperInstance.
*
- * @param $helperInstance An instance of a ConnectionHelper class
- * @param $packageData An instance of a DeliverablePackage class
- * @return $isSamePeerState Whether the peer's state is the same
+ * @param $helperInstance An instance of a ConnectionHelper class
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return $isSamePeerState Whether the peer's state is the same
*/
public function isSamePeerState (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
// Now get the search instance from given package data
- $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageData);
+ $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance);
// With this search instance query the database for the peer and get a result instance
$resultInstance = $this->doSelectByCriteria($searchInstance);
$socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0);
// Get container from it
- $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_FILE, $packageInstance));
+ $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+ $socketResource,
+ StorableSocket::SOCKET_PROTOCOL_FILE,
+ $packageInstance,
+ ));
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketInstance[]=%s', gettype($socketInstance)));
// Create a streaming socket, of type TCP/IP
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- // Init fake package data with address/port from listener
- $packageData = array(
- StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
- StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
- StorableSocket::SOCKET_ARRAY_INDEX_TYPE => StorableSocket::CONNECTION_TYPE_SERVER,
- );
+ // Init fake "package" instance, the SocketContainer class requires this
+ $packageInstance = PackageDataFactory::createPackageDataInstance();
// Create socket instance
$socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
$socketResource,
StorableSocket::SOCKET_PROTOCOL_TCP,
- $packageData,
- NULL
+ $packageInstance,
));
+ // Set listener instance and type
+ $socketInstance->setListenerInstance($listenerInstance);
+ $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
+ /*
+ StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
+ StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
+ */
+
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
// Something bad happened
// Create a streaming socket, of type UDP
$socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- // Init fake package data with address/port from listener
- $packageData = array(
- StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
- StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
- StorableSocket::SOCKET_ARRAY_INDEX_TYPE => StorableSocket::CONNECTION_TYPE_SERVER,
- );
+ // Init fake package instance
+ $packageInstance = PackageDataFactory::createPackageDataInstance();
// Create socket instance
- $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_UDP, $packageData, NULL));
+ $socketInstance = self::createObjectByConfiguredName('socket_container_class', array(
+ $socketResource,
+ StorableSocket::SOCKET_PROTOCOL_UDP,
+ $packageInstance,
+ ));
+
+ // Set listener instance and socket type
+ $socketInstance->setListenerInstance($listenerInstance);
+ $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER);
+ /*
+ StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(),
+ StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(),
+ */
// Is the socket resource valid?
if (!$socketInstance->isValidSocket()) {
// Debugging:
//* DEBUG-DIE: */ $infoInstance->debugInstance();
- // Create a faked package data instance
- $packageInstance = PackageDataFactory::createPackageDataInstance();
-
// Set all required data
- $packageInstance->setSenderAddres($peerAddress . $peerSuffix);
- $packageInstance->setSenderPort($peerPort);
- $packageInstance->setRecipient($nodeInstance->getSessionId());
- $packageInstance->setStatus(NetworkPackageHandler::PACKAGE_STATUS_FAKED);
+ $socketInstance->setSenderAddres($peerAddress . $peerSuffix);
+ $socketInstance->setSenderPort($peerPort);
+ $socketInstance->setRecipient($nodeInstance->getSessionId());
+ $socketInstance->setStatus(NetworkPackageHandler::PACKAGE_STATUS_FAKED);
die(__METHOD__.': UNFINISHED!');
// Register the socket with the registry and with the faked array
/**
* Checks whether the listener would accept the given package data array
*
- * @param $packageData An instance of a DeliverablePackage class
+ * @param $packageInstance An instance of a DeliverablePackage class
* @return $accepts Whether this listener does accept
*/
public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) {
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: packageData()=%d - CALLED!', strtoupper($this->getProtocolName()), count($packageData)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER: packageInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $packageInstance));
// Check if same socket protocol
$socketProtocol = $this->getSocketInstance()->getSocketProtocol();
* @return void
*/
public function setSocketFile (SplFileInfo $socketFile) {
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Setting socketFile=%s ...', $socketFile));
$this->socketFile = $socketFile;
}
* @return void
*/
public function setSocketType ($socketType) {
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Setting socketType=%s ...', $socketType));
$this->socketType = $socketType;
}
* @return void
*/
public function setPackageContent ($packageContent) {
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Setting packageContent()=%d ...', strlen($packageContent)));
$this->packageContent = $packageContent;
}
* @return void
*/
public function setContentHash ($contentHash) {
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Setting contentHash()=%d ...', strlen($contentHash)));
$this->contentHash = $contentHash;
}
/**
* Checks whether the given package data is already processed by this fragmenter
*
- * @param $packageData An instance of a DeliverablePackage class array
+ * @param $packageInstance An instance of a DeliverablePackage class array
* @return $isProcessed Whether the package has been fragmented
*/
private function isPackageProcessed (DeliverablePackage $packageInstance) {
// Get array index
- $index = $this->getProcessedPackagesIndex($packageData);
+ $index = $this->getProcessedPackagesIndex($packageInstance);
// Is the array index there?
$isProcessed = (
/**
* Marks the given package data as processed by this fragmenter
*
- * @param $packageData An instance of a DeliverablePackage class array
+ * @param $packageInstance An instance of a DeliverablePackage class array
* @return void
*/
private function markPackageDataProcessed (DeliverablePackage $packageInstance) {
// Remember it (until we may remove it)
- $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = TRUE;
+ $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = TRUE;
}
/**
* Getter for final hash from given package data
*
- * @param $packageData An instance of a DeliverablePackage class array
+ * @param $packageInstance An instance of a DeliverablePackage class array
* @return $finalHash Final hash for package data
*/
private function getFinalHashFromPackageInstance (DeliverablePackage $packageInstance) {
// Make sure it is there
- assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageData)]));
+ assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)]));
// Return it
- return $this->processedPackages[$this->getProcessedPackagesIndex($packageData)];
+ return $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)];
}
/**
* to all chunks and prepends a chunk with all hashes only in it. It will
* return the final hash for faster processing of packages.
*
- * @param $packageData An instance of a DeliverablePackage class array
+ * @param $packageInstance An instance of a DeliverablePackage class array
* @param $helperInstance An instance of a ConnectionHelper class
* @return $finalHash Final hash for faster processing
* @todo $helperInstance is unused
*/
public function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance) {
// Is this package already fragmented?
- if (!$this->isPackageProcessed($packageData)) {
+ if (!$this->isPackageProcessed($packageInstance)) {
// First we need to "implode" the array
$rawData = implode(NetworkPackageHandler::PACKAGE_DATA_SEPARATOR, $packageInstance->getAllAsArray());
$finalHash = $this->generateHashFromRawData($rawData);
// Remember it
- $this->processedPackages[$this->getProcessedPackagesIndex($packageData)] = $finalHash;
+ $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash;
// Init pointer and reset serial number
$this->initPointer($finalHash);
$this->prependHashChunk($finalHash);
// Mark the package as fragmented
- $this->markPackageDataProcessed($packageData);
+ $this->markPackageDataProcessed($packageInstance);
} else {
// Get the final hash from the package data
- $finalHash = $this->getFinalHashFromPackageInstance($packageData);
+ $finalHash = $this->getFinalHashFromPackageInstance($packageInstance);
}
// Return final hash
* implementation will add more than one recipient to the list as a DHT is
* distributed and the package might go to more than one recipient.
*
- * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
- * @param $listInstance An instance of a Listable class
- * @param $packageData An instance of a DeliverablePackage class
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @param $packageInstance An instance of a DeliverablePackage class
* @return void
* @throws FrameworkException Could throw different exceptions depending on implementation
*/
$discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class');
// "Discover" recipients by given package data
- $recipients = $discoverInstance->resolveRecipientsByPackageData($packageData);
+ $recipients = $discoverInstance->resolveRecipientsByPackageData($packageInstance);
// Now "walk" through all elements and add them to the list
foreach ($recipients as $recipient) {
* Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
- * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
- * @param $listInstance An instance of a Listable class
- * @param $packageData An instance of a DeliverablePackage class
- * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
* @throws FrameworkException Could throw different exceptions depending on implementation
*/
public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
* Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
- * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
- * @param $listInstance An instance of a Listable class
- * @param $packageData An instance of a DeliverablePackage class
- * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
* @throws FrameworkException Could throw different exceptions depending on implementation
*/
public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {
* Tries to resolve given recipient into session ids or Universal Node Locator
* depending on implementation (hint: Template Method Pattern)
*
- * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
- * @param $listInstance An instance of a Listable class
- * @param $packageData An instance of a DeliverablePackage class
- * @return $resolved Resolved recipient or VOID if only the set list has been filled
+ * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+ * @param $listInstance An instance of a Listable class
+ * @param $packageInstance An instance of a DeliverablePackage class
+ * @return $resolved Resolved recipient or VOID if only the set list has been filled
* @throws FrameworkException Could throw different exceptions depending on implementation
*/
public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) {