// CFG: DHT-STACKER-CLASS
$cfg->setConfigEntry('dht_stacker_class', 'FiLoStacker');
+// CFG: RAW-DATA-STACKER-CLASS
+$cfg->setConfigEntry('raw_data_stacker_class', 'FiFoStacker');
+
// CFG: NODE-ANNOUNCEMENT-ANSWER-TEMPLATE-TYPE
$cfg->setConfigEntry('node_announcement_answer_template_type', 'xml/answer/announcement');
// CFG: STACKER-RAW-DATA-MAX-SIZE
$cfg->setConfigEntry('stacker_raw_data_max_size', 100);
+// CFG: STACKER-OUTGOING-STREAM-MAX-SIZE
+$cfg->setConfigEntry('stacker_outgoing_stream_max_size', 100);
+
// CFG: STACKER-FINAL-CHUNKS-MAX-SIZE
$cfg->setConfigEntry('stacker_final_chunks_max_size', 100);
// CFG: NODE-ACTIVE-STATE-CLASS
$cfg->setConfigEntry('node_active_state_class', 'NodeActiveState');
-// CFG: NODE-ANNOUNCED-STATE-CLASS
-$cfg->setConfigEntry('node_announced_state_class', 'NodeAnnouncedState');
+// CFG: NODE-ANNOUNCING-STATE-CLASS
+$cfg->setConfigEntry('node_announcing_state_class', 'NodeAnnouncingState');
// CFG: NODE-REACHABLE-STATE-CLASS
$cfg->setConfigEntry('node_reachable_state_class', 'NodeReachableState');
* Sends raw package data to the recipient
*
* @param $packageData Raw package data
- * @return $totalSentBytes Total sent bytes to the peer
+ * @return void
* @throws InvalidSocketException If we got a problem with this socket
*/
function sendRawPackageData (array $packageData);
* @throws SocketShutdownException If the current socket could not be shut down
*/
function doShutdown ();
+
+ /**
+ * Getter for port number to satify ProtocolHandler
+ *
+ * @return $port The port number
+ */
+ function getPort ();
+
+ /**
+ * Getter for protocol
+ *
+ * @return $protocol Used protocol
+ */
+ function getProtocol ();
+
+ /**
+ * Getter for IP address
+ *
+ * @return $address The IP address
+ */
+ function getAddress ();
+
+ /**
+ * Static "getter" for this connection class' name
+ *
+ * @param $address IP address
+ * @param $port Port number
+ * @param $className Original class name
+ * @return $class Expanded class name
+ */
+ static function getConnectionClassName ($address, $port, $className);
+
+ /**
+ * Getter for shuttedDown
+ *
+ * @return $shuttedDown Whether this connection is shutted down
+ */
+ function isShuttedDown ();
}
// [EOF]
*/
function isPackageWaitingForDelivery ();
+ /**
+ * Checks whether encoded (raw) data is pending
+ *
+ * @return $isPending Whether encoded data is pending
+ */
+ function isEncodedDataPending ();
+
/**
* Delivers an enqueued package to the stated destination. If a non-session
* id is provided, recipient resolver is being asked (and instanced once).
*/
function sendWaitingPackage ();
+ /**
+ * Sends pending encoded (raw) data
+ *
+ * @return void
+ */
+ function sendEncodedData ();
+
/**
* Clears all stacks
*
*/
private $sentData = 0;
- /**
- * Difference
- */
- private $diff = 0;
-
/**
* Whether this connection is initialized
*/
// Call parent constructor
parent::__construct($className);
+ // Init state which sets the state to 'init'
+ $this->initState();
+
// Initialize output stream
$streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_output_stream_class');
// And add it to this connection helper
$this->setOutputStreamInstance($streamInstance);
- // Init state which sets the state to 'init'
- $this->initState();
+ // Get package instance from factory
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // ... and set it here
+ $this->setPackageInstance($packageInstance);
// Register this connection helper
Registry::getRegistry()->addInstance('connection', $this);
* Sends raw package data to the recipient
*
* @param $packageData Raw package data
- * @return $totalSentBytes Total sent bytes to the peer
+ * @return void
* @throws InvalidSocketException If we got a problem with this socket
*/
public function sendRawPackageData (array $packageData) {
// Implode the package data array and fragement the resulting string, returns the final hash
$finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageData, $this);
+
+ // Is the final hash set?
if ($finalHash !== TRUE) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Setting finalHash=' . $finalHash . ',currentFinalHash[' . gettype($this->currentFinalHash) . ']=' . $this->currentFinalHash);
// Reset serial number
$this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
- // Cache buffer length
- $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
-
// Init variables
$rawData = '';
$dataStream = ' ';
- $totalSentBytes = 0;
// Fill sending buffer with data
while (strlen($dataStream) > 0) {
// Nothing to sent is bad news, so assert on it
assert(strlen($rawData) > 0);
+ // Calculate buffer size
+ $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
+
// Encode the raw data with our output-stream
$encodedData = $this->getOutputStreamInstance()->streamData($rawData);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: rawData()=' . strlen($rawData) . ',encodedData()=' . strlen($encodedData));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: socketResource[]=' . gettype($this->getSocketResource()) . PHP_EOL);
+
+ // Init array
+ $encodedDataArray = array(
+ NetworkPackage::RAW_FINAL_HASH_INDEX => $this->currentFinalHash,
+ NetworkPackage::RAW_ENCODED_DATA_INDEX => $encodedData,
+ NetworkPackage::RAW_SENT_BYTES_INDEX => 0,
+ NetworkPackage::RAW_SOCKET_INDEX => $this->getSocketResource(),
+ NetworkPackage::RAW_BUFFER_SIZE_INDEX => $bufferSize,
+ NetworkPackage::RAW_DIFF_INDEX => 0
+ );
// Calculate difference
- $this->diff = $bufferSize - strlen($encodedData);
-
- // Get socket resource
- $socketResource = $this->getSocketResource();
-
- // Init sent bytes
- $sentBytes = 0;
-
- // Deliver all data
- while ($sentBytes !== FALSE) {
- // And deliver it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
-
- if ($this->diff >= 0) {
- // Send all out (encodedData is smaller than or equal buffer size)
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedData, 0, ($bufferSize - $this->diff))));
- $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
- } else {
- // Send buffer size out
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedData, 0, $bufferSize)));
- $sentBytes = socket_write($socketResource, $encodedData, $bufferSize);
- }
-
- // If there was an error, we don't continue here
- if ($sentBytes === FALSE) {
- // Handle the error with a faked recipientData array
- $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
-
- // And throw it
- throw new InvalidSocketException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
- } elseif (($sentBytes == 0) && (strlen($encodedData) > 0)) {
- // Nothing sent means we are done
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
- break;
- }
-
- // The difference between sent bytes and length of raw data should not go below zero
- assert((strlen($encodedData) - $sentBytes) >= 0);
-
- // Add total sent bytes
- $totalSentBytes += $sentBytes;
-
- // Cut out the last unsent bytes
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...');
- $encodedData = substr($encodedData, $sentBytes);
-
- // Calculate difference again
- $this->diff = $bufferSize - strlen($encodedData);
-
- // Can we abort?
- if (strlen($encodedData) <= 0) {
- // Abort here, all sent!
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
- break;
- } // END - if
- } // END - while
+ $diff = $encodedDataArray[NetworkPackage::RAW_BUFFER_SIZE_INDEX] - strlen($encodedDataArray[NetworkPackage::RAW_ENCODED_DATA_INDEX]);
- // Return sent bytes
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: totalSentBytes=' . $totalSentBytes . ',diff=' . $this->diff);
- return $totalSentBytes;
+ // Push raw data to the package's outgoing stack
+ $this->getPackageInstance()->getStackerInstance()->pushNamed(NetworkPackage::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
}
/**
throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
} // END - if
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Setting socket resource ... (' . gettype($socketResource) . ')');
+
// Set the resource
$helperInstance->setSocketResource($socketResource);
$helperInstance->sendPackage($this);
// Change the state, this should be the last line except debug output
- $this->getStateInstance()->nodeAnnouncedToUpperHubs();
+ $this->getStateInstance()->nodeAnnouncingToUpperHubs();
// Debug output
self::createDebugInstance(__CLASS__)->debugOutput('HUB-Announcement: FINISHED');
const STACKER_NAME_PROCESSED_MESSAGE = 'package_processed_message';
/**************************************************************************
- * Stacker for other/internal purposes *
+ * Stacker for raw data handling *
**************************************************************************/
/**
- * Stacker name for "back-buffered" packages
+ * Stacker for outgoing data stream
*/
- const STACKER_NAME_BACK_BUFFER = 'package_backbuffer';
+ const STACKER_NAME_OUTGOING_STREAM = 'outgoing_stream';
+
+ /**
+ * Array index for final hash
+ */
+ const RAW_FINAL_HASH_INDEX = 'hash';
+
+ /**
+ * Array index for encoded data
+ */
+ const RAW_ENCODED_DATA_INDEX = 'data';
+
+ /**
+ * Array index for sent bytes
+ */
+ const RAW_SENT_BYTES_INDEX = 'sent';
+
+ /**
+ * Array index for socket resource
+ */
+ const RAW_SOCKET_INDEX = 'socket';
+
+ /**
+ * Array index for buffer size
+ */
+ const RAW_BUFFER_SIZE_INDEX = 'buffer';
+
+ /**
+ * Array index for diff between buffer and sent bytes
+ */
+ const RAW_DIFF_INDEX = 'diff';
/**************************************************************************
* Protocol names *
self::STACKER_NAME_DECODED_CHUNKED,
self::STACKER_NAME_NEW_MESSAGE,
self::STACKER_NAME_PROCESSED_MESSAGE,
- self::STACKER_NAME_BACK_BUFFER
+ self::STACKER_NAME_OUTGOING_STREAM
), $forceReInit);
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: stateInstance=' . $helperInstance->getStateInstance());
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
- // Is it not there?
- if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
- // The socket needs to be put in a special registry that can handle such data
- $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
+ // The socket needs to be put in a special registry that can handle such data
+ $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
- // Get the connection helper from registry
- $helperInstance = Registry::getRegistry()->getInstance('connection');
+ // Get the connection helper from registry
+ $helperInstance = Registry::getRegistry()->getInstance('connection');
- // And make sure it is valid
- assert($helperInstance instanceof ConnectionHelper);
+ // And make sure it is valid
+ assert($helperInstance instanceof ConnectionHelper);
+ // Is it not there?
+ if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Registering socket ' . $socketResource . ' ...');
} // END - if
// Sent out package data
- $sentBytes = $helperInstance->sendRawPackageData($packageData);
-
- // Remember unsent raw bytes in back-buffer, if any
- $this->storeUnsentBytesInBackBuffer($packageData, $sentBytes);
+ $helperInstance->sendRawPackageData($packageData);
}
/**
return $isWaitingDelivery;
}
+ /**
+ * Checks whether encoded (raw) data is pending
+ *
+ * @return $isPending Whether encoded data is pending
+ */
+ public function isEncodedDataPending () {
+ // Check whether the stacker is not empty
+ $isPending = (($this->getStackerInstance()->isStackInitialized(self::STACKER_NAME_OUTGOING_STREAM)) && (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_OUTGOING_STREAM)));
+
+ // Return the result
+ return $isPending;
+ }
+
/**
* Delivers an enqueued package to the stated destination. If a non-session
* id is provided, recipient resolver is being asked (and instanced once).
* @return void
*/
public function sendWaitingPackage () {
- // Send any waiting bytes in the back-buffer before sending a new package
- $this->sendBackBufferBytes();
-
// Sanity check if we have packages waiting for delivery
if (!$this->isPackageWaitingForDelivery()) {
// This is not fatal but should be avoided
}
}
+ /**
+ * Sends out encoded data to a socket
+ *
+ * @return void
+ */
+ public function sendEncodedData () {
+ // Make sure there is pending encoded data
+ assert($this->isEncodedDataPending());
+
+ // Pop current data from stack
+ $encodedDataArray = $this->getStackerInstance()->popNamed(self::STACKER_NAME_OUTGOING_STREAM);
+
+ // Init in this round sent bytes
+ $sentBytes = 0;
+
+ // Assert on socket
+ assert(is_resource($encodedDataArray[self::RAW_SOCKET_INDEX]));
+
+ // And deliver it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sending out ' . strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) . ' bytes,rawBufferSize=' . $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] . ',diff=' . $encodedDataArray[self::RAW_DIFF_INDEX]);
+ if ($encodedDataArray[self::RAW_DIFF_INDEX] >= 0) {
+ // Send all out (encodedData is smaller than or equal buffer size)
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedDataArray[self::RAW_ENCODED_DATA_INDEX], 0, ($encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - $encodedDataArray[self::RAW_DIFF_INDEX]))));
+ $sentBytes = socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], ($encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - $encodedDataArray[self::RAW_DIFF_INDEX]));
+ } else {
+ // Send buffer size out
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedDataArray[self::RAW_ENCODED_DATA_INDEX], 0, $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX])));
+ $sentBytes = socket_write($encodedDataArray[self::RAW_SOCKET_INDEX], $encodedDataArray[self::RAW_ENCODED_DATA_INDEX], $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX]);
+ }
+
+ // If there was an error, we don't continue here
+ if ($sentBytes === FALSE) {
+ // Handle the error with a faked recipientData array
+ $this->handleSocketError(__METHOD__, __LINE__, $encodedDataArray[self::RAW_SOCKET_INDEX], array('0.0.0.0', '0'));
+
+ // And throw it
+ throw new InvalidSocketException(array($this, $encodedDataArray[self::RAW_SOCKET_INDEX], $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } elseif (($sentBytes === 0) && (strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) > 0)) {
+ // Nothing sent means we are done
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
+ return;
+ } else {
+ // The difference between sent bytes and length of raw data should not go below zero
+ assert((strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) - $sentBytes) >= 0);
+
+ // Add total sent bytes
+ $encodedDataArray[self::RAW_SENT_BYTES_INDEX] += $sentBytes;
+
+ // Cut out the last unsent bytes
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sent out ' . $sentBytes . ' of ' . strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) . ' bytes ...');
+ $encodedDataArray[self::RAW_ENCODED_DATA_INDEX] = substr($encodedDataArray[self::RAW_ENCODED_DATA_INDEX], $sentBytes);
+
+ // Calculate difference again
+ $encodedDataArray[self::RAW_DIFF_INDEX] = $encodedDataArray[self::RAW_BUFFER_SIZE_INDEX] - strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]);
+
+ // Can we abort?
+ if (strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) <= 0) {
+ // Abort here, all sent!
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
+ return;
+ } // END - if
+ }
+
+ // Push array back in stack
+ $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray);
+ }
+
///////////////////////////////////////////////////////////////////////////
// Receiving packages / raw data
///////////////////////////////////////////////////////////////////////////
*
* @return void
*/
- public function nodeAnnouncedToUpperHubs () {
+ public function nodeAnnouncingToUpperHubs () {
// Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('announced', $this->getNodeInstance());
+ NodeStateFactory::createNodeStateInstanceByName('announcing', $this->getNodeInstance());
}
/**
+++ /dev/null
-<?php
-/**
- * A Announced node state class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class NodeAnnouncedState extends BaseNodeState implements Stateable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set state name
- $this->setStateName('announced');
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance An instance of a NodeHelper class
- * @return $stateInstance An instance of a Stateable class
- */
- public static final function createNodeAnnouncedState (NodeHelper $nodeInstance) {
- // Get new instance
- $stateInstance = new NodeAnnouncedState();
-
- // Set the node instance
- $stateInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $stateInstance;
- }
-
- /**
- * Changes the state if the announcement (to bootstrap node) was
- * successful.
- *
- * @return void
- */
- public function nodeAnnouncementSuccessful () {
- // The node's announcement was successful
- NodeStateFactory::createNodeStateInstanceByName('announcement_completed', $this->getNodeInstance());
- }
-}
-
-// [EOF]
-?>
--- /dev/null
+<?php
+/**
+ * A Announcing node state class
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NodeAnnouncingState extends BaseNodeState implements Stateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set state name
+ $this->setStateName('announcing');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance An instance of a NodeHelper class
+ * @return $stateInstance An instance of a Stateable class
+ */
+ public static final function createNodeAnnouncingState (NodeHelper $nodeInstance) {
+ // Get new instance
+ $stateInstance = new NodeAnnouncingState();
+
+ // Set the node instance
+ $stateInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+
+ /**
+ * Changes the state if the announcement (to bootstrap node) was
+ * successful.
+ *
+ * @return void
+ */
+ public function nodeAnnouncementSuccessful () {
+ // The node's announcement was successful
+ NodeStateFactory::createNodeStateInstanceByName('announcement_completed', $this->getNodeInstance());
+ }
+}
+
+// [EOF]
+?>
}
/**
- * Validates whether the state is 'active' or 'announced' or throws an
+ * Validates whether the state is 'active' or 'announcing' or throws an
* exception if it is every other state.
*
* @return void
- * @throws InvalidStateException If the state is not 'active' and not 'announced'
+ * @throws InvalidStateException If the state is not 'active' and not 'announcing'
*/
public function validateNodeStateIsActiveOrAnnounced () {
// Just compare it...
* exception if it is every other state.
*
* @return void
- * @throws InvalidStateException If the state is not 'active' and not 'announced'
+ * @throws InvalidStateException If the state is not 'active' and not 'announcing'
*/
public function validateNodeStateIsAnnouncementCompleted () {
// Just compare it...
*
* @return void
*/
- public function nodeAnnouncedToUpperHubs () {
+ public function nodeAnnouncingToUpperHubs () {
// Create the new state instance
- NodeStateFactory::createNodeStateInstanceByName('announced', $this->getNodeInstance());
+ NodeStateFactory::createNodeStateInstanceByName('announcing', $this->getNodeInstance());
}
}
$packageInstance = $this->getPackageInstance();
// Do we have something to deliver?
- if ($packageInstance->isPackageWaitingForDelivery()) {
+ if ($packageInstance->isEncodedDataPending()) {
+ // Sent encoded (raw) data
+ $packageInstance->sendEncodedData();
+ } elseif ($packageInstance->isPackageWaitingForDelivery()) {
// Sent it finally out
$packageInstance->sendWaitingPackage();
} elseif ($packageInstance->isPackageDeclared()) {