* @return void
*/
function doSelfConnection (Taskable $taskInstance);
+
+ /**
+ * "Getter for address:port combination
+ *
+ * @param $handlerInstance A valid Networkable instance
+ * @return $addressPort A address:port combination for this node
+ */
+ function getAddressPort (Networkable $handlerInstance);
}
// [EOF]
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('!!!');
}
/**
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseHandler extends BaseHubSystem {
+ /**
+ * Handler name
+ */
+ private $handlerName = 'invalid';
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * Getter for handler name
+ *
+ * @return $handlerName Name of this handler
+ */
+ public final function getHandlerName () {
+ return $this->handlerName;
+ }
+
+ /**
+ * Setter for handler name
+ *
+ * @param $handlerName Name of this handler
+ * @return void
+ */
+ protected final function setHandlerName ($handlerName) {
+ $this->handlerName = $handlerName;
+ }
}
// [EOF]
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('!!!');
}
/**
*/
class BaseNetworkPackageHandler extends BaseHandler {
// Error codes
- const SOCKET_ERROR_UNKNOWN = 'unknown_error';
- const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint';
- const SOCKET_ERROR_UNHANDLED = 'unhandled_package';
- const SOCKET_ERROR_EMPTY_DATA = 'empty_data';
- const PACKAGE_ERROR_INVALID_DATA = 'invalid_data';
- const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data';
- const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content';
- const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package';
+ const SOCKET_ERROR_UNKNOWN = 'unknown_error';
+ const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint';
+ const SOCKET_ERROR_UNHANDLED = 'unhandled_package';
+ const SOCKET_ERROR_EMPTY_DATA = 'empty_data';
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data';
+ const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data';
+ const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content';
+ const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error';
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package';
/**
* Error code from socket
parent::__construct($className);
}
+ /**
+ * Checks wether the 'recipient' field matches our own address:port
+ * combination.
+ *
+ * @param $packageData Raw package data
+ * @return $matches Wether it matches
+ */
+ protected function ifRecipientMatchesOwnAddress (array $packageData) {
+ // Construct own address first,
+ $ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
+
+ // Does it match?
+ $matches = ($ownAddress === $packageData[1]);
+
+ // Return result
+ return $matches;
+ }
+
/**
* Setter for error code
*
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('tcp');
}
/**
* Creates an instance of this class
*
- * @return $handlerInstance An instance of a Networkable class
+ * @return $handlerInstance An instance of a Networkable class
*/
public final static function createTcpNetworkPackageHandler () {
// Get new instance
} elseif (count(explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData[2])) < 2) {
// Not entougth fields in content
$this->setErrorCode(self::PACKAGE_ERROR_INVALID_CONTENT);
+ } elseif (!$this->ifRecipientMatchesOwnAddress($packageData)) {
+ // Field 'recipient' doesn't match our address, this must always be the case
+ $this->setErrorCode(self::PACKAGE_ERROR_RECIPIENT_MISMATCH);
} else {
// This check went fine...
$isValid = true;
protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('udp');
}
/**
// Call parent constructor
parent::__construct(__CLASS__);
+ // Set handler name
+ $this->setHandlerName('task');
+
// Init the task list
$this->setListInstance(ObjectFactory::createObjectByConfiguredName('task_list_class'));
public final function enableIsActive ($isActive = true) {
$this->isActive = (bool) $isActive;
}
+
+ /**
+ * "Getter for address:port combination
+ *
+ * @param $handlerInstance A valid Networkable instance
+ * @return $addressPort A address:port combination for this node
+ */
+ public final function getAddressPort (Networkable $handlerInstance) {
+ // Construct config entry
+ $configEntry = 'node_' . $handlerInstance->getHandlerName() . '_listen_port';
+
+ // Get IP and port
+ $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry($configEntry);
+
+ // Return it
+ return $addressPort;
+ }
}
// [EOF]