*/
private $stateInstance = null;
+ /**
+ * Wether this hub is active
+ */
+ private $isActive = false;
+
/**
* Protected constructor
*
}
/**
- * Generates a session id which will be sent to the other hubs and clients
+ * Generates a session id which will be sent to the other hubs and peers
*
* @return void
*/
/**
* Announces this hub to the upper (bootstrap or list) hubs. After this is
- * successfully done the given task is unregistered from the handler.
+ * successfully done the given task is unregistered from the handler. This
+ * might look a bit overloaded here but the announcement phase isn't a
+ * simple "Hello there" message, it may later on also contain more
+ * informations like the object list.
*
* @param $taskInstance The task instance running this announcement
* @return void
} // END - if
// Debug output
- $this->debugOutput('HUB: Self-announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
+ $this->debugOutput('HUB: Self Announcement: START (taskInstance=' . $taskInstance->__toString(). ')');
// Get a helper instance
$helperInstance = ObjectFactory::createObjectByConfiguredName('hub_announcement_helper_class', array($this));
$this->getStateInstance()->nodeAnnouncedToUpperHubs();
// Debug output
- $this->debugOutput('HUB: Self-announcement: FINISHED');
+ $this->debugOutput('HUB: Self Announcement: FINISHED');
+ }
+
+ /**
+ * Does a self-connect attempt on the public IP address. This should make
+ * it sure, we are reachable from outside world. For this kind of package we
+ * don't need that overload we have in the announcement phase.
+ *
+ * @param $taskInstance The task instance running this announcement
+ * @return void
+ */
+ public function doSelfConnection (Taskable $taskInstance) {
+ // Debug output
+ $this->debugOutput('HUB: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')');
+
+ // Get a helper instance
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('hub_self_connect_helper_class', array($this));
+
+ // And send the package away
+ $helperInstance->doSelfConnect();
+
+ // Debug output
+ $this->debugOutput('HUB: Self Connection: FINISHED');
}
/**
public function activateHub (Requestable $requestInstance, Responseable $responseInstance) {
// Checks wether a listener is still active and shuts it down if one
// is still listening.
- if (($this->determineIfListenerIsActive()) && ($this->determineIfHubIsActive())) {
+ if (($this->determineIfListenerIsActive()) && ($this->getIsActive())) {
// Shutdown them down before they can hurt anything
$this->shutdownListenerPool();
} // END - if
// Setup address and port
$listenerInstance->setListenAddressByConfiguration('node_listen_addr');
- $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
+ if ($this instanceof HubBootNode) {
+ // Bootstrap have different listening port
+ $listenerInstance->setListenPortByConfiguration('boot_node_tcp_listen_port');
+ } else {
+ // All other nodes use the default port
+ $listenerInstance->setListenPortByConfiguration('node_tcp_listen_port');
+ }
// Initialize the listener
$listenerInstance->initListener();
$this->getListenerPoolInstance()->addListener($decoratorInstance);
// Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_tcp_listener_class', array($listenerInstance));
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_tcp_listener_class', array($listenerInstance));
// Add this listener to the pool
$this->getListenerPoolInstance()->addListener($decoratorInstance);
// Setup address and port
$listenerInstance->setListenAddressByConfiguration('node_listen_addr');
- $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
+ if ($this instanceof HubBootNode) {
+ // Bootstrap have different listening port
+ $listenerInstance->setListenPortByConfiguration('boot_node_udp_listen_port');
+ } else {
+ // All other nodes use the default port
+ $listenerInstance->setListenPortByConfiguration('node_udp_listen_port');
+ }
// Initialize the listener
$listenerInstance->initListener();
$this->getListenerPoolInstance()->addListener($decoratorInstance);
// Get a decorator class
- $decoratorInstance = ObjectFactory::createObjectByConfiguredName('client_udp_listener_class', array($listenerInstance));
+ $decoratorInstance = ObjectFactory::createObjectByConfiguredName('peer_udp_listener_class', array($listenerInstance));
// Add this listener to the pool
$this->getListenerPoolInstance()->addListener($decoratorInstance);
}
/**
- * Determines wether the hub is active by checking its current state
+ * Getter for isActive attribute
*
* @return $isActive Wether the hub is active
*/
- public function determineIfHubIsActive () {
- // Check the state
- // @TODO Add more states e.g. 'firewalled', 'senior'
- $isActive = ($this->getStateInstance() instanceof NodeActiveState);
+ public final function getIsActive () {
+ return $this->isActive;
+ }
- // Return value
- return $isActive;
+ /**
+ * Enables (default) or disables isActive flag
+ *
+ * @param $isActive Wether the hub is active
+ * @return void
+ */
+ public final function enableIsActive ($isActive = true) {
+ $this->isActive = (bool) $isActive;
}
/**
- * Returns a singleton network package instance. If an instance is found in
- * the registry it will be returned, else a new instance is created and
- * stored in the same registry entry.
+ * "Getter for address:port combination
*
- * @param $compressorInstance A Compressor instance
- * @return $packageInstance A network package instance
- */
- public function createPackageInstance (Compressor $compressorInstance) {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('network_package')) {
- // Then use this instance
- $packageInstance = Registry::getRegistry()->getInstance('network_package');
- } else {
- /**
- * Prepare the compressor for our package, GZIP should be fine but we
- * keep it open here so you can experiment with the settings and don't
- * need to touch any code.
- */
- $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
-
- // Prepare the decorator compressor (for later flawless and easy updates)
- $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
-
- // Now prepare the network package for delivery so only need to do this
- // once just before the "big announcement loop".
- $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('network_package', $packageInstance);
- }
+ * @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 the instance
- return $packageInstance;
+ // Return it
+ return $addressPort;
}
}